Find a file
kite 80a5794667
Some checks are pending
CI / test (push) Waiting to run
CI / cross-compile (amd64, darwin) (push) Waiting to run
CI / cross-compile (amd64, windows) (push) Waiting to run
CI / cross-compile (arm64, darwin) (push) Waiting to run
CI / cross-compile (arm64, linux) (push) Waiting to run
CI / cross-compile (arm64, windows) (push) Waiting to run
Deploy Pages / build (push) Waiting to run
Deploy Pages / deploy (push) Blocked by required conditions
refactor(cli): migrate to Cobra framework for shell completion support (#625)
* refactor(cli): migrate to Cobra framework for shell completion support

Replace the hand-rolled ocrFlagSet + switch dispatch with spf13/cobra,
enabling native bash/zsh/fish/powershell completion via `ocr completion`.

Key changes:
- Add root.go (rootCmd definition, version flag with -V shorthand)
- Add completion.go (ocr completion [bash|zsh|fish|powershell])
- Add shared_flags.go (reusable flag registration helpers + validation)
- Rewrite all *_cmd.go to use cobra.Command with RunE
- Delete flags.go (ocrFlagSet, expandShortFlags, parseXxxFlags)
- Add compat_test.go (test compatibility wrappers for existing tests)
- Promote github.com/spf13/cobra from indirect to direct dependency

Behavioral improvements over the previous implementation:
- Shell completion for all commands, flags, and enum values
- "Did you mean?" suggestions for misspelled commands
- cobra.NoArgs on review/scan prevents silent positional arg ignoring
- Cleaner error messages on unknown flags (no full flag dump)
- Consistent help output format across all subcommands

Closes #576

* fix(cli): add Args: cobra.NoArgs to viewerCmd

Prevents `ocr viewer localhost:3000` from silently ignoring the
positional argument and starting on the default address.
Consistent with reviewCmd and scanCmd.

* feat(cli): add "Did you mean?" suggestions for misspelled flags

Cobra only suggests corrections for unknown subcommands, not flags.
Add a levenshtein-distance based suggestion that fires when cobra
returns an "unknown flag" error, matching the same UX pattern.

Examples:
  --hel     → Did you mean this? --help
  --audienc → Did you mean this? --audience
  --comit   → Did you mean this? --commit

* fix(deps): promote spf13/pflag to direct dependency

After the Cobra migration, pflag is directly imported but was still
marked as indirect in go.mod, causing CI's go-mod-tidy check to fail.

* refactor(cli): use idiomatic cobra patterns for args validation and flag errors

Replace hand-rolled argument validation in configSetCmd/configUnsetCmd
with cobra.ExactArgs, and move flag typo suggestions from post-hoc error
string parsing into SetFlagErrorFunc where cobra provides the command
context directly.
2026-07-31 16:56:07 +08:00
.claude/commands feat(background-file) Add the background-file CLI option to read a local business context file (#206) 2026-07-08 19:46:30 +08:00
.claude-plugin fix(codex): add native marketplace manifest (#402) 2026-07-20 22:13:50 +08:00
.github ci: upgrade low-risk GitHub Actions dependencies (#468) 2026-07-30 15:54:59 +08:00
bin chore: reduce default update check interval from 30 to 18 minutes 2026-06-23 21:08:55 +08:00
cmd/opencodereview refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
examples Add CodeUp CI integration (#570) 2026-07-29 22:37:29 +08:00
extensions/vscode fix(vscode): force-kill unresponsive reviews (#489) 2026-07-31 12:05:28 +08:00
imgs i18n(pages): add Russian (ru) locale (#596) 2026-07-30 14:40:06 +08:00
internal feat(viewer): add review comments display to session detail page (#627) 2026-07-31 16:27:06 +08:00
npm fix: normalize repository.url with git+ prefix to suppress npm publish warnings 2026-06-23 20:29:45 +08:00
pages docs(configuration): note url accepts base URL or full /responses endpoint (#623) 2026-07-31 13:14:25 +08:00
plugins/open-code-review docs(readme): reorganize coding agent integrations (#512) 2026-07-26 20:30:36 +08:00
scripts i18n(pages): add Russian (ru) locale (#596) 2026-07-30 14:40:06 +08:00
skills feat(delegate): add delegation mode for host-agent driven code review (#383) 2026-07-16 13:10:54 +08:00
.gitignore chore(gitignore): ignore local claude command files 2026-07-31 11:27:35 +08:00
.npmignore feat: add platform-specific npm packages to eliminate postinstall download 2026-06-17 14:17:03 +08:00
action.yml ci: upgrade low-risk GitHub Actions dependencies (#468) 2026-07-30 15:54:59 +08:00
ASSURANCE_CASE.md docs: add security assurance case and use signed tags 2026-06-26 21:30:57 +08:00
CODE_OF_CONDUCT.md docs: add GOVERNANCE.md, CODE_OF_CONDUCT.md and clean up SECURITY.md 2026-06-26 19:38:37 +08:00
CONTRIBUTING.ja-JP.md docs: add Russian translations for README and CONTRIBUTING (#101) 2026-06-12 11:49:04 +08:00
CONTRIBUTING.ko-KR.md docs: add Russian translations for README and CONTRIBUTING (#101) 2026-06-12 11:49:04 +08:00
CONTRIBUTING.md docs: add Russian translations for README and CONTRIBUTING (#101) 2026-06-12 11:49:04 +08:00
CONTRIBUTING.ru-RU.md docs: add Russian translations for README and CONTRIBUTING (#101) 2026-06-12 11:49:04 +08:00
CONTRIBUTING.zh-CN.md docs: add Russian translations for README and CONTRIBUTING (#101) 2026-06-12 11:49:04 +08:00
go.mod refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
go.sum refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
GOVERNANCE.md docs: add GOVERNANCE.md, CODE_OF_CONDUCT.md and clean up SECURITY.md 2026-06-26 19:38:37 +08:00
install.ps1 feat: add install.ps1 for Windows one-line install (#397) 2026-07-17 20:12:40 +08:00
install.sh feat: add install.ps1 for Windows one-line install (#397) 2026-07-17 20:12:40 +08:00
LICENSE docs(license): update copyright holder to project contributors (#560) 2026-07-28 20:31:16 +08:00
Makefile ci: unify gofmt -s across Makefile and CI, reduce cross-compile timeout (#439) 2026-07-22 11:23:39 +08:00
package.json ci: add translation-sync guardrails for READMEs and docs (#455) 2026-07-23 16:07:27 +08:00
README.ja-JP.md docs(README.ja-JP): fix Contributing link to point to Japanese version (#549) 2026-07-28 15:40:30 +08:00
README.ko-KR.md docs(readme): reorganize coding agent integrations (#512) 2026-07-26 20:30:36 +08:00
README.md docs(readme): reorganize coding agent integrations (#512) 2026-07-26 20:30:36 +08:00
README.ru-RU.md i18n(pages): add Russian (ru) locale (#596) 2026-07-30 14:40:06 +08:00
README.zh-CN.md docs(readme): reorganize coding agent integrations (#512) 2026-07-26 20:30:36 +08:00
ROADMAP.md docs(roadmap): mark MCP as shipped and add delegate mode 2026-07-09 13:42:45 +08:00
SECURITY.md feat(ci): add Sigstore attestation for release artifacts 2026-06-26 22:18:03 +08:00

OpenCodeReview logo

OpenCodeReview

alibaba%2Fopen-code-review | Trendshift alibaba%2Fopen-code-review | Trendshift

npm Build status License Ask DeepWiki OpenSSF Best Practices

Windows macOS Linux Claude Code Codex Cursor

English | 简体中文 | 日本語 | 한국어 | Русский


What is Open Code Review?

Open Code Review is an AI-powered code review CLI tool. It originated as Alibaba Group's internal official AI code review assistant — over the past two years, it has served tens of thousands of developers and identified millions of code defects. After thorough validation at massive scale, we incubated it into an open source project for the community. Simply configure a model endpoint to get started.

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.

Visit the official website for more details.

Highlights

Benchmark

Compared to general-purpose agents (Claude Code), Open Code Review achieves significantly higher Precision and F1 with the same underlying model, while consuming only ~1/9 of the tokens and completing reviews faster. Note that its Recall is lower than general-purpose agents — a deliberate trade-off favoring precision over noise.

A real-world code review benchmark built from 50 popular open-source repositories, 200 real Pull Requests, and 10 programming languages — cross-validated by 80+ senior engineers (1,505 annotated ground-truth issues).

Metric What it measures Why it matters
F1 Harmonic mean of precision and recall Best single number for overall review quality
Precision Proportion of reported issues that are real defects Higher = fewer false alarms to triage
Recall Proportion of real defects that are found Higher = fewer issues slip through review
Avg Time Wall-clock time per review Matters for CI pipeline latency
Avg Token Total tokens consumed per review Directly impacts API cost

Benchmark

Why Open Code Review?

The Problem with General-Purpose Agents

If you've used general-purpose agents like Claude Code with Skills for code review, you've likely encountered these pain points:

  • Incomplete coverage — On larger changesets, agents tend to "cut corners," selectively reviewing only some files and missing others.
  • Position drift — Reported issues frequently don't match the actual code location, with line numbers or file references drifting off target.
  • Unstable quality — Natural-language-driven Skills are hard to debug, and review quality fluctuates significantly with minor prompt variations.

The root cause: a purely language-driven architecture lacks hard constraints on the review process.

Core Design: Deterministic Engineering × Agent Hybrid

Open Code Review's core philosophy is to combine deterministic engineering with an agent, each handling what it does best.

Deterministic Engineering — Hard Constraints

For review steps that must not go wrong, engineering logic — not the language model — guarantees correctness:

  • Precise file selection — Determines exactly which files need review and which should be filtered, ensuring no important change is missed.
  • Smart file bundling — Groups related files into a single review unit (e.g., message_en.properties and message_zh.properties are bundled together). Each bundle runs as a sub-agent with isolated context — a divide-and-conquer strategy that stays stable on very large changesets and naturally supports concurrent review.
  • Fine-grained rule matching — Matches review rules to each file's characteristics, keeping the model's attention sharply focused and eliminating information noise at the source. Compared to purely language-driven rule guidance, template-engine-based rule matching is more stable and predictable.
  • External positioning and reflection modules — Independent comment-positioning and comment-reflection modules systematically improve both the location accuracy and content accuracy of AI feedback.

Agent — Dynamic Decision-Making

The agent's strengths are concentrated where they matter most — dynamic decisions and dynamic context retrieval:

  • Scenario-tuned prompts — Prompt templates deeply optimized for code review, improving effectiveness while reducing token consumption.
  • Scenario-tuned toolset — Distilled from deep analysis of tool-call traces in large-scale production data — including call frequency distributions, per-tool repetition rates, and the impact of new tools on the overall call chain — resulting in a purpose-built toolset that is more stable and predictable for code review than a generic agent toolkit.

How to Use

Prerequisites

  • Git >= 2.41 — Open Code Review relies on Git for diff generation, code search, and repository operations.

CLI

Install

npm install -g @alibaba-group/open-code-review

After installation, the ocr command is available globally.

For other installation methods (install script, GitHub Release binary, from source), see Installation.

Quick Start

1. Configure LLM

You must configure an LLM before reviewing code, unless you use Delegation Mode.

ocr config provider          # Select a built-in provider or add a custom one
ocr config model             # Pick a model for the active provider

Provider setup

The interactive UI guides you through provider selection, API key entry, and model configuration, then automatically tests connectivity.

For CLI setup, environment variables, custom providers, and other advanced configuration, see Configuration.

2. Review

cd your-project

# Workspace mode — review all staged, unstaged, and untracked changes
ocr review

# Branch range — compare two refs
ocr review --from main --to feature-branch

# Single commit
ocr review --commit abc123

# Resume an interrupted range or commit review
ocr session list
ocr review --from main --to feature-branch --resume <session-id>

# Full-file scan — review whole files instead of a diff (no git history needed)
ocr scan                          # scan the entire repository
ocr scan --path internal/agent    # scan a directory or specific files

# Delegation mode — let your AI coding agent perform the review itself
# OCR handles file selection and rule resolution; no LLM configuration needed
ocr delegate preview
ocr delegate rule src/main.go src/handler.go

Documentation

Full documentation lives at open-codereview.ai/docs:

  • Quickstart — install and run your first review
  • Installation — all platforms and package managers
  • CLI Reference — every command and flag
  • Review Rules — customize review rules with path filtering and targeting
  • Configuration — config keys and environment variables
  • MCP Server — extend the review agent with external tools
  • Coding Agent Integrations — choose the platform you use
    • Claude Code — install a plugin with review slash commands
    • Codex — install a plugin with callable review skills
    • Cursor — install a plugin with portable review skills
    • OpenCode — install native review tools and slash commands
    • Skill-compatible agents — install the portable agent skill
  • Review Execution Modes — after integration, choose which LLM performs the review
  • CI/CD Integration — GitHub Actions, GitLab CI, GitFlic CI, and Gerrit integration
  • Session Viewer — browse and replay review sessions in browser
  • Telemetry — OpenTelemetry integration for observability
  • FAQ — common questions and troubleshooting

Contributing

This project exists thanks to all the people who contribute. See CONTRIBUTING.md for development setup, coding guidelines, and how to submit pull requests.

License

Apache-2.0 — Copyright 2026 Alibaba