Claude Tips mascot
Claude Tips & Tricks
Claude Code advanced

Run Claude Non-Interactively in CI Pipelines

Use claude -p to run Claude Code without a session, perfect for CI/CD pipelines, pre-commit hooks, and scripted workflows.

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"
Paste into Claude Code
Create a CI/CD pipeline step (GitHub Actions) that uses claude -p to automatically review PRs and post comments with suggestions.