Claude Code setup guide

Claude Code headless print mode with claude -p

Run claude -p "your prompt" to print one reply and return control to the shell. Plain text is the default, and you can pipe input into the command. For JSON, add --output-format json and check the exit status before reading the reply from the result field.

Last updated · Published

By CWYN · Published · Not affiliated with Anthropic

1. Run a single prompt

From a Bash or Zsh terminal with Claude Code installed, try the command below. Print mode runs without the interactive interface. --bare skips discovery of customizations such as hooks, MCP servers and CLAUDE.md. For the Anthropic API, set ANTHROPIC_API_KEY in the environment before running these examples. Bare mode requires API authentication for this setup.

claude --bare -p --tools "" "Rewrite this as a status update: the export button is ready."

2. Pipe text into the prompt

Pass sample text on standard input and put the task in the prompt. The empty --tools list disables the built-in tools. These bare runs supply no MCP servers.

printf '%s\n' "CSV export is ready. Documentation is still in review." |
  claude --bare -p --tools "" "Summarize the input in one sentence."

3. Save the result as JSON

The first two commands use the default output format, --output-format text. Add --output-format json so a script can read the structured response. This example writes it to summary.json in the current directory. Use a new filename if you have a file there you want to keep. For parallel runs, see how to give each session its own worktree.

printf '%s\n' "CSV export is ready. Documentation is still in review." |
  claude --bare -p --tools "" --output-format json "Summarize the input in one sentence." > summary.json

4. Check exit status before reading the reply

Have your script check the exit status before it reads the file. Claude Code exits with a nonzero status on failure, and a failure during the run can appear on standard output. After a successful run, use jq -r '.result' summary.json if you have jq installed. Check that the reply preserves both details from the input.

For recurring scripts, compare a Claude subscription with API billing. To budget the same coding workload across providers, see Claude Code and Codex costs.

To run a prompt when a pull request opens, set up Claude Code GitHub Actions.

Checked against docs, not run. November 27, 2026 · Print mode, piped input, bare mode authentication, JSON and exit status · Built-in tool restriction and print mode flags

Next steps

Set up your Claude Code project

If you also run Claude Code interactively, the Claude Code Complete Setup Pack ($12.95) includes project instructions, hooks and permission rules for those sessions.
Kit details as of Nov 27, 2026