Delegate coding tasks to Cline CLI (open-source autonomous coding agent). Model-agnostic, supports all major providers. Use for one-shot tasks, CI/CD automation, and parallel workstreams. Requires Node.js 20+.
Delegate coding tasks to Cline CLI — an open-source, model-agnostic coding agent that runs directly in the terminal.
Install Cline CLI globally:
npm install -g cline
# or
npx cline auth # Follow prompts to configure your provider
This installs the cline command globally. No PATH configuration needed for standard npm installs.
Default model: Configure during cline auth — recommended: anthropic/claude-haiku-4-5 (cheap, fast) or xiaomi/mimo-v2-pro (good for large tasks when credits are tight).
Config stored in ~/.cline/data/.
Run cline auth interactively (needs a TTY/PTY), or use flags:
cline auth -p <provider> -k <api_key> -m <model_id>
v2.8.0 quirk: Even with flags, auth launches a TUI. Run in the background with a long timeout (20-25s) — it writes config before exiting on SIGTERM. Config is saved to ~/.cline/data/globalState.json and ~/.cline/data/secrets.json.
cd /path/to/project
cline -y "Add error handling to all API calls in src/"
-y / --yolo = auto-approve all file changes, forces headless mode.
cline -y --timeout 300 "Run tests and fix any failures"
git diff origin/main | cline -y "Review these changes for bugs and security issues"
npm test 2>&1 | cline -y "Fix failing tests"
cline --json "List all TODO comments" | jq '.text'
cline -y -m anthropic/claude-sonnet-4-5 "Refactor auth module to use JWT"
(cd /tmp/branch-a && cline -y "Fix login bug") &
(cd /tmp/branch-b && cline -y "Add unit tests for auth") &
wait
For complex multi-task implementations, don't send vague instructions to Cline. Use a two-step pattern:
Plan first — dispatch a delegate_task subagent with full codebase context to read the relevant files, understand the structure, and write a detailed plan doc (exact file paths, line numbers, complete code snippets) to e.g. docs/plans/YYYY-MM-DD-feature.md.
Implement with Cline — hand the plan file to Cline:
cline -y --timeout 600 -m anthropic/claude-sonnet-4-5 \
"Implement the plan in docs/plans/2026-04-03-feature.md exactly as written. Read the plan first, then read each source file before editing it."
Optionally add --double-check-completion to force Cline to re-verify its work before marking done. Adds time, reduces the need for a first-pass audit.
This pattern works because:
When to use: Any implementation involving 3+ files, or where field names / API shapes need to be verified before writing code.
For features spanning many files, Cline first passes routinely miss steps — even with a detailed plan. Observed: 5 of 13 planned steps skipped on a leaderboard feature (UI, tests, runner loop all absent). The reliable pattern is:
delegate_task with max_iterations=40, ask it to read every changed file against the plan and produce a prioritised list: bugs, missing steps, integration gaps, test gaps. Specify exact files and what to check.Key differences from the first pass prompt:
Observed outcome: Two-pass cycle (Cline → Opus review → Cline) consistently produces cleaner results than one long prompt, because the review grounds the second prompt in reality rather than the plan.
If all tasks in a phase touch the same file — use ONE Cline agent for the whole phase.
The parallel workstream pattern only works when tasks are on different files. When a code review or plan surfaces N tasks that all modify dashboard.html (or any single file), combine them into one agent prompt rather than trying to parallelize. Sequential tasks in a single session preserve the file state correctly.
Quick decision:
Exception: Kanban. When using cline kanban, each task runs in its own git worktree. Parallel agents can't clobber each other because they're working in separate checkpoints. The one-agent-per-file constraint does not apply when using Kanban.
One agent per file, always — unless using Kanban (worktrees handle isolation natively). If multiple tasks touch the same file and you're using raw CLI, combine them into one agent prompt. Two agents editing the same file concurrently will clobber each other — the second write overwrites the first, silently. Group tasks by file before dispatching.
When a code review surfaces N independent issues, dispatch one Cline agent per issue as background processes. Critical rule: split work so no two agents touch the same file. If two agents edit the same file concurrently, the second write overwrites the first.
Workflow:
cd /path/to/your/project
# Agent 1: touches only dice.py
cline -y --timeout 300 "Fix scatter logic in app/game/dice.py: ..." \
> /tmp/fix_scatter.log 2>&1 &
echo "Agent 1 pid $!"
# Agent 2: touches only combat.py
cline -y --timeout 300 "Implement assists in app/game/combat.py: ..." \
> /tmp/fix_assists.log 2>&1 &
echo "Agent 2 pid $!"
# Agent 3: touches only action_executor.py
cline -y --timeout 300 "Implement push in app/state/action_executor.py: ..." \
> /tmp/fix_push.log 2>&1 &
echo "Agent 3 pid $!"
Then schedule a single cron job (deliver: origin) to fire after enough time for all agents to finish. The cron task reads each log, runs the full test suite, and reports pass/fail per agent plus any issues needing manual attention.
# In the cron prompt, check each log and run tests:
# - cat /tmp/fix_scatter.log | tail -30
# - cd /path/to/your/project && uv run pytest tests/ -q | tail -20
For larger features (5+ files), a single Cline pass frequently skips steps or times out silently. Realistically expect three passes for anything complex:
Plan — delegate_task subagent reads codebase, writes docs/plans/YYYY-MM-DD-feature.md with exact file paths, line numbers, and complete code snippets.
First Cline pass — implement the plan with a tight, specific prompt.
Opus audit — run as a direct delegate_task (not a cron) when actively working — faster feedback. Use a cron (deliver: origin) if you're stepping away. The subagent reads every new/modified file and produces a prioritised findings report: bugs, missing steps, integration gaps, test coverage. Give it the plan file path and the specific integration points to check.
Second Cline pass — targeted fix prompt. Provide exact code for each fix, not just descriptions. Cline is significantly more accurate when the prompt says "add this exact block after line X" vs "fix the timeout handling". List each issue as a numbered heading with the precise code to insert.
Second Opus audit + third Cline pass if needed — for a feature with multiple review cycles, the second audit is usually much cleaner. If only a handful of issues remain (missing tests, minor edge cases), fix them directly rather than firing another Cline pass.
Observed failure modes on first pass:
--timeout 600 hit mid-task, leaving the last file untouched (0-byte test file)@property not serialized (needs @computed_field), datetime.utcnow() deprecatedset.add()) placed before the disk write it protects — silent data loss on failureAudit prompt shape that works well: