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.
Basic Pattern
Section titled “Basic Pattern”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.
Good Uses
Section titled “Good Uses”| Use case | Example |
|---|---|
| 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 extraction | claude -p "extract changed modules" --output-format json |
Use --bare For Scripts
Section titled “Use --bare For Scripts”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.
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.
Structured Output
Section titled “Structured Output”For scripts, plain text is fragile. Prefer JSON when another command needs to parse the result.
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.
Tool Permissions
Section titled “Tool Permissions”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:
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.
When Not To Use Print Mode
Section titled “When Not To Use Print Mode”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