CC-201d · Module 2
API Usage Patterns
4 min read
The Claude Code CLI is not just an interactive terminal. It is a programmable interface. The --print flag turns Claude Code into a Unix pipe-friendly tool that accepts input, processes it, and returns output — no interactive session, no approval prompts, no conversation. This is the bridge between Claude Code and every other tool in your development stack.
Consider: "echo 'Review this PR for security issues' | claude --print --allowedTools bash,read" — that is a one-liner that can be called from a Makefile, a shell script, a GitHub Action, or a cron job. Claude reads the prompt from stdin, executes using only the allowed tools, and writes the result to stdout. No session management. No context persistence. Just input, process, output.
The --print flag changes the mental model fundamentally. Interactive Claude Code is a development partner you converse with. CLI-mode Claude Code is a function you call. And functions compose. You can chain Claude Code invocations with Unix pipes: "git diff HEAD~1 | claude --print 'Summarize these changes for a changelog' | tee CHANGELOG-entry.md" — that is a pipeline that takes a git diff, summarizes it, and writes the summary to a file. Three tools, one pipeline, zero interaction.
The --allowedTools flag is critical for non-interactive use. In an interactive session, you approve each tool use. In --print mode, there is no approval step — Claude executes whatever tools it needs. Constraining the allowed tools is how you maintain safety. For a code review pipeline, you might allow read and bash but deny write. For a documentation generator, you might allow read and write but deny bash. The tool allowlist is your security boundary.
# One-shot code review
git diff --staged | claude --print "Review for bugs and security issues"
# Generate changelog entry from recent commits
git log --oneline -10 | claude --print "Write a changelog entry" > CHANGELOG.md
# Analyze test failures
npm test 2>&1 | claude --print "Explain why these tests failed and suggest fixes"
# Constrained tool access for safety
claude --print --allowedTools read,bash "Audit src/ for SQL injection"
# Pipe between Claude invocations
claude --print "List all API endpoints in src/" | \
claude --print "Generate OpenAPI spec for these endpoints"