How to Run Droid CLI in CI and Scripts for Automated Fixes

September 21, 2026

Droid CLI can run without a human at the keyboard, which makes it useful for CI jobs, git hooks, and batch refactors. The trick is disabling the interactive approval prompts and giving the agent a hard budget. Done right, an automated lint-fix job costs a few cents per run.

Can Droid run non-interactively?

Yes. Droid ships a headless style invocation where you pass the task as an argument and it exits with a status code. The flag set matters more than anything else here, because an unattended agent with no limits will happily loop all night. You want a task, a max-turn cap, and a timeout wrapping the whole command.

How do you wire Droid into CI?

The pattern below works on GitHub Actions, GitLab CI, and plain cron:

  1. Install Node 18+ and run npm install -g @factory-ai/droid.
  2. Export your model key as a secret, for example ANTHROPIC_API_KEY.
  3. Call droid with the task and a turn limit: timeout 600 droid run "fix all ESLint errors in src/ and run tests" --max-turns 20
  4. Fail the job if git diff --quiet returns false, so uncommitted changes are visible.

Keep the task narrow. “Fix all lint errors” is safe because the linter defines done. “Improve the codebase” is not, and the agent will meander into files you did not intend to change.

How do you control cost?

A CI run that touches 5-10 small files uses roughly 30k-80k tokens. At Claude Sonnet rates that is under $0.50. Two levers keep it there: a max-turns cap and a diff size check. If the produced diff touches more than, say, 15 files, reject the run instead of opening a pull request. This one rule prevents the classic failure where a bot rewrites half the repo overnight.

Where does it fit next to opencode and IDE agents?

If your team already scripts agents, opencode is the closer sibling — it was built to be embedded in shell pipelines. Droid’s edge is its planning loop on larger multi-file tasks, which shows up when a single lint rule needs changes across many modules. For interactive day-to-day work, stick with the normal Droid session; reserve headless mode for repetitive jobs.

What are the limits?

Unattended agents cannot ask clarifying questions. If the task is ambiguous, you get a plausible but wrong diff, and someone reviews it anyway. There is also no built-in dedup: run it twice on the same branch and you may get two competing patches. Gate every run behind a fresh branch and a human merge.

Quick Summary

  • Droid runs headless with a task argument and an exit code.
  • Always set a max-turn cap and an external timeout wrapper.
  • Typical CI run: 30k-80k tokens, under $0.50.
  • Reject any diff touching more than ~15 files.
  • Headless mode cannot ask questions — use it only for well-defined jobs.

Last updated September 2026.

Tags: