-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.
Basic usage
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.
- text (default)
- json
- stream-json
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:
Exit codes
Scripts should check the exit code before consuming stdout.
Using in scripts and CI/CD pipelines
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.