Skip to main content
Non-interactive mode (-p / --print) runs Claude Code as a single-shot command: send a prompt, get a response, exit. There is no REPL, no UI, and no user interaction. This makes it suitable for shell pipelines, CI/CD jobs, and SDK-style integrations.
The workspace trust dialog is skipped when Claude is run with -p. Only use this flag in directories you trust.

Basic usage

Claude processes the prompt, prints the response to stdout, and exits. By default the output is plain text.

Reading from stdin

When stdin is not a TTY, Claude Code reads it and appends it to the prompt. This lets you pipe file contents, command output, or any text directly into a prompt.
If no stdin data arrives within 3 seconds, Claude Code proceeds without it and prints a warning to stderr. To skip stdin explicitly, redirect from /dev/null: claude -p "prompt" < /dev/null.

Output formats

Use --output-format to control how the response is printed. This flag only works with --print.
Plain text — Claude’s response as a string, suitable for human reading or piping into other tools.

Input format

Use --input-format to describe the shape of data arriving on stdin. stream-json input is used for SDK integrations where the orchestrating process sends structured messages rather than raw text.

Limiting agentic turns

By default Claude Code will run as many tool-use turns as needed to complete the task. Use --max-turns to set a hard upper bound:
This is useful in CI pipelines where you want a safety limit on how much work Claude can do autonomously.

Exit codes

Scripts should check the exit code before consuming stdout.

Using in scripts and CI/CD pipelines

Set ANTHROPIC_API_KEY (or configure another auth method) before running Claude Code in CI. The interactive OAuth flow is not available in non-interactive mode.

Environment variables

Claude Code inherits environment variables from the calling shell. Variables that affect behaviour in non-interactive mode include:

SDK usage pattern

The Claude Code CLI can be driven programmatically from the official SDKs. The SDK launches Claude Code as a subprocess with --output-format stream-json and --input-format stream-json, exchanging structured JSON messages over stdio.
When using the SDK you do not need to construct these flags manually — the SDK handles the subprocess lifecycle and message parsing for you.

Complete flag reference for non-interactive mode