Background Agents in CI: Approvals Without a Terminal
Background agents in CI are coding agents that run inside a pipeline job or a cloud sandbox with nobody attached. GitHub calls the idea Continuous AI: agents that work in your repository on tasks that need reasoning, such as triage, documentation and code quality. They are useful because they run without you. That is also the difficulty. An agent in a terminal can ask a person; a headless agent has no one to ask. This guide covers the design decisions for running agents unattended: permissions, identity, what happens on timeout, and how to stop them.
What changes for background agents in CI
Four things you get for free at a desk disappear in a pipeline.
- The prompt. Anthropic's docs say that in a Claude Code session that cannot show a prompt, a tool call with no permission decision is denied. Unless you plan for it, your agent's first non-trivial command fails.
- Your identity. A desktop agent runs as you, with your credentials. A CI agent runs as whatever the job was given.
- Your attention. No one sees the agent drift.
- Ctrl+C. Stopping means cancelling a job, if you notice.
GitHub's write-up of its agentic workflows treats these as security design: agents are not trusted with secrets, writes are staged and vetted, and everything is logged. Its guidance on Continuous AI stresses permissions and safe outputs, with developers kept in the loop by design.
Decide permissions before the run
With no one to ask, permission has to be settled in advance or delegated.
Option 1: A strict allowlist. Claude Code's dontAsk mode denies every call that would otherwise prompt and runs only what your allow rules pre-approve. Combined with a short list of commands, this is the tightest setup. The agent can do exactly what you listed.
Option 2: A sandbox and wide permission. If the job's environment is disposable and holds nothing valuable, you can let the agent do anything inside it. The boundary is the sandbox, not the prompt. This is only as good as the sandbox and whatever credentials you put in it.
Option 3: A classifier. Auto mode lets a model judge each action. It removes prompts without removing all checks.
Option 4: A hook that asks someone. A PermissionRequest hook can send the question to a rule engine or a person outside the job, and deny if no answer comes.
These combine. A common arrangement: a sandbox for containment, an allowlist for the routine, and a hook for the few commands that need a decision.
Give each job its own short-lived identity
Do not put a developer's long-lived key in a pipeline.
- One key per job or per agent. Then logs say which agent did what, and you can revoke one.
- Short-lived keys. A key that outlives the job is a liability.
- Attribution to a person. Someone started this. Record who.
Forkit's fan-out keys are built for this. One request creates up to 1,000 keys named <name>-001 onward. They expire after an hour by default (24 hours at most), act under the person of the agent that started them, and cannot start further fan-outs.
Sandbox setup without questions
A setup step in CI cannot open a browser to sign in or wait for someone to press Enter.
Forkit's forkit init --sandbox installs Claude Code's hooks with no sign-in, no key and no question, and sets the hook to deny on timeout. The key arrives at run time in the FORKIT_API_KEY environment variable. Alternatively, forkit init --project writes .claude/settings.json and the hook script into the repository so you can commit them, and every job that checks out the repository has them.
Plain forkit init, run with no terminal and without --yes, connects nothing, says to rerun with --yes and exits 1. That is the right behaviour for a tool in a pipeline: fail loudly instead of hanging.
A job step looks like this:
- name: Run agent
env:
FORKIT_API_KEY: ${{ secrets.FORKIT_WORKER_KEY }}
run: |
forkit init --sandbox
claude -p "Update the API docs for changed endpoints. Edit only docs/."
In a fan-out, the key would come from the fan-out's response instead of a stored secret.
Choose what happens on timeout
When a headless agent asks and nobody answers, there are two honest outcomes.
Deny on timeout. The agent is told no, with a reason, and moves on or reports that it is blocked. Forkit records an unanswered permission request from a fan-out's agent as denied. Any agent gets the same behaviour with FORKIT_ON_TIMEOUT=deny.
Wait longer. For a job where a person is expected to respond, extend the wait. Mind the job's own time limit.
What you must not do is allow on timeout. In a terminal, Forkit's hook falls back to the local prompt when nobody answers remotely. In CI there is no local prompt, so the fallback has to be refusal.
Tell the agent what a denial means. An instruction such as "if a command is denied, do not retry it; continue with what you can and list what was blocked in your final message" turns a denial into a useful report instead of a loop.
Answer many jobs at once
Jobs that do the same work ask the same things. Forkit merges pending requests with the same fan-out, tool, subject and repository into one question, and one answer settles all of them. Rules go further: a command rule answers before anyone is asked.
Before launching many jobs, run one, see what it asks, and write rules for those requests. Then the fleet runs without interruption, and anything outside the rules is denied or reaches a person.
Sensitive requests are the exception. Anything touching production, secrets or money always reaches a person, is never grouped, and can only be allowed once.
Get results out
A background agent's output has to land somewhere a person or another agent will see it.
- A pull request. The usual output. GitHub's Copilot coding agent works this way.
- A handoff message. In Forkit, a worker started with a fan-out key links to the fan-out's parent thread, so its handoff goes to the planner automatically.
- A thread. Each session becomes a thread with its commands and changed files, which a person can open later.
- A review request. When the work is done, the agent asks for review, and approval rules route it to the owner of the files.
Have the agent finish with a structured summary. See agent handoff notes.
Stop them
Plan the stop before the start.
- Time. Give keys and jobs a lifetime.
- Budget. A fan-out can carry a limit on total tool calls; reaching it stops every agent in it. It can overshoot by a few calls.
- One action. Stopping a fan-out makes every request from its keys return a stop. Claude Code's hook then ends the session, pending requests are denied and file claims are released.
- Cancel the jobs too. Forkit stops the agents; it does not delete sandboxes or cancel pipeline jobs. Your CI system does that.
More in how to stop a runaway agent.
Limits worth knowing
From Forkit's documentation:
- Codex in a sandbox is not covered. Codex requires hooks to be trusted through
/hooksin a terminal. - No spending limit in money. Hooks do not report cost. Use the tool call limit and your provider's controls.
- The 1,000-agent figures come from one staging run with scripted agents, not from a real CI fleet.
A checklist for headless agents
- The job's environment is disposable and holds only the credentials the task needs.
- Each job has its own key, which expires.
- Permission is decided by an allowlist, a sandbox, a hook, or a combination.
- Timeout means deny.
- The agent's instructions say what to do when denied.
- Output goes to a pull request, a handoff or a review request.
- There is a time limit, a tool call budget and one stop action.
- A person is named as responsible for the run.
Related: agent fan-out explained and cloud agents vs local agents.
Where Forkit fits
Forkit gives agents in pipelines and sandboxes what a terminal used to provide: someone to ask, a recorded answer when no one replies, and a way to be stopped. It is free to try. More at forkit-mcp.com.