Headless mode
Also called Non-interactive mode · Print mode · Scripted run · -p
Running the agent from a script or CI with a prompt and no interactive UI; the result comes back as text or JSON.
Headless mode runs the agent without its interactive interface: you pass a prompt on the command line or from a script, the agent does the work, and the result comes back as plain text or JSON on stdout. Nobody types, nobody clicks. Claude Code does this with claude -p 'your prompt', Codex with codex exec, and most harnesses have an equivalent. It is the same loop, same model, same tools, just driven by a program instead of a person.
Headless is how the agent becomes a building block. A CI job that reviews every pull request, a nightly run that updates docs to match the code, a script that fans a hundred repos through the same migration, a scheduled routine that refreshes a dataset: each is an agent invoked headlessly with a fixed prompt. The trade is that nothing can be asked mid-run. A permission request with no one to answer it either blocks forever or has to be pre-decided, so the permission mode must be set in advance.
Treat a headless run like any unattended automation. Run it in a sandbox or a clean checkout, cap its budget and time, make its output machine-checkable (JSON with a schema beats prose), and end in something reviewable such as a PR or a report rather than a direct change. Log the tool calls so a bad run can be diagnosed. Everything that applies to AFK work applies twice here, because you may not even be awake.
- Claude Code
claude -p 'prompt'prints the result;--output-format jsonmakes it parseable and--allowedToolsfixes permissions up front. - Codex
codex execruns non-interactively with the sandbox and approval policy given as flags. - Claude Cowork and ChatGPT WorkScheduled tasks are the no-code cousin, a saved prompt run on a timer with the result delivered to you.
“Can we get a first-pass review on every PR before a human looks?”
“Yes, run it headless in CI: pipe the diff to the agent with the review prompt, post the JSON findings as a comment.”
“Read-only tools only, and it never approves anything itself.”
Course 01 puts every one of these terms to work: you install Claude Code, run the loop, and ship a real project — permission modes, compaction, hooks and all.
Start Course 01 →