ClaudeHack
0

Run Claude headless in CI with --print and JSON output

Scheduled Tasks / Automation·13 hours ago·verified 13 hours ago·hard·~30 min setup·verified

Use `claude --print --output-format json` in GitHub Actions to automate reviews or summaries without an interactive TTY.

The problem

Interactive Claude Code cannot run in CI, so teams skip automated AI checks on pull requests.

The hack

Install Claude Code in the workflow, pass a fully specified prompt with `--print`, and parse JSON for PR comments.

Why it works

Headless mode exits with stdout you can pipe into `gh` or github-script—ideal for mechanical first-pass reviews.

Setup

1. Store `ANTHROPIC_API_KEY` as a repo secret. 2. On pull_request, checkout with sufficient fetch-depth for diffs. 3. Run `claude --print --output-format json "Review this diff for bugs and missing tests..."`. 4. Post the parsed result as a PR comment; use continue-on-error if you do not want API blips to fail the pipeline.

Code

claude --print --output-format json "Review the PR diff for security issues, bugs, and missing tests."

Additional details

Keep prompts unambiguous—headless Claude cannot ask clarifying questions.

Source

anthropic·View original →·by Community

Does this still work?

0 said it works · 0 said it's broken

Discussion

No comments yet. Be the first to say whether this worked for you.