GC-301g · Module 1
Input Piping & Context Injection
3 min read
Piping input into Gemini CLI lets you feed arbitrary data — file contents, command output, API responses, log streams — directly into the model without saving to temporary files. The standard Unix pipe operator (|) sends stdout from one command into Gemini's stdin. This is how you compose Gemini with existing tools: git diff | gemini -p "Review these changes", curl api/health | gemini -p "Parse this health check", cat error.log | gemini -p "Diagnose the root cause".
Context injection goes beyond simple piping. When the input data is large — a full test suite output, a dependency tree, a database schema — you need to manage token consumption. Truncate inputs to relevant sections before piping. Use head, tail, grep, or jq to pre-filter data. The model processes everything you send, and irrelevant context dilutes the quality of the response. The best headless prompts are precise about what they send and what they ask for.
# Pipe git diff for review
git diff --staged | gemini -p "Review these staged changes for bugs"
# Pipe filtered logs for diagnosis
grep "ERROR" app.log | tail -50 | gemini -p "What is the root cause of these errors?"
# Pipe JSON API response for analysis
curl -s https://api.example.com/metrics | \
gemini -p "Summarize these metrics. Flag any anomalies." --output-format json
# Combine file content with explicit prompt
echo "File: $(cat src/auth.ts)" | \
gemini -p "Find security vulnerabilities in the authentication code above"
# Pipe dependency tree for audit
npm ls --json 2>/dev/null | \
gemini -p "Identify any known-vulnerable packages in this dependency tree"