Class 03 — Claude Code

Output & Sessions

Scripting Claude as a Unix tool — controlling what comes out, in what format, and how conversations persist across invocations.

Key concept
--print  /  -p is the gateway flag. It unlocks output format control, streaming, partial messages, budget caps, and turn limits — none of which are available in interactive mode.

The --print Flag

-p / --print

Print once and exit

Without -p, claude starts an interactive REPL. With it, claude becomes a standard Unix filter — reads input, writes output to stdout, exits. Everything below unlocks with it.

--output-format --input-format --include-partial-messages --max-turns --max-budget-usd --no-session-persistence --json-schema --fallback-model

--output-format

Three formats, three use cases. Select a tab to see what the same query looks like in each.

--output-format print only

Set output format: text (default, plain string to stdout), json (structured envelope with cost + metadata), stream-json (one JSON object per line as events arrive).

claude -p "query" --output-format json
--input-format print only

Accept input as text or stream-json. Lets you pipe the stream-json output of one Claude call directly into the input of another.

claude -p --input-format stream-json
--include-partial-messages print only

Include partial streaming events in output. Requires --output-format stream-json. Lets you see tokens as they arrive mid-stream.

claude -p --output-format stream-json --include-partial-messages "q"
--verbose

Show full turn-by-turn output. Works in both modes. Useful for debugging — shows each tool call and result as Claude works through a task.

claude --verbose "explain this"

Persistence & Resumption

By default, every interactive session is saved by session ID. These flags control how you navigate that history.

--continue -c interactive + print

Load the most recent conversation in the current directory. Picks up context from your last session automatically.

claude --continue
--resume -r interactive + print

Resume a specific session by its ID or saved name. Pass no value to get an interactive picker showing past sessions.

claude --resume auth-refactor
--fork-session

When resuming, create a new session ID instead of continuing the original. Branch a conversation without altering the original history.

claude --resume abc123 --fork-session
--session-id

Use a specific UUID as the session ID. Useful for deterministic session naming in CI pipelines or automated workflows.

claude --session-id "550e8400-e29b-41d4-a716-446655440000"
--no-session-persistence print only

Disable session persistence entirely. Nothing is written to disk. Fully ephemeral — good for sandboxed CI runs.

claude -p --no-session-persistence "query"
--from-pr

Resume sessions linked to a GitHub PR by number or URL. Sessions link automatically when created via gh pr create.

claude --from-pr 123
← Class 02: The Exchange 3 of 5 Class 04: Controlling Claude →