Non-interactive mode (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/jackdog668/claude-code/llms.txt
Use this file to discover all available pages before exploring further.
-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.
| Value | Description |
|---|---|
text (default) | Plain text read from stdin and appended to the prompt |
stream-json | A newline-delimited stream of JSON messages (SDK control protocol) |
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
| Code | Meaning |
|---|---|
0 | Claude finished successfully |
1 | An error occurred (API error, invalid flags, etc.) |
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:| Variable | Effect |
|---|---|
ANTHROPIC_API_KEY | API key for authentication |
CLAUDE_CODE_ENTRYPOINT | Identifies the caller context (e.g. sdk-ts, sdk-py, github-action) |
GITHUB_ACTIONS | When set to true, Claude Code identifies the client type as github-action |
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.
Complete flag reference for non-interactive mode
| Flag | Description |
|---|---|
-p, --print | Enable non-interactive mode |
--output-format <format> | text (default), json, or stream-json |
--input-format <format> | text (default) or stream-json |
--max-turns <n> | Maximum number of agentic turns |
--model <model> | Model to use (alias or full name) |
--allowed-tools <tools...> | Comma or space-separated list of tools to allow |
--disallowed-tools <tools...> | Comma or space-separated list of tools to deny |
--system-prompt <prompt> | Override the system prompt |
--append-system-prompt <prompt> | Append text to the default system prompt |
--add-dir <directories...> | Additional directories to allow tool access to |
--no-session-persistence | Disable saving the session to disk |
-c, --continue | Continue the most recent conversation |
-r, --resume [session-id] | Resume a specific session by ID |