Skip to content

Repository files navigation

critique

AI code review for your diffs — a CLI and GitHub Action powered by Claude.

CI TypeScript Powered by Claude License: MIT

critique sends a git diff to Claude and gets back structured review findings — each with a severity, category, confidence, and a concrete suggestion. Use it locally to review your changes before you push, or as a GitHub Action that comments on every pull request.

$ git diff | critique
Code review
Adds a retry helper but the backoff can overflow on high attempt counts.

[HIGH] Unbounded exponential backoff (performance)
  src/retry.ts:14
  `2 ** attempt` grows without limit and can exceed Number.MAX_SAFE_INTEGER.
  → Cap the exponent, e.g. Math.min(attempt, 10).

1 finding(s); highest severity: high

How it works

  • Uses the Claude API (@anthropic-ai/sdk) with structured outputs — the response is validated against a Zod schema, so findings are always well-formed (no brittle JSON parsing).
  • Defaults to claude-opus-4-8 with adaptive thinking at high effort; both are configurable.
  • Runs non-streaming with a bounded max_tokens, which keeps requests comfortably under timeouts.

Requirements

  • Node.js 20+
  • An Anthropic API key in ANTHROPIC_API_KEY

CLI

npm install -g critique
export ANTHROPIC_API_KEY=sk-ant-...

critique                     # review unstaged working changes
critique --staged            # review staged changes
critique --base main         # review your branch against main
git diff HEAD~3 | critique   # review a piped diff

critique --format markdown   # markdown (for PR comments)
critique --format json       # machine-readable
critique --fail-on high      # exit code 2 if a finding is >= high severity

Options

Option Description Default
-b, --base <ref> Review the diff against a base ref
-s, --staged Review staged changes
-f, --format pretty | markdown | json pretty
-m, --model Claude model to use claude-opus-4-8
-e, --effort low | medium | high | xhigh | max high
--fail-on Exit with code 2 if a finding meets/exceeds this severity

If no --base/--staged flag is given and nothing is piped in, critique reviews git diff.

GitHub Action

Add a workflow that reviews every pull request and posts the findings as a comment:

name: Code review
on: pull_request

permissions:
  contents: read
  pull-requests: write

jobs:
  critique:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # needed to diff against the base branch
      - uses: lasitosPT/critique@v1
        with:
          anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
          fail-on: high # optional: fail the check on high+ findings

Action inputs

Input Description Default
anthropic-api-key Anthropic API key (required)
model Claude model to use claude-opus-4-8
effort Reasoning effort high
fail-on Fail the job on findings at/above this severity (never)

Programmatic API

import { reviewDiff, formatMarkdown } from 'critique'

const review = await reviewDiff(diff, { model: 'claude-opus-4-8', effort: 'high' })
console.log(formatMarkdown(review))
// review.findings: { file, line, severity, category, title, description, suggestion, confidence }[]

reviewDiff accepts an injectable client, which makes it easy to unit-test without hitting the API.

Cost

Each review is a single Claude request over your diff. On the default claude-opus-4-8 ($5 / $25 per million input / output tokens), a typical PR-sized diff costs a few cents. Pass --model claude-haiku-4-5 for a cheaper, faster review when you don't need maximum depth.

License

MIT © Pedro Lascasas Pinto

About

AI code review for your diffs — a CLI and GitHub Action powered by Claude.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages