Open Code Review – An AI-powered code review CLI tool
Open Code Review – An AI-powered code review CLI tool
Open Code Review – 一款 AI 驱动的代码审查 CLI 工具
The open source AI code review agent. 开源 AI 代码审查智能体。
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. 什么是 Open Code Review?Open Code Review 是一款 AI 驱动的代码审查 CLI 工具。它源自阿里巴巴集团内部官方的 AI 代码审查助手——在过去两年中,它服务了数万名开发者,并识别出了数百万个代码缺陷。经过大规模的充分验证后,我们将其孵化为面向社区的开源项目。
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. 只需配置模型端点即可开始使用。它读取 Git diff,通过具备工具调用能力的智能体将变更文件发送给可配置的大语言模型(LLM),并生成具有行级精度的结构化审查意见。该智能体能够读取完整文件内容、搜索代码库、检查其他变更文件以获取上下文,并提供深度审查,而不仅仅是表层的 diff 反馈。
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: 为什么选择 Open Code Review?通用智能体存在的问题。如果你曾使用过 Claude Code 等带有 Skills 的通用智能体进行代码审查,你可能遇到过以下痛点:
- 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.
- 质量不稳定——自然语言驱动的 Skills 难以调试,且审查质量会随着提示词的微小变化而产生显著波动。
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. 核心设计:确定性工程 × 智能体混合架构。Open Code Review 的核心理念是将确定性工程与智能体相结合,让两者各司其职。
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.
- 智能文件打包——将相关文件归为同一个审查单元(例如,将 message_en.properties 和 message_zh.properties 打包在一起)。每个包作为一个具有独立上下文的子智能体运行——这是一种分治策略,在处理超大变更集时依然保持稳定,并天然支持并发审查。
- 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.
- 外部定位与反思模块——独立的评论定位和评论反思模块系统性地提升了 AI 反馈的位置准确性和内容准确性。
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.
- 场景调优的提示词——针对代码审查深度优化的提示词模板,在提高效果的同时降低了 Token 消耗。
- 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
如何使用
Install Via NPM (Recommended) 通过 NPM 安装(推荐)
npm install -g @alibaba-group/open-code-review
After installation, the ocr command is available globally.
安装后,ocr 命令即可全局使用。
From GitHub Release 从 GitHub Release 下载
Download the latest binary from GitHub Releases: 从 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 1. 配置 LLM
You must configure an LLM before reviewing code. 在审查代码之前,必须先配置 LLM。
# Option A: Interactive config
# 选项 A:交互式配置
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)
# 选项 B:环境变量(优先级最高)
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. It is also compatible with Claude Code environment variables (ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_MODEL) and parses ~/.zshrc / ~/.bashrc for those exports.
配置存储在 ~/.opencodereview/config.json 中。它也兼容 Claude Code 的环境变量(ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_MODEL),并会解析 ~/.zshrc / ~/.bashrc 中的相关导出项。
Note for CC-Switch Users: CC-Switch 用户注意:
If you are using CC-Switch with routing service enabled, you can point llm.url to the CC-Switch proxy address without additional configuration:
如果你在使用开启了路由服务的 CC-Switch,可以将 llm.url 指向 CC-Switch 代理地址,无需额外配置:
- For Claude provider: set
llm.urltohttp://127.0.0.1:15721 - 对于 Claude 提供商:将
llm.url设置为http://127.0.0.1:15721 - For CodeX provider: set
llm.urltohttp://127.0.0.1:15721/v1 - 对于 CodeX 提供商:将
llm.url设置为http://127.0.0.1:15721/v1 - Set
llm.modelaccording to your provider settings - 根据你的提供商设置
llm.model llm.auth_tokencan be any valuellm.auth_token可以是任意值extra_bodysettings still applyextra_body设置依然有效