PrepGenAICerts

The Headless/Streaming Flag Set

Advanced

Distinguish Claude Code's session and operating-mode features · Difficulty 1/5

0%
cli-flagsheadless-modesession-resumestreaming-mode

Explanation

Beyond the Bare `claude -p`

claude -p "..." is the example that comes up first for headless mode, but it's shorthand for a small, specific flag set worth knowing individually -- each flag controls a different axis of how a non-interactive run behaves.

FlagWhat it controls
--print / -pNon-interactive, headless output -- process the prompt, print the result, exit. No TUI.
--output-formatSelects the structured output format (e.g., stream-JSON) for programmatic consumption instead of plain text
--resumeReattaches to a specific prior session and continues it
--continueContinues the most recent session without needing to specify a session ID

Why the Distinctions Matter

--print/-p alone answers *whether* the run is interactive at all -- it's the flag that makes headless mode headless. --output-format is a separate, composable choice layered on top: a headless run can emit plain text, or it can emit structured stream-JSON that a calling script parses incrementally instead of waiting for one final blob. This is the same headless/streaming independence covered elsewhere in this lesson -- -p and --output-format are two different dials, not one setting.

--resume and --continue solve a different problem: session continuity across separate invocations. A CI job or script that needs to pick back up on a specific earlier session uses --resume (naming that session); a script that just wants "whatever I was doing last" uses --continue. Neither of these is about interactivity or output format -- they're about which conversation state the new invocation attaches to.

Common exam traps

  • Treating --output-format as a synonym for -p/--print. -p controls interactivity; --output-format controls the shape of what gets printed once you're already non-interactive. A scenario can combine both (headless + stream-JSON) or use -p alone (headless + plain text).
  • Confusing --resume (reattach to a specific named session) with --continue (continue the most recent session without specifying one) -- both address session continuity, but they answer different questions about which session to pick up.

Key Takeaways

  • --print / -p runs Claude Code non-interactively (headless), printing output and exiting with no TUI
  • --output-format selects structured output (e.g., stream-JSON) for programmatic consumption, independent of whether the run is headless
  • --resume reattaches to a specific prior session; --continue continues the most recent session without naming one
  • -p (interactivity) and --output-format (output shape) are separate, composable flags, not the same setting

Glossary Terms

Related Concepts

PrepGenAICerts.com is an independent third-party exam-prep platform for the Claude Certified Architect (CCA-F) certification. We are not affiliated with, endorsed by, or acting on behalf of Anthropic PBC.

Note: New premium upgrades are temporarily paused while we resolve an issue with our payment provider. Existing premium members retain full access.