GUIDE · HEADLESS RUNS

Run Claude Code headless in CI and overnight batches

Short answer: A headless agent run is one bounded invocation with a machine-readable result, not a chat. Give it print mode, structured output, explicit permissions and a supervised host, and read its exit the way CI reads a test.

Why an interactive session does not fit a pipeline

A chat session assumes someone is watching: it asks follow-up questions, waits for approval and keeps going until the person is satisfied. A CI job or an overnight batch assumes the opposite: nobody is watching, the machine decides pass or fail, and the run must finish on its own. An agent that works well in the first setting needs a different shape for the second: one invocation, one result, no questions in the middle.

That shape has a name in both tools the site already describes. Claude Code runs headless with claude -p, which prints the answer and exits instead of opening a chat, and Codex does the same with codex exec. Either way the run becomes something a pipeline already knows how to handle: a command with an exit code.

One invocation, one machine-readable result

The first rule of a headless run is that its result must be readable by a machine, not just by a person scrolling back. Ask for structured output up front: claude -p accepts --output-format json, and codex exec accepts --json. Parse that output in the next step instead of grepping prose: the exit code says whether the run finished, the JSON says what it did, and a saved transcript says what to show the human who reviews it in the morning.

  • Pin the prompt. The prompt is the specification. Keep it in the repository next to the workflow file, under the same review as any other code, so a rerun months later runs the same instruction.
  • Read the exit like a test. Zero means the invocation finished; it does not mean the change is good. The checks that decide that run separately, on the produced revision.
  • Keep the transcript. Store the full output as a job artifact. When the morning review asks what the agent actually did, the answer is in the log, not in anyone’s memory of a chat.

Say what it may do before it starts

A headless run cannot ask for permission halfway through, so every permission has to be decided before it starts. Claude Code documents --permission-mode and --allowedTools for exactly this: which classes of action may run without asking, and which tools the agent may touch at all. Choose the narrowest set that still lets the job finish, and keep anything that spends, publishes or deletes behind an explicit owner decision.

The same boundary applies to secrets. An overnight run needs the logins it depends on to already exist: signed-in CLIs and available quota, not a browser window waiting for someone to approve. Our guide on keeping Claude Code and Codex working for days lists what a supervised host needs so those runs start instead of stalling at 3 a.m.

Keep the host awake and supervised

CI runners already solve supervision: they start the job, watch it, kill it on timeout and keep the log. An overnight batch on your own machine needs the same three things, usually from the machine’s own scheduler such as cron: a start time, a timeout that stops a stuck run, and a restart rule so a finished run is followed by the next one. An asleep laptop is the most common cause of a batch that “ran” but produced nothing.

  • Start on a schedule the team can see, not on someone’s laptop lid.
  • Cap every run with a timeout; a run that cannot finish must fail loudly.
  • Restart from the recorded state, never by re-running yesterday’s prompt blindly.
  • Collect the JSON result and the transcript where the morning review looks first.

What still needs a human

  • Expired logins, missing permissions or missing credentials wait for the owner.
  • Model calls consume your subscription quota; a loop without a budget is a bill, not a plan.
  • A green run is a finished run, not a verified change: the independent check still decides.
  • Anything the run was not explicitly allowed to do stays undone until someone allows it.

How Orchestro handles it

Orchestro is a control plane for autonomous software agents: it keeps agent loops going with durable state, work selection, recovery and independent verification, around the coding agents you already use. A scheduled watcher launches bounded runs, each worker’s report triggers an independent check instead of closing the work, and the project history survives across sessions. Execution stays on your own Mac or server, with your own coding-agent subscriptions. Read how Orchestro works for the loop from the owner’s side, the product guide for each part, or try the 64-second simulation, no signup needed.

Apply for an assisted pilot

All articles