1212 words Slides

14.4 Claude as Unix Utility

Course: Claude Code - Enterprise Development Section: CI/CD & Automation Video Length: 2-5 minutes Presenter: Daniel Treasure


Opening Hook

Claude Code isn't just an interactive assistant — it's a Unix citizen. It reads from stdin, writes to stdout, and plays nicely with pipes. That means you can slot it into shell scripts, chain it with grep and jq, and use it the same way you'd use any other command-line tool.


Key Talking Points

1. The Unix Philosophy Applied to AI

  • Claude Code follows the Unix principle: do one thing, accept input, produce output
  • The -p (print) flag is the key — it makes Claude non-interactive
  • Input comes from stdin or the prompt string, output goes to stdout

What to say: "If you've ever piped grep into awk into sort, you already know the pattern. Claude fits right into that chain. The -p flag turns it into a filter — data in, result out, no interactive session."

What to show on screen: A simple pipe: echo "explain this error" | claude -p

2. Piping Data Into Claude

  • Pipe file contents: cat server.log | claude -p "find errors and summarize"
  • Pipe command output: git diff HEAD~3 | claude -p "summarize these changes"
  • Pipe from any tool: curl -s api.example.com/data | claude -p "analyze this JSON"
  • Claude receives the piped content as context alongside the prompt

What to say: "Anything you can pipe in Unix, you can pipe into Claude. Logs, diffs, API responses, CSV files — it all works. Claude sees the piped content as context."

What to show on screen: Run git log --oneline -20 | claude -p "categorize these commits by type"

3. Structured Output for Downstream Tools

  • --output-format json produces machine-readable output
  • --output-format stream-json for real-time JSON streaming
  • --json-schema forces output to match a specific structure
  • Plain text output works for human-readable pipelines

What to say: "The real power is structured output. Add --output-format json and now Claude's response is machine-parseable. Pipe it to jq, feed it to another script, or store it in a database. Add --json-schema and Claude will match your exact format."

What to show on screen: git diff | claude -p "list files changed" --output-format json | jq '.result'

4. Chaining Claude with Itself

  • Output from one Claude call can feed another
  • Build multi-step analysis pipelines
  • Each call is independent — no shared state between pipes

What to say: "Here's where it gets fun. You can chain Claude with itself. First call analyzes the problem, second call generates the fix. Each one is a focused, single-purpose step."

What to show on screen: claude -p "list the bugs in src/" --output-format json | claude -p "fix the first bug from this list"

5. Practical Script Examples

  • Log monitoring: tail -f app.log | claude -p "alert me to errors"
  • Batch processing: find . -name "*.py" -exec claude -p "add docstrings to {}" \;
  • CI integration: Use in shell scripts within CI pipelines
  • Cron jobs: Scheduled analysis and reporting

What to say: "In production, this looks like a cron job that tails your logs and flags anomalies. Or a CI step that reviews every Python file for missing docstrings. The pattern is always the same: data in, analysis out."

What to show on screen: Show a small shell script that uses Claude in a pipeline.


Demo Plan

  1. Basic pipeecho "What is the capital of France?" | claude -p
  2. ~15 seconds

  3. File analysiscat package.json | claude -p "list all dependencies and their purpose"

  4. ~20 seconds

  5. Git integrationgit log --oneline -10 | claude -p "categorize these commits"

  6. ~20 seconds

  7. Structured outputgit diff | claude -p "summarize changes" --output-format json | jq '.result'

  8. ~30 seconds

  9. Chain two callsclaude -p "list TODO comments in src/" | claude -p "prioritize these by importance"

  10. ~25 seconds

  11. Shell script — Show a 5-line script that combines multiple tools with Claude

  12. ~20 seconds

Code Examples & Commands

Basic stdin pipe:

echo "Explain Docker networking" | claude -p

File analysis:

cat error.log | claude -p "find the root cause of these errors"

Git diff summary:

git diff HEAD~5 | claude -p "summarize what changed and flag any risks"

Structured JSON output:

claude -p "list all functions in src/auth.py" --output-format json

JSON schema enforcement:

claude -p "extract names and emails" --output-format json --json-schema '{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"email":{"type":"string"}}}}'

Multi-step chain:

claude -p "find security issues in src/" --output-format json | \
  claude -p "for each issue in this JSON, suggest a fix"

Shell script example:

#!/bin/bash
# Daily code health report
echo "=== Code Health Report ===" > report.txt
git log --since="1 day ago" --oneline | claude -p "summarize today's commits" >> report.txt
git diff HEAD~1 | claude -p "flag any risky changes" >> report.txt
echo "Report saved to report.txt"

Cost-controlled batch processing:

claude -p "review this file" --max-turns 1 --max-budget-usd 0.05 < input.py

Gotchas & Tips

  1. Always use -p for scripting. Without it, Claude starts an interactive session that will hang in a pipe. The -p flag is what makes it non-interactive.

  2. Stderr vs stdout: Claude's progress output goes to stderr, results go to stdout. This means pipes only get the actual result, not the "thinking..." messages.

  3. Token limits in pipes: Large files piped to Claude still consume tokens. For huge logs, pre-filter with grep or tail before piping.

  4. --max-turns 1 for simple queries: In pipe mode, you usually want a single response, not an agentic loop. Set --max-turns 1 to prevent Claude from trying to use tools.

  5. Exit codes: Claude returns 0 on success. Use set -e in scripts to catch failures.

  6. Combine with --permission-mode dontAsk: For fully automated scripts, pair -p with dontAsk mode and explicit --allowedTools to control exactly what Claude can do.


Lead-out

"Claude as a Unix utility is one of those features that seems simple until you start combining it with your existing toolchain. Once you think of it as just another command in the pipe, the automation possibilities are wide open. That wraps up our CI/CD & Automation section — next we move into Enterprise Deployment."


Reference URLs


Prep Reading

  • Unix philosophy and pipe composition patterns
  • Review claude --help for all print-mode flags
  • Test pipe examples with actual project files before recording
  • Review 14.3 (Headless Mode) for overlap — this video focuses on composition, that one on automation modes

Notes for Daniel: This is a fun, demo-heavy video. The audience will love seeing Claude slotted into familiar Unix patterns. Keep the demos snappy — show the command, show the output, move on. The shell script at the end should be the "aha moment" where viewers see how to combine everything. Consider using a real project's git history for the demo so the output feels authentic rather than contrived.