Session 11
Scripting & CI: headless mode
Goal. Run Claude Code non-interactively so you can pipe data into it and use it in scripts or CI.
- 1
claude -p "query"runs a one-off prompt and exits. It's composable, Unix-style:tail -200 app.log | claude -p "flag any anomalies". - 2Chain it into pipelines:
git diff main --name-only | claude -p "review these changed files for security issues", or run it in CI to translate strings and raise a PR. - 3For recurring work, Routines run on Anthropic's infrastructure on a schedule (created with
/schedule);/looprepeats a prompt within a session for quick polling.
You'll see. Claude Code working as a command-line filter — taking piped input, doing the task, and printing a result you can redirect to a file.
Cost. Headless runs bill like any session; keep prompts focused since each -p call is its own task.
Takeaway. With -p, Claude Code becomes a Unix tool — pipe data in, get analysis or edits out, and drop it into any script or CI job.