# Warden

> Agents that review your code. Locally or on every PR.

Warden watches over your code by running **skills** against your changes. Skills are prompts that define what to look for: security vulnerabilities, API design issues, performance problems, or anything else you want consistent coverage on.

Skills follow the [agentskills.io](https://agentskills.io) specification. They're markdown files with a prompt that tells the AI what to look for. Warden includes `security-review` for baseline AppSec coverage, `code-review` for correctness bugs, and `integrity-review` for destructive, concealed, or trigger-gated changes. Treat them as first passes, and add more skills when you need deeper coverage.

- Docs: https://warden.sentry.dev
- GitHub: https://github.com/getsentry/warden
- npm: https://www.npmjs.com/package/@sentry/warden

## How It Works

Every time you run Warden, it:

1. Identifies what changed (files, hunks, or entire directories)
2. Matches changes against configured triggers
3. Runs the appropriate skills against matching code
4. Reports findings with severity, location, and optional fixes

Architecture details: https://warden.sentry.dev/architecture/

## Architecture Flow

Warden has three entry paths and one review pipeline:

- CLI runs start from local git state or explicit file targets.
- Pull request reviews start from a GitHub event payload.
- Scheduled reviews start from cron workflows and configured paths.

All entry paths build a review context, resolve `warden.toml`, match triggers, and run skill tasks through the same analysis engine.

The review pipeline is:

1. Changed code becomes an event context.
2. Config and triggers decide which skills run and which files they see.
3. Matched triggers become skill tasks with model, runtime, chunking, verification, and output settings.
4. Warden prepares diffs by parsing patches, applying chunking rules, coalescing nearby hunks, expanding context, and grouping hunks by file.
5. Main analysis agents run the resolved `SKILL.md` prompt against prepared hunks.
6. Post-processing agents extract and validate findings, verify candidates, merge same-root-cause findings, and check suggested fixes.
7. Reports render to terminal output, JSONL logs, GitHub Checks, and GitHub review comments.

Agent lanes:

- Main analysis uses `defaults.agent.model`, skill `model`, or trigger `model`.
- Auxiliary work uses `defaults.auxiliary.model` for structured helper calls such as extraction repair, verification, fix gates, deduplication, and fix evaluation.
- Synthesis uses `defaults.synthesis.model` for cross-location finding consolidation.

Warden works in two contexts:

- **Locally** - Review changes before you push, get instant feedback
- **In CI** - Automatically review pull requests, post findings as comments

## Quick Start

### Install

```bash
# npm
npm install -g @sentry/warden

# pnpm
pnpm add -g @sentry/warden

# bun
bun add -g @sentry/warden
```

### Initialize

```bash
warden init
```

Creates `warden.toml` (configuration) and `.github/workflows/warden.yml` (GitHub Actions workflow).

### Add a Skill

```bash
warden add security-review
warden add code-review
warden add integrity-review
```

### Run Locally

```bash
warden
```

### Authentication

Warden runs model-backed work through Pi. Set a model and the matching WARDEN-prefixed provider key:

```bash
# OpenAI example
export WARDEN_MODEL=openai/gpt-5.5
export WARDEN_OPENAI_API_KEY=sk-...

# Anthropic example
export WARDEN_MODEL=anthropic/claude-sonnet-4-6
export WARDEN_ANTHROPIC_API_KEY=sk-ant-...
```

CI/CD environments require provider credentials.

## CLI Commands

### warden

```
warden [targets...] [options]
```

Run code analysis on the specified targets. If no target is given, analyzes uncommitted changes.

```bash
warden                     # Analyze uncommitted changes (default)
warden src/auth.ts         # Analyze specific file
warden src/api/            # Analyze a directory
warden @targets.txt        # Analyze targets listed in a file
warden HEAD~3..HEAD        # Analyze changes in a git range
warden main..HEAD          # Analyze all commits not on main
```

### warden init

```
warden init [options]
```

Initialize Warden in your project. Creates a configuration file and GitHub workflow.

- `-f, --force` - Overwrite existing files

### warden add

```
warden add [skill-name] [options]
```

Add a skill trigger to your configuration.

- `skill-name` - Name of the skill to add (optional, interactive if omitted)
- `--remote <owner/repo[@sha]>` - Install skill from a GitHub repository
- `--list` - List available skills

```bash
warden add                     # Interactive mode
warden add security-review     # Add baseline security review
warden add code-review         # Add correctness bug review
warden add integrity-review    # Add change integrity review
warden add --list              # List available skills
warden add --remote your-org/warden-skills --skill api-review
warden add --remote your-org/warden-skills@abc123 --skill api-review  # Pinned to commit
```

### warden sync

```
warden sync [remote]
```

Update cached remote skills. Refreshes unpinned skills to their latest versions.

- `remote` - Specific remote to sync (e.g., `owner/repo`). If omitted, syncs all.

### warden setup-app

```
warden setup-app [options]
```

Create a GitHub App for Warden. Gives you a custom bot identity instead of the generic "github-actions" user.

- `--org <name>` - Create the app for an organization
- `--port <number>` - Local server port (default: 3000)
- `--timeout <sec>` - Callback timeout in seconds (default: 300)
- `--name <string>` - Custom app name (default: Warden)
- `--no-open` - Print URL instead of opening browser

### Global Options

- `--skill <name-or-path>` - Run a specific skill by name or path
- `--fix` - Automatically apply suggested fixes
- `--json` - Output results as JSON
- `--fail-on <level>` - Exit with error code if findings meet severity: `critical`, `high`, `medium`, `low`
- `--config <path>` - Path to config file (default: `warden.toml`)
- `--verbose` - Show detailed output
- `-m, --model <model>` - Model to use (fallback when not set in config)
- `--effort <level>` - Override effort level for this run: `off`, `low`, `medium`, `high`, `xhigh`
- `-o, --output <path>` - Write full run output to a JSONL file
- `--report-on <severity>` - Only show findings at or above this severity
- `--parallel <n>` - Max concurrent trigger/skill executions (default: 4)
- `--quiet` - Errors and final summary only
- `-vv` - Show debug info (token counts, latencies)
- `--color / --no-color` - Override color detection
- `--git` - Treat ambiguous targets as git refs instead of file paths
- `--log` - Non-TTY output with timestamps
- `--debug` - Debug-level output (implies verbose)
- `--offline` - Use cached remote skills only, skip network fetches
- `--fail-fast` - Stop after first finding

## Configuration

Warden is configured via `warden.toml` in your repository root.

```toml
version = 1

[[skills]]
name = "security-review"

[[skills.triggers]]
type = "pull_request"
actions = ["opened", "synchronize", "reopened", "labeled"]
draft = false
labels = ["Warden"]

[[skills]]
name = "code-review"

[[skills.triggers]]
type = "pull_request"
actions = ["opened", "synchronize", "reopened", "labeled"]
draft = false
labels = ["Warden"]
```

### Skills

Skills define what Warden analyzes and when.

| Field | Description |
|-------|-------------|
| `name` | Skill name or path |
| `paths` | Files to include (glob patterns) |
| `ignorePaths` | Files to exclude (glob patterns) |
| `failOn` | Minimum severity to fail: `critical`, `high`, `medium`, `low`, `info`, `off` |
| `reportOn` | Minimum severity to report |
| `remote` | GitHub repository for remote skills: `owner/repo` or `owner/repo@sha` |
| `model` | Override the main agent model for this skill |
| `maxTurns` | Max agentic turns per hunk |

### Triggers

Triggers define when a skill runs. Each skill can have one or more triggers. Triggers can override output settings and the main agent model.

| Field | Description |
|-------|-------------|
| `type` | `pull_request`, `local`, `schedule` |
| `actions` | Event actions for `pull_request` type |
| `draft` | Draft state for `pull_request` type |
| `labels` | Pull request labels that can also match the trigger |
| `failOn` | Override failure threshold |
| `reportOn` | Override reporting threshold |
| `maxFindings` | Override max findings |
| `reportOnSuccess` | Override report-on-success behavior |
| `requestChanges` | Override REQUEST_CHANGES behavior |
| `failCheck` | Override check failure behavior |
| `model` | Override the main agent model for this trigger |
| `maxTurns` | Override max agentic turns |

Pull request actions: `opened`, `synchronize`, `reopened`, `closed`, `labeled`.

Label opt-in example:

```toml
[[skills]]
name = "security-review"

[[skills.triggers]]
type = "pull_request"
actions = ["opened", "synchronize", "reopened", "labeled"]
draft = false
labels = ["Warden"]
```

### Filters

Control which files are analyzed using glob patterns at the skill level.

```toml
[[skills]]
name = "api-review"
paths = ["src/api/**/*.ts"]
ignorePaths = ["**/*.test.ts"]

[[skills.triggers]]
type = "pull_request"
actions = ["opened", "synchronize"]
```

### Output

Control how findings are reported. Set at the skill level or in defaults.

| Field | Default | Description |
|-------|---------|-------------|
| `failOn` | - | Minimum severity to fail |
| `reportOn` | - | Minimum severity to report |
| `maxFindings` | - | Maximum findings to report |
| `reportOnSuccess` | `false` | Post comment when no findings |
| `requestChanges` | `false` | Use REQUEST_CHANGES review event |
| `failCheck` | `false` | Fail the check run |

### Defaults

Default settings inherited by all skills. Individual skills can override output
settings and the main agent model.

```toml
[defaults]
failOn = "high"
reportOn = "medium"
requestChanges = false
failCheck = false
ignorePaths = ["**/vendor/**", "**/node_modules/**"]
```

### Models and Runtimes

Runtime is configured under `[defaults]`. The default runtime is `pi`.

```toml
[defaults]
runtime = "pi"

[defaults.agent]
model = "anthropic/claude-sonnet-4-6"
maxTurns = 30
effort = "medium"

[defaults.auxiliary]
model = "anthropic/claude-haiku-4-5"
effort = "high"
maxRetries = 3

[defaults.synthesis]
model = "anthropic/claude-opus-4-5"
```

Runtime values:

- `pi` - default. Model values must use `provider/model` selectors such as `openai/gpt-5.5` or `anthropic/claude-sonnet-4-6`.
- `claude` - runs through Claude Code. Use Claude Code model IDs and Anthropic API key or Claude Code OAuth auth.

Runtime selection is global within a config layer. `runtime` is not currently a skill-level or trigger-level field.

Model lanes:

- `defaults.agent.model` - main repo-aware skill analysis. Preferred default model field.
- `defaults.agent.effort` - optional repo-aware skill effort. Supported values are `off`, `low`, `medium`, `high`, `xhigh`, and `max`.
- `defaults.auxiliary.model` - structured helper calls such as extraction, repair, merging, dedupe, and fix evaluation.
- `defaults.auxiliary.effort` - optional reasoning effort for Pi-backed auxiliary structured calls. Claude structured helper calls currently ignore this field.
- `defaults.synthesis.model` - post-analysis synthesis and consolidation. Falls back to `defaults.auxiliary.model` when unset.

`defaults.model` and `defaults.maxTurns` are legacy shorthand for the agent lane.

Main agent model precedence: trigger `model` > skill `model` > `defaults.agent.model` > legacy `defaults.model` > CLI flag (`-m`) > env var (`WARDEN_MODEL`) > SDK/runtime default.

Auxiliary and synthesis models only come from `[defaults.auxiliary]` and `[defaults.synthesis]`. They do not inherit skill or trigger `model` overrides.

Effort is separate from model selection. For local runs, `--effort` overrides `defaults.agent.effort` for that invocation. Without either setting, each runtime uses its own default. `defaults.auxiliary.effort` is independent of `--effort` and only affects the auxiliary lane.

Generated skill commands (`warden build` and `warden improve`) use the synthesis lane. Their model fallback order is `defaults.synthesis.model` > `defaults.auxiliary.model` > CLI flag (`-m`) > env var (`WARDEN_MODEL`) > SDK/runtime default.

### Chunking

Control how files are split for analysis.

File pattern modes:

- `per-hunk` - Analyze each diff hunk separately (default)
- `whole-file` - Analyze entire file as one chunk
- `skip` - Skip the file entirely

Coalescing (merge nearby hunks for better context):

| Field | Default | Description |
|-------|---------|-------------|
| `enabled` | `true` | Enable hunk coalescing |
| `maxGapLines` | `30` | Max lines between hunks to merge |
| `maxChunkSize` | `8000` | Target max chunk size in characters |

```toml
[defaults.chunking]

[[defaults.chunking.filePatterns]]
pattern = "**/pnpm-lock.yaml"
mode = "skip"

[[defaults.chunking.filePatterns]]
pattern = "**/migrations/*.sql"
mode = "whole-file"

[defaults.chunking.coalesce]
enabled = true
maxGapLines = 50
maxChunkSize = 10000
```

### Schedule Triggers

Run on a cron schedule instead of PR events. Requires `paths` to specify which files to scan.

| Field | Default | Description |
|-------|---------|-------------|
| `issueTitle` | `"Warden: {name}"` | Title for the tracking issue |
| `createFixPR` | `false` | Create PR with fixes when available |
| `fixBranchPrefix` | `warden-fix` | Branch prefix for fix PRs |

```toml
[[skills]]
name = "security-review"
paths = ["src/**/*.ts"]

[[skills.triggers]]
type = "schedule"
createFixPR = true
```

### Skill References

Skills can be referenced in multiple ways:

```toml
# By name (repo-local first, then built-in skills)
[[skills]]
name = "security-review"

[[skills]]
name = "code-review"

# By relative path
[[skills]]
name = "./custom-skills/my-review"

# Remote skill (unpinned - checks for updates every 24h)
[[skills]]
name = "api-review"
remote = "your-org/warden-skills"

# Remote skill (pinned to commit - cached permanently)
[[skills]]
name = "api-review"
remote = "your-org/warden-skills@abc123def"
```

Resolution order:

1. Remote repository (if `remote` field is specified)
2. Direct path (if skill contains `/`, `\`, or starts with `.`)
3. Conventional directories: `.warden/skills/`, `.agents/skills/`, `.claude/skills/`
4. Built-in skills, including `security-review` and `code-review`

### Environment Variables

| Variable | Description |
|----------|-------------|
| `WARDEN_MODEL` | Fallback model selector when config and CLI do not set one |
| `WARDEN_OPENAI_API_KEY` | OpenAI API key for OpenAI Pi models |
| `WARDEN_ANTHROPIC_API_KEY` | Anthropic API key for Anthropic Pi models or Claude runtime |
| `WARDEN_SKILL_CACHE_TTL` | Cache duration for unpinned remote skills. Default: 24h |

## Creating Skills

Skills are markdown files that tell Warden what to look for. They follow the [agentskills.io](https://agentskills.io) specification.

### Directory Structure

```
.warden/skills/skill-name/SKILL.md   # Warden-local generated skills
.agents/skills/skill-name/SKILL.md   # Primary (recommended)
.claude/skills/skill-name/SKILL.md   # Backup (Claude Code convention)
```

### SKILL.md Format

A skill has YAML frontmatter for metadata and markdown for the prompt:

```markdown
---
name: api-review
description: Review API changes for compatibility and contract issues
allowed-tools: Read Grep Glob
---

Review API changes for:
- Breaking response shape changes
- Missing pagination on list endpoints
- Inconsistent error response formats
- New endpoints without authentication checks

Focus on issues in the changed code. For each issue found, report:
- The specific contract or compatibility risk
- Why it's a problem
- How to fix it
```

### Frontmatter Fields

| Field | Description |
|-------|-------------|
| `name` | Skill identifier (must match directory name) |
| `description` | Brief description of what the skill does |
| `allowed-tools` | Space-separated list of tools the skill can use |

### Available Tools

`Read`, `Grep`, `Glob`, `Edit`, `Write`, `Bash`, `WebFetch`, `WebSearch`

Most review skills only need `Read`, `Grep`, and `Glob` for exploring context.

**Note:** Warden restricts execution to read-only tools (`Read` and `Grep`) regardless of what the skill declares in `allowed-tools`. This ensures skills cannot modify your codebase during analysis.

### What Makes a Good Skill

- **Specific scope** - One skill, one concern. "Security review" not "code quality"
- **Clear criteria** - What counts as an issue? What severity?
- **Actionable output** - Findings should include how to fix
- **Examples** - Show what good and bad code looks like

## Pull Request Reviews

Warden runs automatically on pull requests via GitHub Actions and reports findings in Checks. When findings can be tied to the current pull request diff, Warden also posts inline review comments.

### Organization Setup

Add these as organization or repository secrets:

| Secret | Description |
|--------|-------------|
| `WARDEN_MODEL` | Fallback model selector when config does not set one |
| `WARDEN_OPENAI_API_KEY` | OpenAI API key for OpenAI Pi models |
| `WARDEN_ANTHROPIC_API_KEY` | Anthropic API key for Anthropic Pi models or Claude runtime |
| `WARDEN_SENTRY_DSN` *(optional)* | Sentry DSN for telemetry |

### Repository Setup

```bash
npx @sentry/warden init
```

Creates `warden.toml` and `.github/workflows/warden.yml`.

### What Happens on a PR

1. PR is opened or updated
2. GitHub Actions runs the Warden workflow
3. Warden analyzes changed files against configured triggers
4. Findings are reported in Checks. Eligible findings are also posted as inline review comments
5. If `requestChanges` is enabled, the review requests changes when findings exceed `failOn`
6. If `failCheck` is enabled, the check run fails when findings exceed `failOn`

Warden skips PR review feedback when the workflow run is no longer analyzing the current PR head. If the current head cannot be verified, Warden skips the write and fails the run rather than silently dropping a blocking review. Non-blocking findings without an inline diff location stay in Checks instead of creating timeline comments that cannot be resolved later.

### GitHub Actions Workflow

```yaml
name: Warden

permissions:
  contents: write
  pull-requests: write
  checks: write

on:
  pull_request:
    types: [opened, synchronize, reopened, labeled]

env:
  WARDEN_MODEL: ${{ secrets.WARDEN_MODEL }}
  WARDEN_OPENAI_API_KEY: ${{ secrets.WARDEN_OPENAI_API_KEY }}
  WARDEN_ANTHROPIC_API_KEY: ${{ secrets.WARDEN_ANTHROPIC_API_KEY }}

jobs:
  warden:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Analyze
        id: warden-analyze
        uses: getsentry/warden@v0
        with:
          mode: analyze

      - name: Report
        uses: getsentry/warden@v0
        with:
          mode: report
          findings-file: ${{ steps.warden-analyze.outputs.findings-file }}
```

### Action Inputs

| Input | Default | Description |
|-------|---------|-------------|
| `mode` | `run` | Action mode: `analyze`, `report`, or legacy `run`. Split `analyze`/`report` modes are pull request workflow only. |
| `findings-file` | - | Structured findings file to read in `mode: report` |
| `github-token` | `GITHUB_TOKEN` | GitHub token for posting comments |
| `anthropic-api-key` | - | Anthropic API key input. Prefer `WARDEN_ANTHROPIC_API_KEY` env for new workflows. |
| `config-path` | `warden.toml` | Path to config file |
| `fail-on` | - | Minimum severity to fail the check |
| `report-on` | - | Minimum severity to post comments |
| `max-findings` | `50` | Maximum findings to report |
| `request-changes` | `false` | Whether to request changes on PR reviews |
| `fail-check` | `false` | Whether to fail the check run |
| `post-checks` | `true` | Whether to create/update the core `warden` check and per-skill checks. Set `false` to post only PR review comments — do not combine with a required Warden status check. |
| `parallel` | `5` | Maximum concurrent trigger executions |

### Split Analyze and Report

Use `mode: analyze` first to run skills and write a structured findings file
without creating checks or comments. Then run `mode: report` with
`findings-file` to create completed checks and post comments. For GitHub App
runs, create the app token between those steps so reporting uses fresh write
credentials. Pass the intended `config-path`, `base-config-path`,
`base-skill-root`, and action-level reporting inputs to the report step; report
mode reloads config and applies the report step's inputs.

```yaml
- name: Analyze
  id: warden-analyze
  uses: getsentry/warden@v0
  with:
    mode: analyze

- name: Create Warden app token
  id: warden-token
  uses: actions/create-github-app-token@v3
  with:
    app-id: ${{ secrets.WARDEN_APP_ID }}
    private-key: ${{ secrets.WARDEN_PRIVATE_KEY }}

- name: Report
  uses: getsentry/warden@v0
  with:
    mode: report
    findings-file: ${{ steps.warden-analyze.outputs.findings-file }}
    github-token: ${{ steps.warden-token.outputs.token }}
```

## GitHub App (Optional)

Create a GitHub App for branded comments that appear from "Warden" with a custom avatar instead of "github-actions".

```bash
warden setup-app --org your-org
```

Add these organization secrets:

| Secret | Description |
|--------|-------------|
| `WARDEN_APP_ID` | App ID from the setup command output |
| `WARDEN_PRIVATE_KEY` | Private key (full PEM contents) |

Create the app token immediately before the report step:

```yaml
- name: Analyze
  id: warden-analyze
  uses: getsentry/warden@v0
  with:
    mode: analyze

- uses: actions/create-github-app-token@v3
  id: app-token
  with:
    app-id: ${{ secrets.WARDEN_APP_ID }}
    private-key: ${{ secrets.WARDEN_PRIVATE_KEY }}

- name: Report
  uses: getsentry/warden@v0
  with:
    mode: report
    findings-file: ${{ steps.warden-analyze.outputs.findings-file }}
    github-token: ${{ steps.app-token.outputs.token }}
```

## Agent Skill

Warden ships with an [agentskills.io](https://agentskills.io) skill that lets AI coding agents run Warden on your behalf.

### Install

```bash
# skills installer (Claude Code, OpenCode, Codex, Cursor)
npx skills add getsentry/warden

# Claude Code marketplace
claude plugin marketplace add getsentry/warden
claude plugin install warden@warden
```

### What It Does

The `/warden` skill teaches agents how to:

- Run Warden against uncommitted changes before committing
- Interpret findings and fix the code
- Configure skills in `warden.toml`
- Create custom skills

### Usage

In any agent that supports the spec:

```
> Use /warden before committing
```

The agent runs `warden`, reads the output, fixes what it finds, and commits clean code.
