One of the most useful tricks with Claude Code is sending data straight in through a pipe. Your shell already produces plenty of output; you can hand it to Claude and get an answer back.
The basic pattern
Pipe any command's output into claude -p. The piped text becomes the input, and your prompt tells Claude what to do with it.
cat error.log | claude -p "summarize the errors and group them by cause"
This works with -p because headless mode reads the incoming stream, runs once, and prints the result. There is no session to manage, so it drops neatly into a chain of commands.
Real examples
Almost anything that writes to standard output can be a source:
git diff | claude -p "write a commit message for this change"
npm test 2>&1 | claude -p "which test failed and why?"
cat package.json | claude -p "list the scripts and what each one does"
The idea is always the same. The pipe supplies the data; your prompt supplies the intent.
Why this is handy
Piping keeps you in the shell you already know. You do not paste large blocks of text or open a file in the session by hand. Instead you let existing tools gather the data and let Claude interpret it.
It also pairs well with output formats. Add --output-format json and the result becomes machine-readable, so the whole pipeline can feed the next step. We cover formats later in the series. For now, remember the shape: something | claude -p "do this with it".
Comments
Be the first to comment.