claude-code·Published 2026.06.01·Views 1
Pipe Files to AI: Master cat file | claude -p
Stop copy-pasting error logs or git diffs. A single pipe (|) hands an entire file to Claude for automatic analysis. A beginner-friendly hands-on guide.
When you want to analyze an error log, have you ever opened the log file, dragged everything, copied it, and pasted it into the chat window? If the file is long, that gets tedious fast. The terminal has a cleaner way: streaming a file's contents straight to Claude with a single command.
Definition (What It Is)
This is a way of streaming a file's contents to Claude for processing via a pipe (|, the pipe symbol connects the output of the preceding command to the input of the next one). Without copy-pasting by hand, you can hand the result of a command like cat (which prints a file's contents to the screen) straight to Claude. Since there's no manual transfer, it's used often in automation.
The -p used alongside it is an option meaning "don't open a chat window, just print the answer and exit" (-p = print). So | claude -p means "analyze what was passed in and show me just the answer right away."
How to Use It (By Difficulty)
Before you start: All the commands below run in the terminal (command prompt). If you first move (cd folder-path) into the folder that holds the file you want to analyze, you only need to type the file name. Claude Code must be installed, and if it's your first time you may need to log in (claude auth login).
Basic — Analyzing a log file
cat error.log | claude -p "원인 설명"
This hands the entire contents of the file error.log to Claude and tells it to "explain what the cause is." When you run it, no chat window opens; only the analysis text streams out onto the terminal screen, and then it ends automatically. You don't need to open the file yourself.
Applied — Generating a commit message from code changes
git diff | claude -p "커밋 메시지 써줘"
git diff is a command that shows code changes you haven't committed yet. If you pipe that output, Claude reads "what changed and how" and writes a fitting commit message. You no longer have to wonder "what did I fix this time?"
Advanced — Pipe in the output of any other command
ls -la | claude -p "이 폴더에서 안 쓰는 것 같은 파일 골라줘"
The heart of the pipe is this: "as long as the preceding command prints something to the screen, you can hand it straight to Claude." Whether it's ls (list folder contents), cat, or git diff, it doesn't matter. Once you grasp this principle, you can combine your own analysis commands endlessly.
Real-World Example
Many people build a single script that pipes the server log to Claude every night to summarize it, then has that summary emailed to them. Without a person opening and reading the log each time, you can receive a tidy report each morning of "whether anything strange happened today."
More Ways to Use It
- Since you can pipe in the output of any command, you can build your own varied automatic-analysis commands.
- If you want to save the analysis result to a file, append
> result.txt(e.g.,cat error.log | claude -p "summary" > summary.txt). - For analyses you need to run regularly, turn them into a script and put them on a schedule so they require no hands at all.
Wrap-Up
The pipe (|) is a tool that replaces "copy-paste" with a single command. Just remember the form cat file | claude -p "task", and you can hand anything—logs, code changes, folder listings—to Claude in one go for analysis. It's a perfect pattern for your first step into automation.
Reference: Claude Code v2.1.154 (2026.05)
Comments
Comments 0
Checking sign-in status…
Loading comments…