Features · Use it anywhere · since version 0.2.21

Headless mode (claude -p)

Run Claude Code from scripts and CI with a single command that prints its answer and exits.

What it is

Adding -p (short for --print) to the claude command runs one task without the interactive screen. Claude works on the prompt, prints the result and exits, so you can call it from a shell script, a Git hook or a CI job. You choose which tools it may use without asking, and can get the result as plain text, JSON or a stream of events.

Why it matters

  • Automate routine tasksFix lint errors, write release notes or review a diff as one step of a script or pipeline.
  • Output your tools can readJSON output includes the result and a session id, and a JSON Schema can make Claude return data in an exact shape.
  • Safe unattended runsPre-approve only the tools a task needs; anything else is refused instead of waiting for a person.

How it works

  1. Run claude -p "your task" and the answer is printed to the terminal.
  2. Allow tools up front with --allowedTools, for example "Read,Edit,Bash(git diff *)".
  3. Pick the format with --output-format: text (the default), json or stream-json.
  4. Continue a run with --continue, or a specific one with --resume and its session id.
  5. Check the exit code: 0 means success, anything else a failure.

Hands-on example coming

This feature has no reviewed example yet. The official documentation below has the details.

Update history

  1. Version 0.2.66 · Apr 9, 2025

    Updated Print mode can stream its output with --output-format=stream-json.

  2. Version 0.2.21 · by Mar 4, 2025

    Introduced Already part of Claude Code when the changelog began with this version.

Official documentation