@Smartpigai: 前身是阿里集团内部官方 AI 代码审查助手,过去两年服务了数万开发者,识别了数百万个代码缺陷。 现在它开源了:Open Code Review。 它不是让 AI “随便看一眼 diff”,而是把 AI Code Review 工程化。 它…
摘要
阿里巴巴开源了其内部AI代码审查助手Open Code Review,一个工程化的代码审查CLI工具,能读取Git diff并生成带行级定位的结构化审查意见。
查看缓存全文
缓存时间: 2026/06/14 07:38
前身是阿里集团内部官方 AI 代码审查助手,过去两年服务了数万开发者,识别了数百万个代码缺陷。
现在它开源了:Open Code Review。
它不是让 AI “随便看一眼 diff”,而是把 AI Code Review 工程化。
它能读取 Git diff,结合上下文分析代码变更,生成带行级定位的结构化审查意见。
对开发者:提 PR 前先自查,少返工。
对 Reviewer:少看低级问题,把精力留给架构和业务逻辑。
对团队:可以沉淀规则,接入 GitHub Actions / GitLab CI。
一句话: 它不是取代人类 Review,而是让团队代码审查更省力、更稳定、更有价值。
GitHub: https://github.com/alibaba/open-code-review…
alibaba/open-code-review
Source: https://github.com/alibaba/open-code-review
The open source AI code review agent.
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.

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.propertiesandmessage_zh.propertiesare 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
CLI
Install
Via NPM (Recommended)
npm install -g @alibaba-group/open-code-review
After installation, the ocr command is available globally.
From GitHub Release
Download the latest binary from GitHub Releases:
# macOS (Apple Silicon)
curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-darwin-arm64
chmod +x ocr && sudo mv ocr /usr/local/bin/ocr
# macOS (Intel)
curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-darwin-amd64
chmod +x ocr && sudo mv ocr /usr/local/bin/ocr
# Linux (x86_64)
curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-linux-amd64
chmod +x ocr && sudo mv ocr /usr/local/bin/ocr
# Linux (ARM64)
curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-linux-arm64
chmod +x ocr && sudo mv ocr /usr/local/bin/ocr
# Windows (x86_64) — move ocr.exe to a directory in your PATH
curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-windows-amd64.exe
# Windows (ARM64) — move ocr.exe to a directory in your PATH
curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-windows-arm64.exe
From Source
git clone https://github.com/alibaba/open-code-review.git
cd open-code-review
make build
sudo cp dist/opencodereview /usr/local/bin/ocr
Quick Start
1. Configure LLM
You must configure an LLM before reviewing code.
# Option A: Interactive config
ocr config set llm.url https://api.anthropic.com/v1/messages
ocr config set llm.auth_token your-api-key-here
ocr config set llm.model claude-opus-4-6
ocr config set llm.use_anthropic true
# Option B: Environment variables (highest priority)
export OCR_LLM_URL=https://api.anthropic.com/v1/messages
export OCR_LLM_TOKEN=your-api-key-here
export OCR_LLM_MODEL=claude-opus-4-6
export OCR_USE_ANTHROPIC=true
Config is stored in ~/.opencodereview/config.json.
auth_header (optional): Controls which HTTP header carries the API key when using Anthropic. Defaults to authorization (Bearer token) if omitted. If you use a standard sk-ant-* API key, you must set it to x-api-key:
ocr config set llm.auth_header x-api-key
# or
export OCR_LLM_AUTH_HEADER=x-api-key
Supported values: x-api-key, authorization (alias: bearer). Other values are rejected with an error.
It is also compatible with Claude Code environment variables (ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_MODEL) and parses ~/.zshrc / ~/.bashrc for those exports.
Note for CC-Switch Users: If you are using CC-Switch with routing service enabled, you can point
llm.urlto the CC-Switch proxy address without additional configuration:
- For Claude provider: set
llm.urltohttp://127.0.0.1:15721- For Codex provider: set
llm.urltohttp://127.0.0.1:15721/v1- Set
llm.modelaccording to your provider settingsllm.auth_tokencan be any valueextra_bodysettings still apply
2. Test Connectivity
ocr llm test
3. 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
Integrate with Coding Agents
OCR can be seamlessly integrated into AI coding agents as a slash command, enabling code review directly within your agent workflow.
Option 1: Install as a Skill
Use npx to install the OCR skill into your project:
npx skills add alibaba/open-code-review --skill open-code-review
This installs the open-code-review skill from the skills registry, which teaches your coding agent how to invoke ocr for code review, classify issues by priority, and optionally apply fixes.
Option 2: Install as a Claude Code Plugin
For Claude Code, install the command plugin through the following command in Claude Code:
/plugin marketplace add alibaba/open-code-review
/plugin install open-code-review@open-code-review
This registers the /open-code-review:review slash command, which runs OCR and automatically filters and fixes issues.
Option 3: Install as a Codex Plugin
For local Codex, install the Open Code Review plugin from this repository:
codex plugin marketplace add alibaba/open-code-review
codex
/plugins
For a local checkout or fork:
codex plugin marketplace add .
codex
/plugins
Install and enable Open Code Review, then start a new Codex thread and invoke it explicitly:
@Open Code Review review my current changes
@Open Code Review review this branch against main
@Open Code Review review and fix high-confidence issues
This registers a Codex skill that runs the local OCR CLI:
ocr review --audience agent
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.
Korean guide: plugins/open-code-review/CODEX.ko-KR.md
Option 4: Copy the Command File Directly
For a quick setup without any package manager, simply copy the command file to use the /open-code-review slash command in Claude Code.
Project-level (shared with team via git):
mkdir -p .claude/commands
curl -o .claude/commands/open-code-review.md \
https://raw.githubusercontent.com/alibaba/open-code-review/main/plugins/open-code-review/commands/review.md
User-level (personal global use across all projects):
mkdir -p ~/.claude/commands
curl -o ~/.claude/commands/open-code-review.md \
https://raw.githubusercontent.com/alibaba/open-code-review/main/plugins/open-code-review/commands/review.md
Prerequisite: All integration methods require the
ocrCLI to be installed and an LLM configured. See Install and Configure LLM above.
CI/CD Integration
OCR can be integrated into CI/CD pipelines to automate code review on Merge Requests / Pull Requests.
The core command for CI integration:
ocr review \
--from "origin/main" \
--to "<commit_sha>" \
--format json
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.
The --format json flag outputs machine-readable results suitable for parsing in CI scripts.
See the examples/ directory for integration examples:
github_actions/— GitHub Actions integration examplegitlab_ci/— GitLab CI integration example
Commands
| Command | Alias | Description |
|---|---|---|
ocr review | ocr r | Start a code review |
ocr rules check <file> | — | Preview which review rule applies to a file path |
ocr config set <key> <value> | — | Set configuration values |
ocr llm test | — | Test LLM connectivity |
ocr viewer | ocr v | Launch WebUI session viewer on localhost:5483 |
ocr version | — | Show version info |
ocr review Flags
| Flag | Shorthand | Default | Description |
|---|---|---|---|
--repo | — | current dir | Git repository root |
--from | — | — | Source ref (e.g., main) |
--to | — | — | Target ref (e.g., feature-branch) |
--commit | -c | — | Single commit to review |
--preview | -p | false | Preview which files will be reviewed without running the LLM |
--format | -f | text | Output format: text or json |
--concurrency | — | 8 | Max concurrent file reviews |
--timeout | — | 10 | Concurrent task timeout in minutes |
--audience | — | human | human (show progress) or agent (summary only) |
--background | -b | — | Optional requirement/business context for the review; auto-filled from commit message when using --commit |
--rule | — | — | Path to custom JSON review rules |
--max-tools | — | built-in | Max tool call rounds per file; only takes effect when greater than template default |
--max-git-procs | — | built-in | Max concurrent git subprocesses |
--tools | — | — | Path to custom JSON tools config |
Examples
# Preview which files will be reviewed (no LLM calls)
ocr review --preview
ocr review -c abc123 -p
# Review workspace changes with default settings
ocr review
# Review branch diff with higher concurrency
ocr review --from main --to my-feature --concurrency 4
# Review a specific commit with verbose JSON output
ocr review --commit abc123 --format json --audience agent
# Provide requirement context for more targeted review
ocr review --background "Adding rate limiting to the login API"
# Use custom review rules
ocr review --rule /path/to/my-rules.json
# Preview which rule applies to a file
ocr rules check src/main/java/com/example/Foo.java
ocr rules check --rule custom.json src/main/resources/mapper/UserMapper.xml
# View review session history in browser
ocr viewer
ocr viewer --addr :3000
Viewer security
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):
OCR_VIEWER_ALLOWED_HOSTS=review.internal,ocr.lan ocr viewer --addr :3000
This blocks DNS-rebinding attacks against the local viewer.
Review Rules
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.
| Priority | Source | Path | Description |
|---|---|---|---|
| 1 (highest) | --rule flag | User-specified path | CLI explicit override |
| 2 | Project config | <repoDir>/.opencodereview/rule.json | Per-project rules, can be committed to git |
| 3 | Global config | ~/.opencodereview/rule.json | User-wide personal preferences |
| 4 (lowest) | System default | Embedded system_rules.json | Built-in rules covering common languages and file types |
Rule File Format
Layers 1–3 share the same JSON format:
{
"rules": [
{
"path": "force-api/**/*.java",
"rule": "All new methods must validate required parameters for null values"
},
{
"path": "**/*mapper*.xml",
"rule": "Check SQL for injection risks, parameter errors, and missing closing tags"
}
]
}
pathsupports**recursive matching and{java,kt}brace expansion.- Within each layer, rules are evaluated in declaration order — the first match wins.
- If a rule file does not exist, it is silently skipped.
Path Filtering
Rule files also support include and exclude fields to control which files enter the review scope:
{
"rules": [
{"path": "**/*.java", "rule": "Check for null safety"}
],
"include": ["src/main/**/*.java", "lib/**/*.kt"],
"exclude": ["**/generated/**", "vendor/**"]
}
Filter decision priority (highest to lowest):
| Step | Condition | Result |
|---|---|---|
| 1 | File is binary | Excluded |
| 2 | Path matches user exclude pattern | Excluded |
| 3 | File extension not in supported list | Excluded |
| 4 | include is configured and path matches | Reviewed (skips step 5) |
| 5 | Path matches built-in default exclude pattern (test files, etc.) | Excluded |
| 6 | None of the above | Reviewed |
How it works:
includeandexcludefollow 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.excludealways wins overinclude— a file matching both is excluded.includeacts as a bypass for built-in default exclude patterns (e.g., test files), not as an exclusive allowlist — files not matching anyincludepattern still proceed through the default filter checks normally.- Pattern syntax: supports
**recursive matching,*single-segment matching, and{a,b}brace expansion. Matching is case-insensitive.
Built-in default exclude patterns (filters test files, etc. — can be overridden with include):
**/*_test.go, **/*Test.java, **/*Tests.java, **/*_test.rs,
**/*.test.{js,jsx,ts,tsx}, **/*.spec.{js,jsx,ts,tsx}, **/__tests__/**,
**/src/test/java/**/*.java, **/src/test/**/*.kt,
**/test/**/*_test.py, **/tests/**/*_test.py, **/*_test.py,
**/*_spec.rb, **/spec/**/*_spec.rb, **/oh_modules/**
Configuration Reference
Config file: ~/.opencodereview/config.json
| Key | Type | Example |
|---|---|---|
llm.url | string | https://api.openai.com/v1/chat/completions |
llm.auth_token | string | sk-xxxxxxx |
llm.auth_header | string | Anthropic only: x-api-key | authorization |
llm.model | string | claude-opus-4-6 |
llm.use_anthropic | boolean | true | false |
language | string | English | Chinese (default: Chinese) |
telemetry.enabled | boolean | true | false |
telemetry.exporter | string | console | otlp |
telemetry.otlp_endpoint | string | OTLP collector address |
telemetry.content_logging | boolean | Include prompts in telemetry |
Environment variables take precedence over the config file.
Environment Variables
| Variable | Purpose |
|---|---|
OCR_LLM_URL | LLM API endpoint URL |
OCR_LLM_TOKEN | API key / auth token |
OCR_LLM_AUTH_HEADER | Anthropic auth header (x-api-key or authorization) |
OCR_LLM_MODEL | Model name |
OCR_USE_ANTHROPIC | true = Anthropic, false = OpenAI |
Telemetry
OpenTelemetry integration for observability (spans, metrics). Disabled by default.
ocr config set telemetry.enabled true
ocr config set telemetry.exporter otlp
ocr config set telemetry.otlp_endpoint localhost:4317
Set telemetry.content_logging to include LLM prompts and responses in exported data.
Contributing
See CONTRIBUTING.md for development setup, coding guidelines, and how to submit pull requests.
Star History
License
Apache-2.0 — Copyright 2026 Alibaba
相似文章
Open Code Review – 一款由 AI 驱动的代码审查 CLI 工具
阿里巴巴已将 Open Code Review 开源,这是一款由 AI 驱动的代码审查 CLI 工具,将确定性工程方法与 LLM 智能体能力相结合。该工具最初作为内部工具使用,服务于数万名开发者,已识别出数百万处缺陷。它通过读取 Git diff 输出,利用可配置的模型端点生成结构化的行级审查意见。
@thinkszyg: AI 编程速度悖论:写代码快了 48%,Review 慢了 6 倍。Review 流程怎么重建? SD Times 分析 25 万开发者数据:AI 让编码提速 48-58%,但 AI 生成的 PR 在 Review 环节卡 4-6 倍时间…
文章指出AI编程使编码速度提升48-58%,但代码审查时间增加4-6倍,安全漏洞增加,并提出了三步重建审查流程的方案,包括AI预审、聚焦架构决策、以及使用微软开源的ASSERT框架进行行为验证。
@Smartpigai: 建议每个使用 AI 编程的人,都收藏这个113K stars开源项目: The Agency:一套现成的 AI 专家团队。 它整理了 232 个专业 Agent,覆盖前端、后端、DevOps、产品、设计、营销、安全、测试等 16 个方向。…
The Agency is a GitHub repository with 232 specialized AI agent prompts and workflows for roles like frontend, backend, DevOps, and more, designed to help developers use AI coding tools more effectively.
@NainsiDwiv50980: AI 智能体变得更聪明了,但理解代码库的方式却没变。大多数仍然逐个文件地爬取仓库……
SocratiCode 是一个完全开源的代码库智能引擎,它利用语义搜索、依赖关系图、影响分析和共享索引帮助 AI 导航仓库,无需供应商锁定。
@laobaishare: GitHub 亲自下场, 从此没有 AI 会再瞎写代码。 --- 刚发布的 Spec Kit,几天就冲到 95K star。 核心就一句话: 让 AI 在动代码之前,先把要做什么写清楚。 不再是甩一个模糊 prompt 然后烧香拜佛,祈祷…
GitHub发布了Spec Kit工具,强制AI在编写代码前先生成结构化规范,包括理解需求、追问遗漏、组织项目等步骤,显著减少AI生成的错误代码,兼容25+个AI agent。