Run Claude Code without the interactive UI so you can script it — in CI, in git hooks, across parallel worktrees. Print mode plus JSON output makes Claude a building block.
Why: -p runs a prompt and prints the result with no interactive UI, so you can pipe Claude into any script. When: use it in CI, cron jobs, or shell pipelines. Where: add --output-format json to get structured output your script can parse.
# One-shot, scriptable:
claude -p "summarize today's git log in 3 bullets"
# Structured output for a script to consume:
claude -p "list the exported functions in src/api.ts" --output-format json
# Pipe data in:
cat error.log | claude -p "what's the root cause of these errors?"Why: in automation there is no human to approve actions, so you set the boundaries up front. When: allowlist exactly the tools the job needs and cap the turns so it cannot run away. Where: pair a tight tool list with a non-default permission mode.
--allowed-tools — Whitelist the tools this run may use (everything else is denied).--permission-mode — Set the mode non-interactively (e.g. acceptEdits) since no one is there to click.--max-turns — Hard cap on agent turns — a safety limit for unattended runs.claude -p "fix the failing lint errors" \
--allowed-tools "Read" "Edit" "Bash(pnpm lint:*)" \
--permission-mode acceptEdits \
--max-turns 15Why: a git worktree gives each task its own checkout, so several Claude sessions can work at once without stepping on each other. When: use it to run independent jobs (a feature here, a bugfix there) in parallel. Where: one Claude session per worktree, each in its own terminal.
# Create isolated checkouts for parallel work:
git worktree add ../app-feature-x feature-x
git worktree add ../app-bugfix bugfix-123
# Then run a separate Claude session in each:
cd ../app-feature-x && claude
cd ../app-bugfix && claude