Claude Code’s headless, or non-interactive, mode runs a prompt without opening the interactive shell and exits after responding. Start it with claude -p (or claude --print), then choose an output format and restrict the tools available to the run. That makes it possible to use Claude Code in scripts and CI pipelines, while still requiring you to manage permissions, turn limits, and session state deliberately.
How do you run Claude Code without the interactive shell?
Use the print flag with a prompt. Anthropic documents -p as the shorthand for --print; in this mode, Claude Code processes the request without entering interactive mode and exits after its response. See the Claude Code CLI reference.
As an Amazon Associate I earn from qualifying purchases.
claude -p "Explain the failing test in this repository"
You can also pipe file content into the command so the prompt can refer to that input:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →cat error.log | claude -p "Identify the likely cause of this error"
Anthropic’s examples show this mode for scripts, pipelines, and GitHub Actions. The exact installation and authentication steps depend on your environment; consult Anthropic’s Claude Code setup guide and the documentation for the version you have installed.
#1 Best Overall
Which output format should a script use?
Choose the format based on what will consume the response. Anthropic’s CLI reference documents text, json, and stream-json output formats.
| Format | Best suited to | What to handle |
|---|---|---|
text |
A person reading a direct response or a simple log. | Plain text; do not treat it as a structured data contract. |
json |
A script that needs to parse a final result. | Parse the JSON rather than extracting information with text matching. The SDK documentation gives an example with fields such as result, is_error, num_turns, total_cost_usd, and session_id; those example fields are not a guarantee that every release returns an identical schema. |
stream-json |
A consumer that needs to process events as they arrive. | Handle a sequence of messages, not one response string. The documented stream includes an initial system init message, conversation messages, and a final system result message. |
For example, request JSON output with:
claude -p "Summarize the changes in this repository" --output-format json
For incremental input and output, Anthropic’s documented stream example combines --output-format=stream-json with --input-format=stream-json. A pipeline using that format needs to encode and consume the documented event stream; it should not assume the final answer is the only message. See the Claude Code SDK documentation.
Rank #2
How should you control tools and permissions?
An unattended run should have only the tools its task needs. The CLI reference lists --allowedTools and --disallowedTools for configuring tool access. Its examples include restricting Bash commands or allowing read and write tools. These are controls to tailor to the repository and runner, not universal safe defaults: an allowed write or shell command can have consequences in the environment where the job runs.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Anthropic also documents permission modes and --permission-prompt-tool. Its CLI reference warns that --dangerously-skip-permissions skips permission prompts and should be used with caution. The documentation does not establish that unattended runs are inherently safe. Review the current flag behavior, give the job only the access it needs, and consider the impact of its runner’s credentials and filesystem permissions.
Rank #3
How do you keep an unattended run bounded?
Use --max-turns to set a limit on agentic turns in non-interactive mode. This puts a bound on the number of turns, but it is not a guarantee that a task will finish or that its output will be correct. Choose a limit appropriate to the work, and have the calling script check the command’s exit status and handle failure rather than treating any output as success.
Can a script continue a Claude Code session later?
Yes. Anthropic’s CLI reference lists resume and continue options, and its SDK examples show capturing a session_id from JSON output and passing it to a later print-mode invocation. In a multi-step workflow, treat that ID as workflow state: capture it from the response, store it where the next step can retrieve it, and use the current CLI reference to confirm the resume or continue syntax for your installed version. The SDK page also demonstrates shell patterns for checking exit status, redirecting file input and output, and looping over files; validate example syntax against the version you run.
Rank #4
What should you verify before using Claude Code in CI?
CLI flags, output details, permission behavior, and setup requirements can change. The Anthropic setup page available for this article lists platform, memory, Node.js, and installation details, but those details are version-sensitive and should not be treated as confirmed 2026 requirements without checking the live guide. Before adopting a workflow, verify installation and authentication for the runner, then test the exact flags and output your script will parse against the installed release. The official references are the CLI reference, setup guide, and SDK documentation.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




