Headless / Non-Interactive Mode
Run Claude Code with no back-and-forth and no approval prompts, using the -p flag — turning it into a scriptable, pipeable tool.
Normal Claude Code is interactive: you type, it responds, you approve actions, back and forth. Add the -p flag and it runs the entire task in one shot with no conversation and no approval prompts — it processes the request and outputs the result, full stop. This is what makes Claude Code composable with the rest of your toolchain: pipe a log file into it, run it inside a CI job, chain it with other commands.
Terminology update: the video says this used to be called “headless mode” and is “now officially CLI mode.” In current documentation it's simply referred to as non-interactive mode (the -p / --print flag), and it's positioned as one entry point into the broader Agent SDK — the same underlying engine, available as a CLI for scripts and CI, or as Python/TypeScript packages for full programmatic control (see the Agent SDK topic). A newer --bare flag is worth knowing: it skips loading hooks, skills, plugins and CLAUDE.md for faster, more predictable, script-safe runs.
Real-life use cases
A Slack alert from a log tail
tail -200 app.log | claude -p "Slack me if you see any anomalies" turns Claude Code into an unattended log-monitoring step, with no one needing to babysit a conversation.
Automated PR review in CI
A CI pipeline runs claude -p against the diff of every pull request with a fixed set of allowed tools, posting a structured review as a comment — consistent, automatic review on every PR without a human needing to trigger it.
Source
- Source video: “Claude Code Explained” — 27 concepts in 27 minutes (YouTube)https://www.youtube.com/watch?v=ZlDnsf_DOzg
- Run Claude Code programmaticallyhttps://code.claude.com/docs/en/headless