Claude Code is mostly a chat in your terminal, but it also has a non-interactive mode that fits in a shell pipeline, so you can use it in small scripts.
git diff --staged | claude -p "Summarize this diff in one sentence"
-p (print mode) takes the prompt, reads whatever you pipe in, prints the answer and exits. There is no chat window and no follow-up, which suits a script, a git hook or a scheduled job.
cat error.log | claude -p "What is the most likely cause?"asks about a log excerpt.claude -p "..." --output-format jsonreturns structured output when another program reads the reply.claude -p "..." > summary.txtsaves the answer to a file.
Check claude --help on your own version: flags and output formats can change between releases.
A commit message helper is the obvious use: a shell function that pipes git diff --staged into claude -p and prints a proposed message, which you then copy or edit. You stay in control because the script only prints text. The same pattern works for explaining a command you do not understand, summarizing a long file or drafting a changelog from a list of commits. Keep the prompt short and specific, tell it the format you want (one sentence, a bullet list, JSON), and the next step of the pipeline gets output it can use.
Everything you pipe in is sent to the service. Keep passwords, tokens and private files out of it, and look at a log before you pipe it in, because logs often contain addresses and keys. Print mode also has no human to ask for permission, so keep prompts that only read and summarize. And the answer is a text suggestion: read it before you act on it, and do not let a script run whatever comes back.
Further reading: Claude Code docs: CLI reference, On this site: pipe a log straight into claude -p instead of pasting it, On this site: add –bare to claude -p so scripts run the same everywhere