Claude Operator: Prompt to Autonomy · 18 min · 120 XP
One-shot answers: print mode and pipes
Use Claude as a command in a pipeline, not only as a conversation.
Not every question deserves a session. --print (or -p) sends one prompt, prints the answer and exits — which makes Claude Code an ordinary command, and ordinary commands compose.
claude -p "What does the --add-dir flag do?" printf 'one\ntwo\n' | claude -p "Turn this into a checklist" claude -p "List this project's entry points" --output-format json
Piping is where this earns its place: anything your shell can produce, Claude can read. A log excerpt, a diff, a CSV sample. Keep what you pipe small and non-sensitive — a pipeline makes it very easy to send a great deal more than you intended, and cat .env | claude -p ... is a mistake you only get to make once.
--output-format json returns a structured result instead of prose, so another program can consume it. Inspect what your installed version actually returns before you build on it: fields differ between versions, and a script that assumes a field that isn't there fails at the least convenient moment.
Practice. Send a one-shot question that exits after printing. Pipe a small, safe local text sample into print mode and ask for a transformation. Then run a one-shot query with JSON output and pass it through another command — jq or a formatter — to confirm it parses, noting which fields your version returns.
Loading your workspace…