Skip to content

Claude Code as a Unix-Style Tool

Claude Code is not only an interactive terminal assistant. In print mode, it can behave like a command-line tool: read stdin, process a prompt, write stdout, and exit.

This is useful for logs, diffs, release notes, CI checks, and small repeatable analyses.

Terminal window
git log --oneline -20 | claude -p "Summarize these recent commits"

The -p flag is short for print mode. Use it when you want a non-interactive result instead of an ongoing terminal session.

Use caseExample
Commit summary`git log —oneline -20
Build failure explanation`npm test 2>&1
Release note draft`git diff v1.2.0..HEAD
PR risk scan`git diff main
Structured extractionclaude -p "extract changed modules" --output-format json

For reproducible scripts and CI jobs, prefer --bare when you do not want local memory, hooks, skills, plugins, or MCP configuration to affect the run.

Terminal window
git diff main | claude --bare -p \
"Review this diff for typo-level issues only. Return filename and issue."

Use normal print mode without --bare when the run should honor project instructions, local tools, skills, or memory.

For scripts, plain text is fragile. Prefer JSON when another command needs to parse the result.

Terminal window
git diff main | claude --bare -p \
"Summarize the diff in one paragraph" \
--output-format json | jq -r '.result'

For stricter automation, use a JSON schema if your installed Claude Code version supports it.

If all context is piped in, Claude may not need permission to run commands.

If you ask it to inspect files or run tests, allow only the tools and commands needed:

Terminal window
claude -p "Run the focused auth tests and explain any failures" \
--allowedTools "Read,Bash(npm test *)"

Avoid broad command allowlists in unattended scripts. For cloud CLIs, deployment tools, and database commands, prefer read-only commands, dry runs, and least-privilege credentials.

Use an interactive session instead when:

  • the task needs back-and-forth clarification
  • the agent may need to edit many files
  • permissions require human judgment
  • you need to review a plan before implementation
  • the input is too large for stdin and should be referenced as files