Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Run Claude Code without opening its interactive shell by using claude -p or claude --print. This non-interactive mode is designed for one-shot prompts and scripted workflows: provide a prompt directly or pipe content into the command, choose an output format that suits the next step, and set tool permissions and turn limits deliberately.

Anthropic’s documentation describes this workflow for scripts, pipelines, and CI. The CLI options and setup details below are documented by Anthropic, but command-line behavior can change; check the CLI reference for the version you have installed.

Start Claude Code without the interactive shell

Use -p or its long form, --print, to run a prompt and exit after Claude responds. Anthropic’s CLI reference shows both a direct prompt and piped file content:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
claude -p "Summarize the changes in this repository"
cat file.txt | claude -p "Summarize this content"

The first pattern sends a prompt directly. The second supplies standard input as context alongside the prompt. In a script or pipeline, capture the command’s exit status and handle errors rather than assuming every invocation succeeds; Anthropic’s SDK examples demonstrate checking that status.

Anthropic’s common-tasks documentation also identifies non-interactive execution as useful in scripts, pipelines, and GitHub Actions. Before placing it in a CI job, decide what repository content it may read or change, which commands it may run, and what should happen if the job fails.

Choose output for the next step

The CLI reference documents three output formats. Pick based on whether a person or another program will consume the result:

Format Use it when What to account for
text A person needs a straightforward response. It is human-readable, not a structured data contract.
json A script needs to parse a final result. Parse the JSON rather than relying on display formatting. Anthropic’s SDK page shows an example with fields such as result, session_id, is_error, num_turns, and cost and duration statistics; treat those fields as an example, not a guarantee that every release returns an identical schema.
stream-json A consumer needs incremental events while a run is underway. Process a sequence of events, not one response string, and identify the final result explicitly.

For machine-readable output, the documented CLI option is --output-format. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
claude -p --output-format json "Summarize the changes in this repository"

Anthropic’s stream example pairs --output-format=stream-json with --input-format=stream-json. Its documented event flow includes an initial system init message, conversation messages, and a final system result message with statistics. A stream consumer should tolerate multiple messages and extract the final result rather than treating the first event as the answer.

Constrain tools and bound unattended runs

Non-interactive execution removes the interactive shell from the workflow; it does not make permission decisions unnecessary. Anthropic documents --allowedTools and --disallowedTools for configuring which tools Claude Code may use. The CLI reference examples include restricting Bash commands and allowing read/write tools, but a suitable boundary depends on the repository and runner. Allow only what the task needs, and review write access and shell commands with particular care.

Use --max-turns to cap the number of agentic turns in a print-mode run. This provides a bound on the conversation’s agentic steps, not a guarantee that a particular task will finish correctly within that limit.

The CLI also lists permission modes and --permission-prompt-tool. Its documentation warns that --dangerously-skip-permissions skips permission prompts and should be used with caution. The documentation does not establish a general security guarantee for unattended jobs, so do not treat skipped prompts as a substitute for runner isolation, least-privilege credentials, or an intentional tool allowlist.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Continue work across script steps

For workflows that span invocations, Anthropic documents resume and continue options. Its SDK example captures a session_id from JSON output and supplies it to a later print-mode invocation. This lets a subsequent step continue a session rather than treating every call as unrelated.

In automation, treat the session identifier as workflow state: capture it from the actual output, preserve it only for the relevant workflow, and handle a missing or unusable identifier as an error path. Confirm the current resume or continue syntax in the CLI reference for your installed version.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Set up Claude Code with version-sensitive expectations

Installation and platform requirements can change. Anthropic’s setup page, Set up Claude Code, has documented macOS 10.15+, Ubuntu 20.04+/Debian 10+, Windows 10+ through WSL or Git for Windows, at least 4 GB of RAM, Node.js 18+, and an internet connection. That page also described global npm installation, local and native-binary alternatives, the native route as alpha, automatic updates, and claude update. These are details from the retrieved documentation, not independently verified guarantees for 2026; check Anthropic’s current setup page before relying on them.

Anthropic’s English CLI reference is at CLI reference. Related workflow and SDK examples are available in Anthropic’s Portuguese documentation: Common tasks and Claude Code SDK. The command names, flags, output details, and permission behavior are version-sensitive, so validate any script against the documentation for the version actually deployed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a reliable headless workflow

  1. Provide the task input. Use a direct prompt or pipe file content into claude -p.
  2. Select the output format. Use text for people, JSON for a structured final response, or stream-JSON for incremental processing.
  3. Set the tool boundary. Configure allowed or disallowed tools to match the task and runner.
  4. Set a turn limit where appropriate. Use --max-turns to bound an unattended run.
  5. Handle results as workflow data. Check the exit status; parse JSON or stream events according to their format, and capture a session ID only if a later step needs to continue the session.

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.