Install script for dispatching kimi, gemini, and other external CLI AI agents as Claude Code subagents — with zero LLM quota cost for dispatch.
Normally Agent() tool calls consume Claude Code LLM quota. This system instead intercepts Agent() calls for specific subagent types and runs the real external CLI binary directly, returning output through the hook's deny reason.
Agents included:
| Agent | CLI | Use Case |
|---|---|---|
kimi-coder |
kimi |
Well-scoped coding tasks with exact file/line specs |
gemini-coder |
gemini |
Coding tasks, visual analysis via screenshots |
gemini-reviewer |
gemini |
Diff/branch/PR review with visual capability |
- Zero quota dispatch — hook intercepts before LLM is called
- Foreground mode — blocks until done, returns output inline
- Background mode (
[bg]) — spawns and returns immediately with PID - Concurrency limit — max 3 simultaneous background agents
- Completion notifications —
notify-senddesktop notification on finish - Auto-reporting — PostToolUse hook detects completed agents and reports inline
- Completion tracking —
/tmp/claude-bg-agents/{ts}.donewith exit code - Auto cleanup — stale tracking files and logs (>24h) cleaned on each invocation
git clone https://github.com/Softtor/claude-code-external-agents.git /tmp/claude-code-external-agents
cd /tmp/claude-code-external-agents
bash install.shWith overwrite:
bash install.sh --forcejq— JSON processorkimi— kimi-cli (for kimi-coder agent)gemini— gemini-cli (for gemini-coder/gemini-reviewer agents)- Claude Code — the host environment
Missing CLIs won't block install, but the corresponding agent will fail at runtime.
~/.claude/
hooks/external-agent-intercept.sh — PreToolUse hook script
agents/kimi-coder.md — kimi-coder agent definition
agents/gemini-coder.md — gemini-coder agent definition
agents/gemini-reviewer.md — gemini-reviewer agent definition
settings.json (or settings.local.json) — hook registration added
Agent(subagent_type="kimi-coder", prompt="fix the login bug in auth.ts")
Returns output inline after completion.
Agent(subagent_type="kimi-coder", description="fix tests [bg]", prompt="fix all failing tests")
Returns immediately with PID and tracking info:
[kimi-coder] BACKGROUND dispatched.
PID: 1812155 (watcher: 1812156)
Active: 1/3 (1812155)
Task: /tmp/kimi-task-1777654657.md
Log: /tmp/kimi-run-1777654657.log
Done: /tmp/claude-bg-agents/1777654657.done
# Poll for .done file
until [ -f /tmp/claude-bg-agents/1777654657.done ]; do sleep 2; done
cat /tmp/claude-bg-agents/1777654657.done # EXIT=0Or via Claude Code Monitor tool:
Monitor(command="tail -f /tmp/kimi-run-1777654657.log", description="kimi-coder PID 1812155")
Max 3 background agents. 4th dispatch returns:
[kimi-coder] BLOCKED: max 3 background agents (3 running: 1813230 1813231 1813232).
Wait for one to finish (check /tmp/claude-bg-agents/*.done) then retry.
~/.claude/
├── hooks/
│ ├── external-agent-intercept.sh # PreToolUse — dispatch external CLI
│ └── bg-agent-notify.sh # PostToolUse — report completions
├── agents/
│ ├── kimi-coder.md
│ ├── gemini-coder.md
│ └── gemini-reviewer.md
└── settings.json # hook registration
/tmp/claude-bg-agents/ # runtime tracking
├── {ts}.pid # active process
└── {ts}.done # completion (EXIT=N)
/tmp/kimi-task-{ts}.md # task prompt
/tmp/kimi-run-{ts}.log # output log
/tmp/gemini-task-{ts}.md
/tmp/gemini-run-{ts}.log
Agent(subagent_type="kimi-coder", ...)is intercepted by PreToolUse hookexternal-agent-intercept.shchecks subagent_type — only kimi-coder/gemini-coder/gemini-reviewer are intercepted; all others pass through- Prompt is written to timestamped task file
- Real CLI binary runs (kimi or gemini)
- Output is returned in hook's
denyreason — Claude Code displays it - Background mode: watcher process polls for completion, writes
.done, fires desktop notification