Claude Code cheatsheet
Claude Code: Automation and CI
4 common Claude Code tasks.
Run Claude Code in CI
Run a non-interactive task with only the tools it needs and a turn limit. Review the changes before merging.
claude -p "Fix the failing tests" --allowedTools "Bash,Edit,Read" --max-turns 5
Caution: Give automated runs the least access they need, and never run them with unreviewed credentials.
Use an API key
Authenticate with an API key from the environment instead of signing in, which suits CI.
export ANTHROPIC_API_KEY="your-api-key"
Review a diff in a script
Pipe a diff to Claude and get a review back.
git diff main... | claude -p "review this diff for bugs"
Draft a commit message
Ask for a commit message from the staged changes.
git diff --staged | claude -p "write a concise commit message"