Field notes
Putting AI coding agents in CI
Give CI agents scoped credentials, isolated jobs and review gates. Check the diff and test results before merging.
Coding agents got good enough that leaving them in a terminal on your laptop started to feel wasteful. The obvious next move is CI, where they can pick up work while nobody is watching.
The obvious next move after that is an incident. Here is the setup that gets the upside without it.
The three non-negotiables
- Ephemeral sandbox. Fresh container per job, no reused state, no access to production networks or secrets stores. Egress allowlisted to your package registry and the model provider, nothing else.
- A token that cannot merge. Contents write for branches, pull request create, and nothing more. No merge, no release, no environment secret access, no repository administration.
- A gate before merge. Human review, or a deterministic check set strong enough to be trusted for the narrow class of task in question. Branch protection enforces it so the rule does not depend on discipline.
Pick tasks where success is machine-checkable
The pattern that separates useful from dangerous is verifiability. If a test suite, a type checker, or a linter can tell you the work is correct, an agent can do it unattended. If correctness requires taste or product judgment, it cannot.
- Excellent. Dependency bumps where tests must pass. Type and lint error cleanup. Adding tests for uncovered branches. Mechanical renames and API migrations. Generating a diagnosis comment on a failing build.
- Workable with review. Small bug fixes with a reproduction test written first. Documentation from code. Adding instrumentation.
- Do not. Schema migrations. Auth and permission logic. Anything touching payments. Broad architectural refactors. Anything without a test that would fail if the change were wrong.
Trigger deliberately, not ambiently
Agents on every push is how you get a hundred pull requests nobody asked for and a bill nobody predicted. Use an explicit trigger for each agent job:
- A label on an issue, meaning a human decided this one is suitable.
- A schedule, for maintenance classes like dependency hygiene.
- A failed build, for triage and a diagnosis comment only.
- An explicit comment command on a pull request, with an allowlist of who can issue it.
Budgets and breakers, in the job definition
Agents in CI fail by spinning, exactly as they do everywhere else, except now nobody is watching the terminal.
- Max turns per job, plus a wall-clock timeout on the job itself.
- Token budget per job, enforced in the loop rather than hoped for.
- Per-repository daily spend cap with an alert before the ceiling.
- Repeat detection, so identical tool calls abort the run with a partial result and a clear reason.
These are the same guards from the Claude Agent SDK in production, with the difference that CI has no human in the loop to notice, so the breakers have to be real.
Deterministic checks are your actual safety net
The agent's own claim that it verified something is not evidence. Every agent pull request runs the same pipeline as a human one, plus a few additions worth having:
- Full test suite, type check, lint, build.
- A diff size ceiling. A job scoped to fix a lint error that produces 900 changed lines gets rejected automatically.
- A path allowlist per job type. A dependency job has no business editing authentication code.
- Dependency and secret scanning, because agents copy patterns from wherever they learned them.
- Your eval suite if the change touches prompts, tools, or retrieval. This checks behavior that a compiler cannot establish.
In a hypothetical review failure, a passing test suite hides a deleted assertion. Read changed test files and verify that they still check the requested behavior.
Make the output reviewable
Half the value of an agent pull request is lost if reviewing it takes as long as writing the code. Require a fixed template in the description: what was asked, what changed and why, what was verified and how, what was deliberately not done, and what the reviewer should look at first.
Then keep the diff small on purpose. One task per pull request, hard ceiling on scope. The review checklist for what to look at is in how to review agent-written pull requests.
Instrument it like any other agent
Log per job: trigger, task type, turns, tokens, cost, duration, outcome, and whether the pull request was merged, edited, or closed. That last field is your quality metric. A task class with a low merge rate should be turned off, not tuned forever. Same discipline as agent observability generally.
A working starting configuration
- One job type only: dependency upgrades on a weekly schedule, tests must pass, diff ceiling of 200 lines, lockfile and manifest paths only.
- Ephemeral container, allowlisted egress, branch-and-PR-only token, branch protection requiring one human approval.
- Turn cap, token cap, job timeout, daily repository budget with an alert.
- Template-enforced pull request description and merge-rate tracking.
- Add a second task type only after four weeks of clean results on the first.
Boring on purpose. Boring is what makes it still running in six months.
Check the permissions and failure handling around the agent before expanding its CI access. If you have a stalled product build that has to work for a real customer, pilot, or launch, send the project brief. Scope and price are agreed before work starts.
Frequently asked
Can AI coding agents run safely in CI?
Yes, with three constraints: the agent runs in an ephemeral sandbox, it holds a token that can only open branches and pull requests, and a human or a deterministic gate approves before anything merges. Without all three you have granted write access to a probabilistic process.
What tasks are agents actually good at in CI?
Bounded, verifiable work. Dependency upgrades with passing tests, adding missing test coverage, mechanical refactors, fixing lint and type errors, and triaging failures with a diagnosis comment. Anything where success is machine-checkable.
Should an agent be allowed to push to main?
No. Branch and pull request only, with branch protection enforcing review. The moment an agent can push to main, one bad run becomes a production incident with no review step in between.
How do you control the cost of agents in CI?
Cap turns and tokens per job, set a per-repository daily budget, and never trigger agents on every push. Trigger on labels, schedules, or failures so the work is intentional rather than ambient.
Have a stalled product build?
I help founders turn stalled product builds into software ready for a real customer, pilot, or launch.
Show me what exists, what is stuck, and what needs to work. I take ownership of the implementation, test the agreed user journey, and document the handoff.
New field notes also go out on my newsletter. Subscribe on Substack.

Written by
Alex Cinovoj, TechTide AI
Founder & CTO, TechTide AI · CTO & Co-Founder, CPG Playbook. I’m based in Columbus, Ohio, and spent 13 years in IT across support, systems, cloud, architecture, and engineering, and the last 2 years on AI implementation. I’m a Lovable Senior Champion, an earned Discord community-support volunteer role, with 9 Anthropic Academy course completions. Logs over vibes. Production over theater.
More on Coding agents
Choosing an AI agent framework in 2026
Choose an agent framework by the state, restart behavior and handoffs your workflow requires.
The Claude Agent SDK in production
The SDK provides the agent loop. Your application still needs scoped tools, permissions, budgets, retries and tests.
How to review agent-written pull requests
A tidy diff still needs checks for scope, behavior, APIs, permissions and tests that verify the requested change.