The -p flag runs Claude Code as a one-shot command with no interactive session and no UI. This is how you integrate Claude into automated workflows.
Basic Usage
# Code review in CI
claude -p "Review this diff for bugs and security issues: $(git diff main...HEAD)"
# Generate commit message
claude -p "Generate a concise commit message for: $(git diff --staged)"
# Pre-commit check
claude -p "Check this code for obvious bugs: $(git diff --cached)"
GitHub Actions Example
- name: AI Code Review
run: |
REVIEW=$(claude -p "Review this diff for bugs and security issues. Be concise. $(git diff ${{ github.event.pull_request.base.sha }}...HEAD)")
gh pr comment ${{ github.event.pull_request.number }} --body "$REVIEW"
Structured Output
claude -p "Classify this log entry: '$LOG_LINE'" --output-format json
Returns structured JSON you can parse in scripts, making Claude a building block in larger automation pipelines.
Pipe Input
# Summarize a file
cat README.md | claude -p "Summarize the key points"
# Generate docs
cat src/api.ts | claude -p "Generate JSDoc comments for all exported functions"