nitpicker 0.11.1

Multi-reviewer code review using LLMs with parallel agents and debate mode
# nitpicker

[![crates.io](https://img.shields.io/crates/v/nitpicker.svg)](https://crates.io/crates/nitpicker)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Multi-model adversarial code review for your terminal and CI.

Supported by [Archestra](https://github.com/archestra-ai/archestra)

[Free Web Version](https://arseny.info/nitpicker) for open source projects

---

Most LLM code reviews suffer from two failure modes: lazy rubber-stamping (*"Looks good! 🎉"*) or hallucinated pedantry (inventing fake bugs because the model lacks repo context).

nitpicker fixes this by pitching models against each other in an adversarial debate:

* **Actor-Critic dynamics**: The Reviewer (Actor) explores the codebase to maximize recall (finding plausible bugs and edge cases). The Validator (Critic) aggressively attempts to falsify those claims using actual repo evidence. Disputed claims are debated; only surviving findings make it to the report. The report preserves material limits on what the evidence supports.
* **Deep repo exploration**: Reviewers don't just stare at a 40-line `git diff`. They run tools (`read_file`, `grep`, `glob`, `git`) and spawn concurrent subagents to trace call graphs, check types, and verify assumptions before claiming an issue exists.
* **Model diversity & economics**: Pit different model families against each other (Claude vs. GPT vs. Gemini), or pair frontier models with fast, inexpensive models via OpenRouter (Qwen, DeepSeek, Kimi). Burn 1M tokens reviewing a complex PR without burning your monthly budget.
* **Production & CI ready**: Regularly used across several engineering orgs, including CI pipelines. Features deterministic exit codes (`0`, `1`, `3`), headless `--json` output, and OpenTelemetry tracing.

---

- [Quick Start]#quick-start
- [Common Workflows]#common-workflows
- [Review Lenses (Presets)]#review-lenses-presets
- [Configuration]#configuration
- [Providers & Authentication]#providers--authentication
- [Production & CI Integration]#production--ci-integration
- [Advanced Features]#advanced-features

---

## Quick Start

Building from source with `cargo install` requires Rust 1.97.1 or newer.

```bash
cargo install nitpicker
```

Set an API key for your preferred provider:

```bash
export ANTHROPIC_API_KEY="your-api-key"
# or: export OPENROUTER_API_KEY="your-api-key"
# or: export OPENAI_API_KEY="your-api-key"
```

Run a review:

```bash
# Review your current branch / uncommitted changes
nitpicker

# Review an open GitHub pull request and post the verdict as a comment
nitpicker pr https://github.com/owner/repo/pull/42

# Ask a technical or architectural question about the repo
nitpicker ask "should we use eyre or thiserror for error handling?"
```

---

## Common Workflows

### 1. Review Local Diffs
By default, nitpicker compares your current branch against its base branch using an adversarial debate:

```bash
nitpicker                                    # review current diff
nitpicker --repo /path/to/repo               # review another repo
nitpicker --prompt "focus on SQL injection"  # add custom reviewer instructions
nitpicker --no-debate                        # use parallel reviewers instead of debate
nitpicker --fallback                         # auto-failover to next reviewer if a model hits rate limits
```

### 2. GitHub PR Reviews & CI
Review PRs locally or in automated CI workflows (requires GitHub CLI `gh`):

```bash
# Review current branch's PR and comment on GitHub
nitpicker pr

# Review any remote PR by URL (clones into temp dir, reviews, cleans up)
nitpicker pr https://github.com/owner/repo/pull/42

# Review without posting a comment to GitHub
nitpicker pr https://github.com/owner/repo/pull/42 --no-comment

# Machine-readable output for CI pipelines (single JSON object on stdout)
nitpicker pr https://github.com/owner/repo/pull/42 --no-comment --json
```

### 3. Ask Architecture & Design Questions
Debate design choices or sanity-check logic across your codebase:

```bash
nitpicker ask "is our token refresh flow thread-safe?"
nitpicker ask --rounds 3 "should we split this crate into a workspace?"
nitpicker ask --no-debate "how does configuration loading work?"
```

### 4. Audit Existing Code (Static Analysis)
Audit existing codebases without needing an active diff:

```bash
nitpicker --analyze src/auth/                # audit a specific directory
nitpicker --analyze                          # audit the entire repository
```

### 5. Second Opinion from Your Coding Agent
The [`second-opinion`](https://github.com/arsenyinfo/skills/tree/main/skills/second-opinion) skill lets Claude Code (and other skill-aware agents) hand a diff, PR, plan, or contested claim to nitpicker for an independent review. If nitpicker isn't installed, it falls back to codex or opencode.

---

## Review Lenses (Presets)

Instead of generic feedback, review against targeted rubrics. Presets control what to investigate, while debate or parallel modes control how.

```bash
nitpicker --preset security                  # focus strictly on vulnerabilities
nitpicker --preset security,performance      # run both security and performance lanes
nitpicker --preset ai-systems                # audit agent prompts, tools, and context boundaries
nitpicker --preset ml-rigor                  # audit ML pipelines, data leakage, and eval hygiene
```

### Built-in Presets

| Preset | Focus Area |
|---|---|
| `correctness` | Logic bugs, race conditions, edge cases, error handling, off-by-one errors. *(Default)* |
| `security` | Injection, auth boundaries, input validation, secret leaks, SSRF. *(Default)* |
| `performance` | Unnecessary allocations, N+1 queries, async blocking, algorithmic complexity. *(Default)* |
| `simplicity` | Over-engineering, dead code, redundant abstractions, readability. *(Default)* |
| `ai-systems` | Agent tool schemas, prompt injection vectors, context truncation, deterministic fallbacks. *(Opt-in)* |
| `ml-rigor` | Training/validation leakage, metric gaming, distribution shift, silent failures. *(Opt-in)* |
| `tone` | Clarity, audience fit, terminology consistency, documentation voice. *(Opt-in)* |
| `general` | Broad standalone review for unconventional targets. Cannot be combined with other presets. |

You can also define custom presets in `nitpicker.toml`:

```toml
[presets.api-security]
prompt = """
Review API trust boundaries, JWT verification, and rate-limiting.
Require a concrete attacker-controlled call path for every finding.
"""
```

---

## Configuration

Initialize a configuration file:

```bash
nitpicker init             # creates ./nitpicker.toml
nitpicker init --global    # creates ~/.nitpicker/config.toml
nitpicker init --free      # configures free OpenRouter models
```

Configuration resolution order: `--config <path>` > `./nitpicker.toml` > `~/.nitpicker/config.toml`.

### Example `nitpicker.toml`

```toml
[defaults]
debate = true          # use Actor-Critic debate (default: true)
fallback = true        # failover to next reviewer if a provider rate-limits (default: false)
max_turns = 100        # tool-use loop limit per agent
# presets = ["correctness", "security"]  # default includes performance and simplicity

# Model that synthesizes the final report from surviving debate findings
[aggregator]
model = "claude-sonnet-5-5"
provider = "anthropic"
max_tokens = 16384

# Reviewer 1 (Actor / Discovery)
[[reviewer]]
name = "claude"
model = "claude-sonnet-5-5"
provider = "anthropic"

# Reviewer 2 (Critic / Validator)
[[reviewer]]
name = "gpt"
model = "gpt-6.1-sol"
provider = "openai"

# Reviewer 3 (Fast / Inexpensive via OpenRouter)
[[reviewer]]
name = "qwen"
model = "qwen/qwen3.5-35b-a3b"
provider = "openrouter"
```

> **Tip:** Pair different model families to avoid shared blind spots.

---

## Providers & Authentication

| Provider | Authentication | Notes |
|---|---|---|
| `anthropic` | `ANTHROPIC_API_KEY` | Automatic 5-minute prompt caching enabled by default. |
| `openai` | `OPENAI_API_KEY` | Compatible with OpenAI models and custom OpenAI gateways. |
| `codex` *(OpenAI)* | Reuses `~/.codex/auth.json` | Uses your existing ChatGPT Plus/Pro subscription token from OpenAI Codex CLI. No API key needed. [Details below]#chatgpt--codex-subscription. |
| `grok` *(xAI)* | Reuses `~/.grok/auth.json` | Uses your Grok Build CLI OAuth token (`grok login`). No API key needed. [Details below]#grok-cli-subscription. |
| `openrouter` | `OPENROUTER_API_KEY` | Access open-weights & Chinese frontier models (Qwen, DeepSeek, Kimi, GLM). |
| `opencode` | `OPENCODE_API_KEY` | OpenCode Console (formerly Zen), pay-as-you-go. |
| `opencode-go` | `OPENCODE_API_KEY` | OpenCode Go subscription; preserves a session ID across each agent's turns. |
| `gemini` | `GEMINI_API_KEY` | Google Gemini models via official API. |
| `azure` *(Entra ID)* | `auth = "azure-ad"` | Azure AI Foundry models with auto-refreshing tokens (requires `--features azure`). |

### ChatGPT / Codex Subscription
If you have a ChatGPT Plus or Pro subscription and the [OpenAI Codex CLI](https://developers.openai.com/codex) installed, nitpicker can authenticate through your subscription without a separate paid API key:

```bash
# 1. Log in once via the official Codex CLI
codex login

# 2. Configure nitpicker to reuse the token (read-only)
```

```toml
[[reviewer]]
name = "codex"
model = "gpt-6.1-sol"
provider = "openai"
auth = "codex"
```

### Grok CLI Subscription
If you have logged in with the [Grok Build CLI](https://github.com/xai-org/grok-build) (`grok login`), nitpicker can reuse the OAuth token from `~/.grok/auth.json` (read-only) without a separate `XAI_API_KEY` (research only):

```bash
# 1. Log in once via the Grok Build CLI
grok login

# 2. Configure nitpicker to reuse the token (read-only)
```

```toml
[[reviewer]]
name = "grok"
model = "grok-4.7"
provider = "openai"
auth = "grok"
```

### OpenRouter & Model Economics
For high-volume reviews, OpenRouter gives you access to cost-effective models with large context windows:

```toml
[[reviewer]]
name = "deepseek"
model = "deepseek/deepseek-v4.1-flash-1017"
provider = "openrouter"

# Or experimental auto-selection of currently available free models:
[[reviewer]]
model = "free"
provider = "openrouter"
```

### OpenCode Console & Go

Use an API key from [OpenCode Console](https://opencode.ai/console) and set
`provider = "opencode"` for pay-as-you-go or `provider = "opencode-go"` for Go.
Use the model ID without the provider prefix. Console's free chat models are
restricted to the OpenCode client.

```toml
[[reviewer]]
name = "opencode-go"
provider = "opencode-go"
model = "glm-5.3"
```

---

## Production & CI Integration

### Deterministic Exit Codes

nitpicker uses standard exit codes designed for automated pipelines and scripts:

| Code | Meaning | CI Recommendation |
|:---:|---|---|
| `0` | Clean verdict | Pass pipeline |
| `1` | Hard failure (network error, bad config, missing keys) | Fail pipeline / Alert |
| `2` | CLI usage error (invalid flags) | Fix CI script |
| `3` | Degraded verdict (report printed, but a reviewer/turn failed) | Warning / Soft alert |

A degraded preset review also starts with a one-line `⚠️ Partial review` note naming the angles that were not reviewed, so a PR comment reading "No findings" is never mistaken for full coverage.

### Headless JSON Output
With `nitpicker pr <url> --json`, nitpicker emits exactly one JSON object on `stdout` with structured findings, token metrics, and coverage data. All progress bars, logs, and diagnostic traces are strictly sent to `stderr`:

```bash
OUTPUT=$(nitpicker pr https://github.com/org/repo/pull/42 --no-comment --json)
STATUS=$(echo "$OUTPUT" | jq -r '.status')
DEGRADED=$(echo "$OUTPUT" | jq -r '.degraded')
```

### OpenTelemetry Tracing
Export every run as an [OpenTelemetry](https://opentelemetry.io) trace (requires `--features otel`):

```bash
cargo install nitpicker --features otel

export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"
export OTEL_SERVICE_NAME="nitpicker"
nitpicker pr https://github.com/owner/repo/pull/42
```

Traces adhere to standard GenAI semantic conventions (`gen_ai.*`), recording token usage, model failovers, tool latencies, and retry attempts. Sensitive prompt text and proprietary repository source code are never exported.

---

## Advanced Features

### External Design Docs (`--context-file`)
Reviewers are sandboxed inside the git repository. If your review needs external context (e.g. an RFC, architecture doc, or migration plan located elsewhere on disk), inject it safely:

```bash
nitpicker --context-file ~/docs/rfc-42.md --context-file /tmp/spec.md
```

### Automatic Fallback Rings (`--fallback`)
Avoid losing 10 minutes of deep review to transient 429 rate-limits. When `--fallback` is enabled, any reviewer that exhausts retries automatically hands its history and completed tool outputs to the next configured model in the ring.

### Self-Reflection (`nitpicker reflect`)
Analyze past review sessions to diagnose recurring false positives, agent friction, and tool loops:

```bash
# Enable trajectory logging in your config:
# [defaults]
# log_trajectories = true

nitpicker reflect          # inspect recent sessions
nitpicker reflect --n 10   # inspect last 10 runs
nitpicker reflect --dump out/   # write formatted session dossiers only, no LLM calls
```

From Claude Code, the `reflect` workflow (`.claude/workflows/reflect.js`) runs the same pipeline on a Claude subscription: it builds dossiers with `--dump`, analyzes each session, and then writes a synthesis that has been checked against the repo. It reads the same `prompts/reflect/` instructions as the CLI.

### Rust Library (`nitpicker-agent`)
The underlying agentic loop and file/git tools are published as a standalone crate [`nitpicker-agent`](crates/nitpicker-agent):

```rust
use nitpicker_agent::prelude::*;
use std::path::Path;

#[tokio::main]
async fn main() -> eyre::Result<()> {
    let client = client_from_env(LLMProvider::Anthropic { base_url: None, api_key_env: None })?;
    let result = AgentBuilder::new("explorer", "claude-sonnet-5-5", "You explore codebases.", client)
        .run("Map the module layout of this repo.", &file_agent_tools(), Path::new("."))
        .await?;

    println!("{}", result.text);
    Ok(())
}
```

<details>
<summary>Experimental: Antigravity Keyring Auth (Research Only)</summary>

> [!CAUTION]
> Research only. AG2 is Google's internal agentic IDE backend. `auth = "agy-keyring"` reads the `agy` CLI OAuth token from the system keyring to evaluate `gemini-3.x` models. Google actively monitors and suspends accounts using third-party OAuth bridges. For standard Gemini access, use `GEMINI_API_KEY`.

Build with `--features antigravity`. The default model for this auth path is
`gemini-3.8-flash-tiered`; use that exact backend ID rather than the `agy` CLI's
`gemini-3.8-flash-low` alias.
</details>

---

For contributors, the binary keeps argument parsing in `src/cli.rs`, config loading and
routing settings in `src/settings.rs`, and config generation in `src/init.rs`.
Command dispatch remains in `src/main.rs`; PR-specific config trust and output handling
live in `src/pr.rs`. See [CLAUDE.md](CLAUDE.md) for the full architecture.

## Changelog

See [CHANGELOG.md](CHANGELOG.md) for version release notes.