Skip to content
Getting Started Simple

Pipe File to Claude

Feed file contents via stdin pipe for quick code review or analysis

Command

"color:#9CA3AF;font-style:italic"># Pipe a single file
$ "color:#7C5CFC">cat src/auth.py | "color:#7C5CFC">claude -p "Review this ">for security issues"
  
"color:#9CA3AF;font-style:italic"># Pipe filtered content (saves tokens)
$ grep -n "TODO\|FIXME\|HACK" src/*.ts | "color:#7C5CFC">claude -p "Prioritize these"
  
"color:#9CA3AF;font-style:italic"># Pipe with output format
$ "color:#7C5CFC">cat package.json | "color:#7C5CFC">claude -p "List outdated patterns" "color:#d97757">--output-format text

Response

## Security Review: auth.py

### Critical
- Line 42: SQL injection in `login()` — use parameterized queries
- Line 89: Hardcoded secret in `verify_token()`

### Medium
- Line 15: Missing rate limiting on auth endpoint

Parsing Code

059669">">const { execSync } = require(059669059669">">'child_process');

059669">">// Pipe content programmatically
059669">">const content = fs.readFileSync(059669059669">">'src/auth.py', 059669059669">">'utf-8');
059669">">const output = execSync(
  059669">`echo ${JSON.stringify(content)} | claude -p "Review 059669">">for security" --output-format text`,
  { encoding: 059669059669">">'utf-8', env: { ...process.env, CLAUDECODE: 059669">'' } }
);

Gotchas

! Piped content counts as part of the prompt — large files consume significant tokens
! Use grep or head to filter before piping to reduce token cost
! Stdin pipe + -p flag: piped content becomes part of the user message

Related Recipes