claude -p "prompt" runs a single non-interactive query and exits. Pipe input to it: cat error.txt | claude -p "explain this error". Use it in shell scripts the same way you'd use curl or jq.
Output format is controlled with --output-format. text is the default: plain prose output. json returns the full conversation as a JSON array. stream-json streams each turn as a JSON object as it's generated. I'll walk you through a common pattern: run Claude to analyze a test failure, parse the JSON output, and post the explanation as a PR comment automatically. In CI pipelines, json output lets downstream scripts parse Claude's response programmatically.