@alibaba-group/open-code-review 1.7.13 → 1.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <a href="https://alibaba.github.io/open-code-review/">
2
+ <a href="https://open-codereview.ai">
3
3
  <img src="imgs/logo-core.svg" alt="OpenCodeReview logo" width="180" />
4
4
  </a>
5
5
  <h1>OpenCodeReview</h1>
@@ -37,7 +37,7 @@ Open Code Review is an AI-powered code review CLI tool. It originated as Alibaba
37
37
 
38
38
  It reads Git diffs, sends changed files to a configurable LLM via an agent with tool-use capabilities, and generates structured review comments with line-level precision. The agent can read full file contents, search the codebase, inspect other changed files for context, and produce deep reviews — not just surface-level diff feedback. Beyond diff review, `ocr scan` reviews entire files for auditing unfamiliar codebases or directories that have no meaningful diff.
39
39
 
40
- Visit the [official website](https://alibaba.github.io/open-code-review/) for more details.
40
+ Visit the [official website](https://open-codereview.ai) for more details.
41
41
 
42
42
  ![Highlights](imgs/highlights-en.png)
43
43
 
@@ -99,116 +99,19 @@ The agent's strengths are concentrated where they matter most — dynamic decisi
99
99
 
100
100
  #### Install
101
101
 
102
- **Via NPM (Recommended)**
103
-
104
102
  ```bash
105
103
  npm install -g @alibaba-group/open-code-review
106
104
  ```
107
105
 
108
106
  After installation, the `ocr` command is available globally.
109
107
 
110
- **Update**
111
-
112
- If you installed via NPM, update manually to the latest version:
113
-
114
- ```bash
115
- npm install -g @alibaba-group/open-code-review@latest
116
- ```
117
-
118
- NPM installations also check for newer versions in the background by default and upgrade automatically. To disable auto-updates, set `OCR_NO_UPDATE=1`.
119
-
120
- If you installed with the install script or a manually downloaded binary, rerun the same install/download command to replace the local binary with the latest release. Use `OCR_VERSION` when you need to pin a specific release tag.
121
-
122
- **From GitHub Release**
123
-
124
- Install the latest binary for your OS/architecture with one command (macOS / Linux):
125
-
126
- ```bash
127
- curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh | sh
128
- ```
129
-
130
- The script picks the right release binary, verifies its SHA-256 checksum, and installs it as `ocr` in `/usr/local/bin`. Override the target with `OCR_INSTALL_DIR` or pin a release with `OCR_VERSION`:
131
-
132
- ```bash
133
- OCR_INSTALL_DIR="$HOME/.local/bin" OCR_VERSION=v1.3.13 \
134
- sh -c "$(curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh)"
135
- ```
136
-
137
- On Windows (PowerShell 5.1+):
138
-
139
- ```powershell
140
- irm https://raw.githubusercontent.com/alibaba/open-code-review/main/install.ps1 | iex
141
- ```
142
-
143
- The script picks the right Windows release binary, verifies its SHA-256 checksum, and installs it as `ocr.exe` in `%LOCALAPPDATA%\Programs\ocr`. Override the target with `OCR_INSTALL_DIR` or pin a release with `OCR_VERSION`:
144
-
145
- ```powershell
146
- $env:OCR_INSTALL_DIR = "$env:USERPROFILE\bin"
147
- $env:OCR_VERSION = "v1.3.13"
148
- irm https://raw.githubusercontent.com/alibaba/open-code-review/main/install.ps1 | iex
149
- ```
150
-
151
- Piping a remote script into a shell executes code from the internet. Prefer downloading and inspecting first:
152
-
153
- ```bash
154
- curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh -o install.sh
155
- less install.sh && sh install.sh
156
- ```
157
-
158
- ```powershell
159
- irm https://raw.githubusercontent.com/alibaba/open-code-review/main/install.ps1 -OutFile install.ps1
160
- notepad install.ps1 # review, then: .\install.ps1
161
- ```
162
-
163
- <details>
164
- <summary>Manual download (all platforms, including Windows)</summary>
165
-
166
- Download the binary for your platform from [GitHub Releases](https://github.com/alibaba/open-code-review/releases):
167
-
168
- ```bash
169
- # macOS (Apple Silicon)
170
- curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-darwin-arm64
171
- chmod +x ocr && sudo mv ocr /usr/local/bin/ocr
172
-
173
- # macOS (Intel)
174
- curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-darwin-amd64
175
- chmod +x ocr && sudo mv ocr /usr/local/bin/ocr
176
-
177
- # Linux (x86_64)
178
- curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-linux-amd64
179
- chmod +x ocr && sudo mv ocr /usr/local/bin/ocr
180
-
181
- # Linux (ARM64)
182
- curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-linux-arm64
183
- chmod +x ocr && sudo mv ocr /usr/local/bin/ocr
184
-
185
- # Windows (x86_64) — move ocr.exe to a directory in your PATH
186
- curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-windows-amd64.exe
187
-
188
- # Windows (ARM64) — move ocr.exe to a directory in your PATH
189
- curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-windows-arm64.exe
190
- ```
191
-
192
- </details>
193
-
194
- **From Source**
195
-
196
- ```bash
197
- git clone https://github.com/alibaba/open-code-review.git
198
- cd open-code-review
199
- make build
200
- sudo cp dist/opencodereview /usr/local/bin/ocr
201
- ```
108
+ For other installation methods (install script, GitHub Release binary, from source), see [Installation](https://open-codereview.ai/docs/installation).
202
109
 
203
110
  #### Quick Start
204
111
 
205
112
  **1. Configure LLM**
206
113
 
207
- **You must configure an LLM before reviewing code.**
208
-
209
- OCR manages LLM configuration through a unified **Provider** system. It ships with many popular built-in providers and also supports adding custom providers to connect to private deployments or other compatible endpoints. Config is stored in `~/.opencodereview/config.json`.
210
-
211
- **Option A: Interactive setup (Recommended)**
114
+ You must configure an LLM before reviewing code, unless you use [Delegation Mode](https://open-codereview.ai/docs/delegate).
212
115
 
213
116
  ```bash
214
117
  ocr config provider # Select a built-in provider or add a custom one
@@ -219,91 +122,9 @@ ocr config model # Pick a model for the active provider
219
122
 
220
123
  The interactive UI guides you through provider selection, API key entry, and model configuration, then automatically tests connectivity.
221
124
 
222
- Run `ocr llm providers` to see all built-in providers. Built-in providers come with preset API URLs and protocols just supply an API key to get started. If the corresponding environment variable is already set (e.g. `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`), the API key is picked up automatically.
223
-
224
- **Custom providers** can also be added through the interactive UI — you'll need to provide a name, API URL, protocol type (`anthropic` or `openai`), and API key.
225
-
226
- **Option B: CLI setup (for CI/CD and non-interactive environments)**
227
-
228
- Use `ocr config set` to write provider configuration directly, suitable for scripts and automation.
229
-
230
- Using a built-in provider:
231
-
232
- ```bash
233
- ocr config set provider anthropic
234
- ocr config set providers.anthropic.api_key your-api-key-here
235
- ocr config set providers.anthropic.model claude-sonnet-4-6
236
- ```
237
-
238
- Using a custom provider (private gateway or other compatible endpoint):
239
-
240
- ```bash
241
- ocr config set provider my-gateway
242
- ocr config set custom_providers.my-gateway.url https://my-llm-gateway.internal/v1
243
- ocr config set custom_providers.my-gateway.protocol openai
244
- ocr config set custom_providers.my-gateway.api_key your-api-key-here
245
- ocr config set custom_providers.my-gateway.model gpt-4o
246
- ```
247
-
248
- > `url` and `protocol` are required for custom providers. Supported protocols: `anthropic`, `openai`, `openai-responses`.
249
-
250
- Optional settings:
251
-
252
- | Key | Description |
253
- |-----|-------------|
254
- | `providers.<name>.auth_header` | Auth header: `x-api-key` or `authorization` (default: `authorization`) |
255
- | `providers.<name>.extra_body` | Custom JSON fields merged into the request body |
256
- | `providers.<name>.extra_headers` | Comma-separated `key=value` pairs of custom HTTP headers added to every request |
257
- | `providers.<name>.models` | Model list for interactive selection |
258
-
259
- **`extra_headers` (optional):** Adds custom HTTP headers to every LLM API request. Useful for proxies, gateways, or enterprise endpoints that require additional headers (e.g. organization IDs, tracing IDs). Format is comma-separated `key=value` pairs. Double-quote values that contain commas:
260
-
261
- ```bash
262
- ocr config set llm.extra_headers "X-Org-ID=org-123,X-Forwarded-For=\"1.2.3.4,5.6.7.8\""
263
- ```
264
-
265
- You can also set extra headers per-provider:
266
-
267
- ```bash
268
- ocr config set providers.anthropic.extra_headers "X-Org-ID=org-123"
269
- ```
270
-
271
- **Environment variables (highest priority)**
272
-
273
- Environment variables override config file settings, useful in CI/CD where writing config files is inconvenient:
274
-
275
- ```bash
276
- export OCR_LLM_URL=https://api.anthropic.com/v1/messages
277
- export OCR_LLM_TOKEN=your-api-key-here
278
- export OCR_LLM_MODEL=claude-opus-4-6
279
- export OCR_USE_ANTHROPIC=true
280
- ```
125
+ For CLI setup, environment variables, custom providers, and other advanced configuration, see [Configuration](https://open-codereview.ai/docs/configuration).
281
126
 
282
- To use the OpenAI Responses API (GPT-5.x / o-series), set `OCR_LLM_PROTOCOL` instead of `OCR_USE_ANTHROPIC`:
283
-
284
- ```bash
285
- export OCR_LLM_URL=https://api.openai.com/v1
286
- export OCR_LLM_TOKEN=your-openai-key
287
- export OCR_LLM_MODEL=gpt-5.4
288
- export OCR_LLM_PROTOCOL=openai-responses
289
- ```
290
-
291
- `OCR_LLM_PROTOCOL` accepts `anthropic`, `openai`, `openai-responses`, and takes priority over `OCR_USE_ANTHROPIC` when both are set.
292
-
293
- Also compatible with Claude Code environment variables (`ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_MODEL`) and parses `~/.zshrc` / `~/.bashrc` for those exports.
294
-
295
- > **Note for CC-Switch Users**: If you are using [CC-Switch](https://github.com/farion1231/cc-switch) with [routing service](https://www.ccswitch.io/en/docs?section=proxy&item=service) enabled, you can point the provider's `url` to the CC-Switch proxy address without additional configuration:
296
- > - For **Claude** provider: set `providers.anthropic.url` to `http://127.0.0.1:15721`
297
- > - For **Codex** provider: set the corresponding provider's `url` to `http://127.0.0.1:15721/v1`
298
- > - `api_key` can be any value; `extra_body` settings still apply
299
-
300
- **2. Test Connectivity**
301
-
302
- ```bash
303
- ocr llm test
304
- ```
305
-
306
- **3. Review**
127
+ **2. Review**
307
128
 
308
129
  ```bash
309
130
  cd your-project
@@ -331,632 +152,24 @@ ocr delegate preview
331
152
  ocr delegate rule src/main.go src/handler.go
332
153
  ```
333
154
 
334
- ### Integrate with Coding Agents
335
-
336
- OCR can be seamlessly integrated into AI coding agents as a slash command, enabling code review directly within your agent workflow.
337
-
338
- #### Option 1: Install as a Skill
339
-
340
- Use `npx` to install the OCR skill into your project:
341
-
342
- ```bash
343
- npx skills add alibaba/open-code-review --skill open-code-review
344
- ```
345
-
346
- This installs the `open-code-review` skill from the [skills registry](skills/open-code-review/SKILL.md), which teaches your coding agent how to invoke `ocr` for code review, classify issues by priority, and optionally apply fixes.
347
-
348
- **Delegation mode** — if you want your coding agent to perform the review itself (using OCR only for file selection and rule resolution, no LLM configuration needed on the OCR side):
349
-
350
- ```bash
351
- npx skills add alibaba/open-code-review --skill open-code-review-delegate
352
- ```
353
-
354
- See [skills/open-code-review-delegate/SKILL.md](skills/open-code-review-delegate/SKILL.md) for details.
355
-
356
- #### Option 2: Install as a Claude Code Plugin
357
-
358
- For [Claude Code](https://docs.anthropic.com/en/docs/claude-code), install the command plugin through the following command in Claude Code:
359
-
360
- ```bash
361
- /plugin marketplace add alibaba/open-code-review
362
- /plugin install open-code-review@open-code-review
363
- ```
364
-
365
- This registers the `/open-code-review:review` slash command, which runs OCR and automatically filters and fixes issues. It also provides `/open-code-review:delegate-review` for delegation mode (the agent reviews using its own capabilities while OCR handles file selection and rules).
366
-
367
- #### Option 3: Install as a Codex Plugin
368
-
369
- For local Codex, install the Open Code Review plugin from this repository:
370
-
371
- ```bash
372
- codex plugin marketplace add alibaba/open-code-review
373
- codex
374
- /plugins
375
- ```
376
-
377
- For a local checkout or fork:
378
-
379
- ```bash
380
- codex plugin marketplace add .
381
- codex
382
- /plugins
383
- ```
384
-
385
- Install and enable `Open Code Review`, then start a new Codex thread and invoke it explicitly:
386
-
387
- ```text
388
- @Open Code Review review my current changes
389
- @Open Code Review review this branch against main
390
- @Open Code Review review and fix high-confidence issues
391
- ```
392
-
393
- This registers a Codex skill that runs the local OCR CLI:
394
-
395
- ```bash
396
- ocr review --audience agent
397
- ```
398
-
399
- This integration does not change OCR's internal LLM backend and does not require configuring an OpenAI Responses API endpoint for Codex. OCR itself still requires the `ocr` CLI to be installed and configured as described in the CLI setup section.
400
-
401
- Korean guide: [`plugins/open-code-review/CODEX.ko-KR.md`](plugins/open-code-review/CODEX.ko-KR.md)
402
-
403
- #### Option 4: Install as a Cursor Plugin
404
-
405
- For [Cursor](https://www.cursor.com/), install the Open Code Review plugin from this repository:
406
-
407
- ```
408
- cursor-plugin marketplace add alibaba/open-code-review
409
- ```
410
-
411
- Or add the marketplace manually. In Cursor, open `/plugins`, search for `Open Code Review`, and install it.
412
-
413
- For a local checkout or fork:
414
-
415
- ```
416
- cursor-plugin marketplace add .
417
- ```
418
-
419
- After installation, invoke it in Cursor:
420
-
421
- ```text
422
- @Open Code Review review my current changes
423
- @Open Code Review review this branch against main
424
- @Open Code Review review and fix high-confidence issues
425
- ```
426
-
427
- This registers a Cursor skill that runs the local OCR CLI:
428
-
429
- ```bash
430
- ocr review --audience agent
431
- ```
432
-
433
- This integration does not change OCR's internal LLM backend. OCR itself still requires the `ocr` CLI to be installed and configured as described in the CLI setup section.
434
-
435
- #### Option 5: Copy the Command File Directly
436
-
437
- For a quick setup without any package manager, simply copy the command file to use the `/open-code-review` slash command in Claude Code.
438
-
439
- **Project-level** (shared with team via git):
440
-
441
- ```bash
442
- mkdir -p .claude/commands
443
- curl -o .claude/commands/open-code-review.md \
444
- https://raw.githubusercontent.com/alibaba/open-code-review/main/plugins/open-code-review/claude-code/commands/review.md
445
- ```
446
-
447
- **User-level** (personal global use across all projects):
448
-
449
- ```bash
450
- mkdir -p ~/.claude/commands
451
- curl -o ~/.claude/commands/open-code-review.md \
452
- https://raw.githubusercontent.com/alibaba/open-code-review/main/plugins/open-code-review/claude-code/commands/review.md
453
- ```
454
-
455
- For delegation mode (no LLM configuration needed on OCR side):
456
-
457
- ```bash
458
- # Project-level
459
- mkdir -p .claude/commands
460
- curl -o .claude/commands/open-code-review-delegate.md \
461
- https://raw.githubusercontent.com/alibaba/open-code-review/main/plugins/open-code-review/claude-code/commands/delegate-review.md
462
-
463
- # User-level
464
- mkdir -p ~/.claude/commands
465
- curl -o ~/.claude/commands/open-code-review-delegate.md \
466
- https://raw.githubusercontent.com/alibaba/open-code-review/main/plugins/open-code-review/claude-code/commands/delegate-review.md
467
- ```
468
-
469
- > **Prerequisite**: All integration methods require the `ocr` CLI to be installed. Standard mode additionally requires an LLM configured — see [Install](#install) and [Configure LLM](#1-configure-llm) above. Delegation mode does **not** require LLM configuration on the OCR side.
470
-
471
- ### CI/CD Integration
472
-
473
- OCR can be integrated into CI/CD pipelines to automate code review on Merge Requests / Pull Requests.
474
-
475
- The core command for CI integration:
476
-
477
- ```bash
478
- ocr review \
479
- --from "origin/main" \
480
- --to "<commit_sha>" \
481
- --format json
482
- ```
483
-
484
- The `--from` flag accepts a branch ref (e.g., `origin/main`) or commit SHA as the base, while `--to` accepts a commit SHA or branch ref as the head. In CI environments, using commit SHA for `--to` is recommended to correctly handle fork PRs/MRs where the source branch doesn't exist on the origin remote.
485
-
486
- The `--format json` flag outputs machine-readable results suitable for parsing in CI scripts.
487
-
488
- Each finding carries two structured fields so CI integrations can sort, group, filter, or gate builds without re-parsing comment text:
489
-
490
- | Field | Allowed values | Notes |
491
- |-------|----------------|-------|
492
- | `category` | `bug`, `security`, `performance`, `maintainability`, `test`, `style`, `documentation`, `other` | The category the issue belongs to. |
493
- | `severity` | `critical`, `high`, `medium`, `low` | The importance of the issue. |
494
-
495
- In JSON output the two fields appear as siblings alongside `content`, `start_line`, etc. In the terminal, they render as an inline `[category · severity]` badge before the comment, colored by severity.
496
-
497
- See the [`examples/`](./examples/) directory for integration examples:
498
-
499
- - [`github_actions/`](./examples/github_actions/) — GitHub Actions integration example
500
- - [`gitlab_ci/`](./examples/gitlab_ci/) — GitLab CI integration example
501
- - [`gitflic_ci/`](./examples/gitflic_ci/) — GitFlic CI integration example
502
-
503
- #### GitHub Action
504
-
505
- For GitHub, this repository also ships a ready-to-use composite Action at the repo root ([`action.yml`](./action.yml)). Instead of scripting `ocr review` yourself, reference it directly and it handles the full pipeline — checkout, OCR install, running the review, posting inline and summary comments, uploading artifacts, and retry/idempotency:
506
-
507
- ```yaml
508
- - uses: alibaba/open-code-review@main
509
- with:
510
- llm_url: ${{ secrets.OCR_LLM_URL }}
511
- llm_auth_token: ${{ secrets.OCR_LLM_AUTH_TOKEN }}
512
- llm_model: ${{ vars.OCR_LLM_MODEL }}
513
- llm_use_anthropic: ${{ vars.OCR_LLM_USE_ANTHROPIC }}
514
- ```
515
-
516
- Pin to a version tag or commit SHA for reproducibility. See the [`examples/github_actions/`](./examples/github_actions/) directory for a complete workflow demo and the full list of inputs, outputs, and comment-posting modes (sticky summary, incremental non-destructive posting).
517
-
518
- ## Commands
519
-
520
- | Command | Alias | Description |
521
- |---------|-------|-------------|
522
- | `ocr review` | `ocr r` | Start a diff-based code review |
523
- | `ocr scan` | `ocr s` | Review whole files (no diff required) |
524
- | `ocr delegate preview` | `ocr d preview` | Preview reviewable files with mode/ref metadata (no LLM required) |
525
- | `ocr delegate rule <path...>` | `ocr d rule` | Output resolved review rules grouped by content (no LLM required) |
526
- | `ocr rules check <file>` | — | Preview which review rule applies to a file path |
527
- | `ocr config provider` | — | Interactive provider setup (built-in, custom, or manual) |
528
- | `ocr config model` | — | Interactive model selection for the active provider |
529
- | `ocr config set <key> <value>` | — | Set configuration values |
530
- | `ocr config unset custom_providers.<name>` | — | Delete a custom provider |
531
- | `ocr llm test` | — | Test LLM connectivity |
532
- | `ocr llm providers` | — | List built-in LLM providers |
533
- | `ocr session list` | `ocr sessions list`, `ocr session ls` | List saved review sessions |
534
- | `ocr session show <id>` | `ocr sessions show <id>` | Inspect one session and its per-file checkpoints |
535
- | `ocr viewer` | `ocr v` | Launch WebUI session viewer on `localhost:5483` |
536
- | `ocr version` | — | Show version info |
537
-
538
- ### `ocr review` Flags
539
-
540
- | Flag | Shorthand | Default | Description |
541
- |------|-----------|---------|-------------|
542
- | `--repo` | — | current dir | Git repository root |
543
- | `--from` | — | — | Source ref (e.g., `main`) |
544
- | `--to` | — | — | Target ref (e.g., `feature-branch`) |
545
- | `--commit` | `-c` | — | Single commit to review |
546
- | `--exclude` | — | — | Comma-separated gitignore-style patterns to skip; merged with rule.json excludes |
547
- | `--preview` | `-p` | `false` | Preview which files will be reviewed without running the LLM |
548
- | `--resume` | — | — | Resume from a previous compatible range or commit review session |
549
- | `--format` | `-f` | `text` | Output format: `text` or `json` |
550
- | `--concurrency` | — | `8` | Max concurrent file reviews |
551
- | `--timeout` | — | `10` | Concurrent task timeout in minutes |
552
- | `--audience` | — | `human` | `human` (show progress) or `agent` (summary only) |
553
- | `--background` | `-b` | — | Optional requirement/business context for the review; auto-filled from commit message when using `--commit` |
554
- | `--background-file` | `-B` | — | Optional requirement/business context from a Markdown file; Combined with `--background` the inline value is given first |
555
- | `--model` | — | — | Select or override the LLM model for this review |
556
- | `--rule` | — | — | Path to custom JSON review rules |
557
- | `--max-tools` | — | built-in | Max tool call rounds per file; only takes effect when greater than template default |
558
- | `--max-git-procs` | — | `16` | Max concurrent git subprocesses |
559
- | `--tools` | — | built-in | Path to custom JSON tools config |
560
-
561
- #### Resumable Reviews and Sessions
562
-
563
- Every `ocr review` run persists a local session log under
564
- `~/.opencodereview/sessions/`. Successful text output stays focused on review
565
- results and does not print the session ID; use `ocr session list/show` to find
566
- saved sessions, or `--format json` to include `session_id` in machine-readable
567
- output. If a range or commit review is interrupted, list the saved sessions and
568
- resume from the one that matches the same review target:
569
-
570
- ```bash
571
- ocr session list
572
- ocr session show <session-id>
573
- ocr review --from main --to feature-branch --resume <session-id>
574
- ocr review --commit abc123 --resume <session-id>
575
- ```
576
-
577
- Resume is intentionally strict: it only supports branch-range and single-commit
578
- reviews, not workspace reviews, and the current `--from/--to` or `--commit`
579
- must match the saved session. `--preview` cannot be combined with `--resume`.
580
-
581
- When `--format json` is used, resumed runs include:
582
-
583
- - `session_id` — the current run's session ID
584
- - `resume.resumed_from` — the source session ID
585
- - `resume.reused_files` — files reused from saved checkpoints
586
- - `resume.rerun_files` — files reviewed again in the current run
587
-
588
- ### `ocr session` Flags
589
-
590
- | Command | Flag | Default | Description |
591
- |---------|------|---------|-------------|
592
- | `ocr session list` | `--repo` | current dir | Repository whose sessions should be listed |
593
- | `ocr session list` | `--json` | `false` | Emit session summaries as JSON |
594
- | `ocr session list` | `--limit` | `20` | Cap listed sessions; use `0` for unlimited |
595
- | `ocr session show <id>` | `--repo` | current dir | Repository whose session should be inspected |
596
- | `ocr session show <id>` | `--json` | `false` | Emit session metadata and per-file items as JSON |
597
-
598
- ### `ocr scan` Flags
599
-
600
- `ocr scan` reviews entire files rather than a diff — useful for auditing an unfamiliar
601
- codebase, a pre-migration sweep, or any directory with no meaningful diff. It works in
602
- non-git directories too (it falls back to a filesystem walk that honors `.gitignore`).
603
-
604
- | Flag | Shorthand | Default | Description |
605
- |------|-----------|---------|-------------|
606
- | `--path` | — | whole repo | Comma-separated dirs/files to scan |
607
- | `--exclude` | — | — | Comma-separated gitignore-style patterns to skip; merged with rule.json excludes |
608
- | `--preview` | `-p` | `false` | List which files would be scanned without running the LLM |
609
- | `--max-tokens-budget` | — | `0` (unlimited) | Cap total token usage; dispatch stops once exceeded |
610
- | `--no-plan` | — | `false` | Skip the per-file planning pre-pass |
611
- | `--no-dedup` | — | `false` | Skip per-batch de-duplication of similar comments |
612
- | `--no-summary` | — | `false` | Skip the project-level summary |
613
- | `--batch` | — | `by-language` | Batching strategy: `none`, `by-language`, or `by-directory` |
614
- | `--format` | `-f` | `text` | Output format: `text` or `json` (JSON includes a `project_summary` field) |
615
- | `--concurrency` | — | `8` | Max concurrent file scans |
616
- | `--rule` | — | — | Path to custom JSON review rules |
617
- | `--repo` | — | current dir | Repository or directory root to scan |
618
-
619
- Before each run, `ocr scan` prints a rough token-cost estimate. Use `--preview` to see the
620
- file list first, and `--max-tokens-budget` to cap spend on large repositories.
621
-
622
- ### `ocr delegate` Flags
623
-
624
- `ocr delegate` is the delegation mode for AI coding agents. It provides deterministic
625
- file selection and rule resolution without calling any LLM — the host agent performs
626
- the actual review using its own capabilities.
627
-
628
- | Sub-command | Description |
629
- |-------------|-------------|
630
- | `ocr delegate preview` | Output reviewable file list with mode/ref metadata |
631
- | `ocr delegate rule <path...>` | Output resolved review rules grouped by content |
632
-
633
- Both sub-commands share these flags:
634
-
635
- | Flag | Shorthand | Default | Description |
636
- |------|-----------|---------|-------------|
637
- | `--repo` | — | current dir | Git repository root |
638
- | `--from` | — | — | Source ref (e.g., `main`) |
639
- | `--to` | — | — | Target ref (e.g., `feature-branch`) |
640
- | `--commit` | `-c` | — | Single commit to review |
641
- | `--exclude` | — | — | Comma-separated gitignore-style patterns to skip |
642
- | `--rule` | — | — | Path to custom JSON review rules |
643
- | `--background` | `-b` | — | Optional requirement/business context |
644
- | `--background-file` | `-B` | — | Business context from a Markdown file |
645
- | `--max-git-procs` | — | `16` | Max concurrent git subprocesses |
646
-
647
- ## Examples
648
-
649
- ```bash
650
- # Interactive provider and model setup
651
- ocr config provider
652
- ocr config model
653
- ocr llm providers
654
-
655
- # Delete a custom provider
656
- ocr config unset custom_providers.my-gateway
657
-
658
- # Preview which files will be reviewed (no LLM calls)
659
- ocr review --preview
660
- ocr review -c abc123 -p
661
-
662
- # Review workspace changes with default settings
663
- ocr review
664
-
665
- # Review branch diff with higher concurrency
666
- ocr review --from main --to my-feature --concurrency 4
667
-
668
- # Review a specific commit with verbose JSON output
669
- ocr review --commit abc123 --format json --audience agent
670
-
671
- # Resume an interrupted range or commit review
672
- ocr session list
673
- ocr session show <session-id>
674
- ocr review --from main --to my-feature --resume <session-id>
675
- ocr review --commit abc123 --resume <session-id>
676
-
677
- # Select or override model for this review
678
- ocr review --model claude-opus-4-6
679
- ocr review --commit abc123 --model claude-sonnet-4-6
680
-
681
- # Provide requirement context for more targeted review
682
- ocr review --background "Adding rate limiting to the login API"
683
-
684
- # Provide requirement context from a Markdown file
685
- ocr review --background-file ./docs/my_business_context.md
686
-
687
- # Combine inline context with a local context file (both are used)
688
- ocr review --background "Focus on auth" --background-file ./docs/my_business_context.md
689
-
690
- # Use custom review rules
691
- ocr review --rule /path/to/my-rules.json
692
-
693
- # Preview which rule applies to a file
694
- ocr rules check src/main/java/com/example/Foo.java
695
- ocr rules check --rule custom.json src/main/resources/mapper/UserMapper.xml
696
-
697
- # Full-file scan: preview the file list first (no LLM calls)
698
- ocr scan --preview
699
-
700
- # Scan the whole repo, cap spend at ~500k tokens
701
- ocr scan --max-tokens-budget 500000
702
-
703
- # Scan a subdirectory, skipping generated/test files
704
- ocr scan --path internal --exclude '**/*_test.go,**/generated/**'
705
-
706
- # Scan a non-git directory with JSON output (includes project_summary)
707
- ocr scan --repo /path/to/plain/dir --format json
708
-
709
- # Fastest scan: skip planning, dedup, and the project summary
710
- ocr scan --no-plan --no-dedup --no-summary
711
-
712
- # Delegation mode — let your AI agent drive the review (no LLM config needed)
713
- ocr delegate preview
714
- ocr delegate preview --from main --to feature-branch
715
- ocr delegate preview --commit abc123
716
- ocr delegate rule internal/handler.go internal/service.go cmd/main.go
717
-
718
- # View review session history in browser
719
- ocr viewer
720
- ocr viewer --addr :3000
721
- ```
722
-
723
- ### Viewer security
724
-
725
- The viewer serves session JSONL contents (LLM request messages and responses) over HTTP. It enforces a Host-header allowlist on every request: loopback names (`localhost`, `127.0.0.0/8`, `::1`) and the concrete bind host are always allowed. Wildcard binds (`--addr :3000`, `--addr 0.0.0.0:3000`) and other non-loopback Hostnames must be added via the `OCR_VIEWER_ALLOWED_HOSTS` environment variable (comma-separated):
726
-
727
- ```bash
728
- OCR_VIEWER_ALLOWED_HOSTS=review.internal,ocr.lan ocr viewer --addr :3000
729
- ```
730
-
731
- This blocks DNS-rebinding attacks against the local viewer.
732
-
733
- ## Review Rules
734
-
735
- OCR resolves review rules using a four-layer priority chain. Each layer uses first-match-wins: if a file path matches a pattern, that rule is used; otherwise it falls through to the next layer.
736
-
737
- | Priority | Source | Path | Description |
738
- |----------|--------|------|-------------|
739
- | 1 (highest) | `--rule` flag | User-specified path | CLI explicit override |
740
- | 2 | Project config | `<repoDir>/.opencodereview/rule.json` | Per-project rules, can be committed to git |
741
- | 3 | Global config | `~/.opencodereview/rule.json` | User-wide personal preferences |
742
- | 4 (lowest) | System default | Embedded `system_rules.json` | Built-in rules covering common languages and file types |
743
-
744
- ### Rule File Format
745
-
746
- Layers 1–3 share the same JSON format:
747
-
748
- ```json
749
- {
750
- "rules": [
751
- {
752
- "path": "force-api/**/*.java",
753
- "rule": "All new methods must validate required parameters for null values",
754
- "merge_system_rule": true
755
- },
756
- {
757
- "path": "**/*mapper*.xml",
758
- "rule": "Check SQL for injection risks, parameter errors, and missing closing tags"
759
- }
760
- ]
761
- }
762
- ```
763
-
764
- - `path` supports `**` recursive matching and `{java,kt}` brace expansion.
765
- - `merge_system_rule` is optional. When `true`, the matched built-in system rule is merged with this user rule; otherwise the user rule replaces the system rule.
766
- - Within each layer, rules are evaluated in declaration order — the first match wins.
767
- - If a rule file does not exist, it is silently skipped.
768
-
769
- **The `rule` field supports both inline content and file paths.** The system auto-detects which one you mean:
770
-
771
- 1. If the value contains newlines → **inline content** (multi-line rules are never file paths).
772
- 2. If the value is a single line, contains no spaces, and ends with `.md` / `.txt` / `.markdown` → **file path**.
773
- - Absolute paths (starting with `/`) are used directly.
774
- - Relative paths are resolved against the project root. Path traversal (e.g. `../../etc/passwd.md`) is blocked. If not found, a `[WARN]` is emitted and the rule is cleared (no fallback to inline).
775
- - The file must pass validation: whitelisted extension, ≤ 512 KB, and resolved symlink target must also be a whitelisted extension. If validation fails, the rule is cleared.
776
- 3. Otherwise → **inline content**.
777
-
778
- ```json
779
- {
780
- "rules": [
781
- {
782
- "path": "**/*mapper*.xml",
783
- "rule": "docs/sql-rules.md"
784
- },
785
- {
786
- "path": "**/*.java",
787
- "rule": "Always check for null safety and resource leaks"
788
- },
789
- {
790
- "path": "**/*.go",
791
- "rule": "shared/go-concurrency.md"
792
- },
793
- {
794
- "path": "**/*.py",
795
- "rule": "/Users/me/team-rules/python.md"
796
- }
797
- ]
798
- }
799
- ```
800
-
801
- - `docs/sql-rules.md` — relative path, resolved from `<project>/docs/sql-rules.md`.
802
- - `Always check for null safety…` — inline string, used directly.
803
- - `shared/go-concurrency.md` — relative path, same resolution.
804
- - `/Users/me/team-rules/python.md` — absolute path, used directly.
805
-
806
- > Absolute paths can access files outside the project directory — this is intentional. `rule.json` is authored by project maintainers, i.e. trusted input. Teams can store shared rules at a common path (e.g. `/opt/company-rules/`) instead of copying them into every project.
807
-
808
- ### Path Filtering
809
-
810
- Rule files also support `include` and `exclude` fields to control which files enter the review scope:
811
-
812
- ```json
813
- {
814
- "rules": [
815
- {"path": "**/*.java", "rule": "Check for null safety"}
816
- ],
817
- "include": ["src/main/**/*.java", "lib/**/*.kt"],
818
- "exclude": ["**/generated/**", "vendor/**"]
819
- }
820
- ```
821
-
822
- **Filter decision priority (highest to lowest):**
823
-
824
- | Step | Condition | Result |
825
- |------|-----------|--------|
826
- | 1 | File is binary | Excluded |
827
- | 2 | Path matches user `exclude` pattern | Excluded |
828
- | 3 | File extension not in supported list | Excluded |
829
- | 4 | `include` is configured and path matches | **Reviewed** (skips step 5) |
830
- | 5 | Path matches built-in default exclude pattern (test files, etc.) | Excluded |
831
- | 6 | None of the above | Reviewed |
832
-
833
- **How it works:**
834
-
835
- - `include` and `exclude` follow the same priority chain as review rules (`--rule` > project config > global config). The **highest-priority layer that has include/exclude configured** takes effect as a whole — patterns are not merged across layers.
836
- - `exclude` always wins over `include` — a file matching both is excluded.
837
- - `include` acts as a **bypass for built-in default exclude patterns** (e.g., test files), not as an exclusive allowlist — files not matching any `include` pattern still proceed through the default filter checks normally.
838
- - Pattern syntax: supports `**` recursive matching, `*` single-segment matching, and `{a,b}` brace expansion. Matching is case-insensitive.
839
-
840
- **Built-in default exclude patterns** (filters test files, etc. — can be overridden with `include`):
841
-
842
- ```
843
- **/*_test.go, **/*Test.java, **/*Tests.java, **/*_test.rs,
844
- **/*.test.{js,jsx,ts,tsx}, **/*.spec.{js,jsx,ts,tsx}, **/__tests__/**,
845
- **/src/test/java/**/*.java, **/src/test/**/*.kt,
846
- **/test/**/*_test.py, **/tests/**/*_test.py, **/*_test.py,
847
- **/*_spec.rb, **/spec/**/*_spec.rb, **/oh_modules/**
848
- ```
849
-
850
- ## Configuration Reference
851
-
852
- Config file: `~/.opencodereview/config.json`
853
-
854
- | Key | Type | Example |
855
- |-----|------|---------|
856
- | `provider` | string | `anthropic` \| `openai` \| `dashscope` \| `deepseek` \| `z-ai` |
857
- | `providers.<name>.api_key` | string | Provider-specific API key |
858
- | `providers.<name>.url` | string | Provider base URL override |
859
- | `providers.<name>.protocol` | string | `anthropic` \| `openai` \| `openai-responses` |
860
- | `providers.<name>.model` | string | Model name for the provider |
861
- | `providers.<name>.models` | array | Optional provider model list for interactive selection |
862
- | `providers.<name>.auth_header` | string | `x-api-key` \| `authorization` |
863
- | `providers.<name>.extra_body` | object | JSON object merged into every request body |
864
- | `providers.<name>.timeout_sec` | integer | Per-request HTTP timeout in seconds (default: `300`) |
865
- | `providers.<name>.extra_headers` | string | Comma-separated `key=value` HTTP headers |
866
- | `custom_providers.<name>.*` | — | Same fields as `providers.<name>.*`, including optional `models` |
867
- | `llm.url` | string | `https://api.openai.com/v1/chat/completions` |
868
- | `llm.auth_token` | string | `sk-xxxxxxx` |
869
- | `llm.auth_header` | string | Anthropic only: `x-api-key` \| `authorization` |
870
- | `llm.extra_body` | object | JSON object merged into every request body |
871
- | `llm.timeout_sec` | integer | Per-request HTTP timeout in seconds (default: `300`) |
872
- | `llm.extra_headers` | string | Comma-separated `key=value` HTTP headers |
873
- | `llm.model` | string | `claude-opus-4-6` |
874
- | `llm.protocol` | string | `anthropic` \| `openai` \| `openai-responses`; takes priority over `llm.use_anthropic` |
875
- | `llm.use_anthropic` | boolean | `true` \| `false` (legacy; prefer `llm.protocol`) |
876
- | `mcp_servers.<name>.command` | string | Command to start the MCP server |
877
- | `mcp_servers.<name>.args` | array | Command-line arguments for the MCP server |
878
- | `mcp_servers.<name>.env` | array | Environment variables in `KEY=VALUE` format |
879
- | `mcp_servers.<name>.tools` | array | Allowed tool names (empty = all tools) |
880
- | `mcp_servers.<name>.setup` | string | Setup command to run before starting the server |
881
- | `language` | string | Any language name, e.g. `English`, `Chinese` (default: `English`) |
882
- | `telemetry.enabled` | boolean | `true` \| `false` |
883
- | `telemetry.exporter` | string | `console` \| `otlp` |
884
- | `telemetry.otlp_endpoint` | string | OTLP collector address |
885
- | `telemetry.content_logging` | boolean | Include prompts in telemetry |
886
-
887
- Environment variables take precedence over the config file.
888
-
889
- ### MCP Server
890
-
891
- Open Code Review supports [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers, allowing the review agent to use external tools during code review via the stdio transport.
892
-
893
- Configure MCP servers via the CLI:
894
-
895
- ```bash
896
- # Add an MCP server
897
- ocr config set mcp_servers.<name>.command <command>
898
- ocr config set mcp_servers.<name>.args '["arg1","arg2"]'
899
- ocr config set mcp_servers.<name>.env '["KEY=VALUE"]'
900
- ocr config set mcp_servers.<name>.tools '["tool_name"]'
901
- ocr config set mcp_servers.<name>.setup '<setup command>'
902
-
903
- # Delete an MCP server
904
- ocr config unset mcp_servers.<name>
905
- ```
906
-
907
- | Field | Required | Description |
908
- |-------|----------|-------------|
909
- | `command` | Yes | The executable command to start the MCP server |
910
- | `args` | No | Command-line arguments passed to the server |
911
- | `env` | No | Environment variables in `KEY=VALUE` format |
912
- | `tools` | No | Allowed tool names; if empty, all tools from the server are available |
913
- | `setup` | No | A shell command to run before starting the server (e.g. build an index) |
914
-
915
- > **Note:** If an MCP tool's name conflicts with a built-in tool, it will be skipped with a warning. The `setup` command has a 5-minute timeout.
916
-
917
- **Example: Add [CodeGraph](https://github.com/nicholasgasior/codegraph) for code structure analysis**
918
-
919
- ```bash
920
- ocr config set mcp_servers.codegraph.command codegraph
921
- ocr config set mcp_servers.codegraph.args '["serve","--mcp"]'
922
- ocr config set mcp_servers.codegraph.tools '["codegraph_explore"]'
923
- ocr config set mcp_servers.codegraph.setup 'codegraph init && codegraph index'
924
- ```
925
-
926
- ### Environment Variables
927
-
928
- | Variable | Purpose |
929
- |----------|---------|
930
- | `OCR_LLM_URL` | LLM API endpoint URL |
931
- | `OCR_LLM_TOKEN` | API key / auth token |
932
- | `OCR_LLM_AUTH_HEADER` | Anthropic auth header (`x-api-key` or `authorization`) |
933
- | `OCR_LLM_EXTRA_HEADERS` | Comma-separated `key=value` HTTP headers |
934
- | `OCR_LLM_MODEL` | Model name |
935
- | `OCR_LLM_PROTOCOL` | Protocol: `anthropic` \| `openai` \| `openai-responses`; takes priority over `OCR_USE_ANTHROPIC` |
936
- | `OCR_LLM_TIMEOUT` | Per-request HTTP timeout in seconds (overrides config file `timeout_sec`) |
937
- | `OCR_USE_ANTHROPIC` | `true` = Anthropic, `false` = OpenAI Chat Completions (legacy; prefer `OCR_LLM_PROTOCOL`) |
938
-
939
- ## Telemetry
940
-
941
- OpenTelemetry integration for observability (spans, metrics). Disabled by default.
942
-
943
- ```bash
944
- ocr config set telemetry.enabled true
945
- ocr config set telemetry.exporter otlp
946
- ocr config set telemetry.otlp_endpoint localhost:4317
947
- ```
948
-
949
- Set `telemetry.content_logging` to include LLM prompts and responses in exported data.
950
-
951
- **Protocol selection:** Set the environment variable `OTEL_EXPORTER_OTLP_PROTOCOL` to choose the export protocol:
952
-
953
- | Value | Transport | Notes |
954
- |---|---|---|
955
- | `grpc` (default) | gRPC | Default port 4317 |
956
- | `http/protobuf` | HTTP | Default port 4318 |
957
-
958
- **Endpoint format:** `telemetry.otlp_endpoint` expects a base URL in `host:port` or `http://host:port` format, without a path component. The SDK appends the signal path (e.g. `/v1/traces`) automatically per the [OTLP specification](https://opentelemetry.io/docs/specs/otlp/#otlphttp-request).
959
-
155
+ ## Documentation
156
+
157
+ Full documentation lives at **[open-codereview.ai/docs](https://open-codereview.ai/docs)**:
158
+
159
+ - [Quickstart](https://open-codereview.ai/docs/quickstart) install and run your first review
160
+ - [Installation](https://open-codereview.ai/docs/installation) — all platforms and package managers
161
+ - [CLI Reference](https://open-codereview.ai/docs/cli-reference) every command and flag
162
+ - [Review Rules](https://open-codereview.ai/docs/review-rules) — customize review rules with path filtering and targeting
163
+ - [Configuration](https://open-codereview.ai/docs/configuration) — config keys and environment variables
164
+ - [MCP Server](https://open-codereview.ai/docs/mcp) — extend the review agent with external tools
165
+ - Coding Agent Integrations — integrate OCR into Claude Code, Codex, Cursor, etc.
166
+ - [Skill](https://open-codereview.ai/docs/agent-skill) — install as a reusable agent skill
167
+ - [Plugin](https://open-codereview.ai/docs/claude-code) install as a Claude Code / Codex / Cursor plugin
168
+ - [Delegation Mode](https://open-codereview.ai/docs/delegate) — let your agent review using its own LLM
169
+ - [CI/CD Integration](https://open-codereview.ai/docs/cicd) GitHub Actions, GitLab CI, GitFlic CI, and Gerrit integration
170
+ - [Session Viewer](https://open-codereview.ai/docs/viewer) — browse and replay review sessions in browser
171
+ - [Telemetry](https://open-codereview.ai/docs/telemetry) — OpenTelemetry integration for observability
172
+ - [FAQ](https://open-codereview.ai/docs/faq) common questions and troubleshooting
960
173
 
961
174
  ## Contributing
962
175