The Complete Claude Guide
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.

Verified against source on 2026-09-30

Video

Steps

  1. Run a single prompt non-interactively with the right flag, confirming the result is stable for script use.
  2. Combine in a pipe: input from a previous command feeds the prompt, and output flows to the next command in the chain.
  3. Request structured JSON output when processing results programmatically, validating the schema before use.
  4. 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

Official sources

← Previous Back to contents Next →