Chapter 28 · CLI
Headless: non-interactive runs, pipes and JSON
Headless mode runs Claude Code without an interactive interface: a prompt goes in, a result comes out. With pipes, JSON output and streaming it becomes a building block in scripts and automation pipelines.
Video
Steps
- Run a single prompt non-interactively with the right flag, confirming the result is stable for script use.
- Combine in a pipe: input from a previous command feeds the prompt, and output flows to the next command in the chain.
- Request structured JSON output when processing results programmatically, validating the schema before use.
- Control permissions in headless too: an unattended run without limits can take unplanned actions.
Common pitfall: Headless without permission limits is a free-roaming automatic agent; define exactly what it may do before scheduling it.
Hands-on exercise: Write one pipe line feeding a command output into Claude Code and returning JSON. Verify the JSON is valid for processing.
Filmed demo · Video is added in the media phase
Recap
Comprehension check
Why limit permissions in headless runs?
Recap
- Headless for scripts and pipelines
- Structured JSON with schema validation
- Narrow permissions in automated runs