Frequently Asked Question
Can I use Claude Code in a shell script or a pipeline?
Yes, and this is what makes it interesting to a Linux user rather than only to a
programmer. The -p flag runs a single prompt and exits, printing to standard
output:
claude -p "summarise what changed in the last five commits"
Because it also reads standard input, it composes with pipes like any other filter:
tail -200 /var/log/syslog | claude -p "any errors worth worrying about?"
git diff main --name-only | claude -p "review these files for security issues"
For scripting, --output-format json returns a structured result rather than prose,
--max-turns bounds how long the agent loop may run, and --max-budget-usd caps
spending. Sessions resume with -c for the most recent or -r for one named
explicitly.
One caution: a prompt running unattended has nobody to answer its permission questions, so it is effectively running with approvals disabled. That is the case where a container or ephemeral VM around the whole job earns its setup cost.