跳转至

概览

<div align="center">
  <a href="https://open-codereview.ai">
    <img src="imgs/logo-core.svg" alt="OpenCodeReview logo" width="180" />
  </a>
  <h1>OpenCodeReview</h1>
</div>

<p align="center">
  <a href="https://trendshift.io/repositories/41087?utm_source=repository-badge&amp;utm_medium=badge&amp;utm_campaign=badge-repository-41087" target="_blank" rel="noopener noreferrer">
    <img src="https://trendshift.io/api/badge/repositories/41087" alt="alibaba%2Fopen-code-review | Trendshift" style="width: 280px; height: 60px;" width="280" height="60" />
  </a>
</p>
<p align="center">
  <a href="https://trendshift.io/repositories/41087" target="_blank">
    <img src="https://trendshift.io/api/badge/trendshift/repositories/41087/weekly" alt="alibaba%2Fopen-code-review | Trendshift" style="width: 280px; height: 60px;" width="280" height="60" />
  </a>
  <a href="https://trendshift.io/repositories/41087" target="_blank">
    <img src="https://trendshift.io/api/badge/trendshift/repositories/41087/monthly?language=Go" alt="alibaba%2Fopen-code-review | Trendshift" style="width: 280px; height: 60px;" width="280" height="60" />
  </a>
</p>
<p align="center" markdown="span">
  <a href="https://www.npmjs.com/package/@alibaba-group/open-code-review"><img alt="npm" src="https://img.shields.io/npm/v/@alibaba-group/open-code-review?style=flat-square" /></a>
  <a href="https://github.com/alibaba/open-code-review/actions/workflows/release.yml"><img alt="Build status" src="https://img.shields.io/github/actions/workflow/status/alibaba/open-code-review/release.yml?style=flat-square" /></a>
  <a href="https://github.com/alibaba/open-code-review/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/alibaba/open-code-review?style=flat-square" /></a>
  <a href="https://deepwiki.com/alibaba/open-code-review"><img alt="Ask DeepWiki" src="https://img.shields.io/badge/Ask-DeepWiki-blue?style=flat-square" /></a>
  <a href="https://www.bestpractices.dev/projects/13328"><img alt="OpenSSF Best Practices" src="https://img.shields.io/badge/OpenSSF-Gold-D4AF37?style=flat-square" /></a>
</p>
<p align="center" markdown="span">
  <a href="#supported-platforms"><img alt="Windows" src="https://img.shields.io/badge/Windows-supported-blue.svg" /></a>
  <a href="#supported-platforms"><img alt="macOS" src="https://img.shields.io/badge/macOS-supported-blue.svg" /></a>
  <a href="#supported-platforms"><img alt="Linux" src="https://img.shields.io/badge/Linux-supported-blue.svg" /></a>
  <a href="#supported-agents"><img alt="Claude Code" src="https://img.shields.io/badge/Claude_Code-supported-blueviolet.svg" /></a>
  <a href="#supported-agents"><img alt="Codex" src="https://img.shields.io/badge/Codex-supported-blueviolet.svg" /></a>
  <a href="#supported-agents"><img alt="Cursor" src="https://img.shields.io/badge/Cursor-supported-blueviolet.svg" /></a>
  <a href="#supported-agents"><img alt="Kimi Code" src="https://img.shields.io/badge/Kimi_Code-supported-blueviolet.svg" /></a>
</p>
<p align="center" markdown="span">
  English | <a href="docs/i18n/README.zh-CN.html">简体中文</a> | <a href="docs/i18n/README.ja-JP.html">日本語</a> | <a href="docs/i18n/README.ko-KR.html">한국어</a> | <a href="docs/i18n/README.ru-RU.html">Русский</a>
</p>

---

## 什么是 Open Code Review? {#what-is-open-code-review}

Open Code Review 是一款由 AI 驱动的代码审查 CLI 工具。它源于阿里巴巴集团内部官方的 AI 代码审查助手——在过去两年中,它服务了数万名开发者,并识别了数百万个代码缺陷。在大规模场景下经过充分验证后,我们将其孵化为一个开源项目并贡献给社区。只需配置一个模型端点即可开始使用。

它读取 Git diff,通过具备工具调用能力的 agent 将变更文件发送给可配置的 LLM,并生成行级精度的结构化审查评论。该 agent 可以读取完整文件内容、搜索代码库、查看其他变更文件以获取上下文,从而产出深度审查——而不仅仅是表层的 diff 反馈。除 diff 审查外,`ocr scan` 还会审查整个文件,用于审计不熟悉的代码库或没有有效 diff 的目录。

访问[官方网站](https://open-codereview.ai)了解更多详情。

![亮点](imgs/highlights-en.png)

## 基准测试 {#benchmark}

> 与通用 agent(Claude Code)相比,Open Code Review 在使用相同底层模型的情况下,**Precision** 和 **F1** 显著更高,同时仅消耗 **约 1/9 的 Token**,且审查完成速度更快。需要注意的是,其 Recall 低于通用 agent——这是一种刻意的取舍,优先保证精确度、减少噪声。

这是一个基于 **50** 个热门开源仓库、**200** 个真实 Pull Request 和 **10** 种编程语言构建的真实代码审查基准——由 80+ 位资深工程师交叉验证(**1,505** 个带标注的真实问题)。

<a href="https://huggingface.co/datasets/Alibaba-Aone/aacr-bench"><img src="https://huggingface.co/favicon.ico" alt="Hugging Face" width="20" height="20" /> 在 Hugging Face 上探索 AACR-Bench 数据集</a>。

| 指标 | 衡量内容 | 重要性 |
|--------|-----------------|----------------|
| **F1** | Precision 与 Recall 的调和平均值 | 衡量整体审查质量的最佳单一指标 |
| **Precision** | 上报问题中真实缺陷所占的比例 | 越高 = 需要处理的误报越少 |
| **Recall** | 真实缺陷中被发现的比例 | 越高 = 审查中遗漏的问题越少 |
| **Avg Time** | 每次审查的实际耗时 | 影响 CI 流水线延迟 |
| **Avg Token** | 每次审查消耗的 Token 总量 | 直接影响 API 成本 |

![基准测试](imgs/benchmark-en.png)

## 为什么选择 Open Code Review? {#why-open-code-review}

### 通用 Agent 的问题 {#the-problem-with-general-purpose-agents}

如果你使用过类似 Claude Code 这样带 Skills 的通用 agent 进行代码审查,你很可能遇到过以下痛点:

- **覆盖不完整** — 在较大的变更集中,agent 往往会"偷工减料",只选择性地审查部分文件而遗漏其他文件。
- **位置偏移** — 上报的问题经常与实际代码位置不符,行号或文件引用偏离目标。
- **质量不稳定** — 基于自然语言驱动的 Skills 难以调试,审查质量会因微小的 Prompt 变化而大幅波动。

根本原因:纯粹由语言驱动的架构在审查流程上缺乏硬性约束。

核心设计:确定性工程 × 智能体混合

Open Code Review 的核心理念是将确定性工程与智能体相结合,让二者各展所长。

确定性工程——硬性约束

对于绝不能出错的审查步骤,由工程逻辑——而非语言模型——保证正确性:

  • 精确的文件选择——准确判定哪些文件需要审查、哪些应被过滤,确保不遗漏任何重要变更。
  • 智能文件分组——将相关文件归入同一个审查单元(例如 message_en.properties 和 message_zh.properties 会被合并在一起)。每个分组作为一个拥有独立上下文的子智能体运行——这是一种分而治之的策略,在非常庞大的变更集上依然保持稳定,并天然支持并发审查。
  • 细粒度规则匹配——将审查规则与每个文件的特征进行匹配,让模型的注意力高度聚焦,从源头消除信息噪声。与纯粹由语言驱动的规则引导相比,基于模板引擎的规则匹配更稳定、更可预测。
  • 外部定位与反思模块——独立的评论定位模块和评论反思模块,系统性地提升 AI 反馈的位置准确性和内容准确性。

智能体——动态决策

智能体的优势集中在最关键之处——动态决策与动态上下文检索:

  • 场景调优的 Prompt——为代码审查深度优化的 Prompt 模板,在提升效果的同时降低 Token 消耗。
  • 场景调优的工具集——从大规模生产数据中对工具调用轨迹进行深度分析后提炼而成,包括调用频率分布、各工具的重复率、新工具对整个调用链的影响。与通用智能体工具包相比,这一为代码审查专门构建的工具集更稳定、更可预测。

如何使用

前提条件

  • Git >= 2.41——Open Code Review 依赖 Git 进行 diff 生成、代码搜索和仓库操作。

CLI

安装

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

安装完成后,ocr 命令即可在全局使用。

如需其他安装方式(安装脚本、GitHub Release 二进制、源码构建),请参阅安装。

快速开始

1. 配置 LLM

在审查代码之前,你必须先配置 LLM,除非你使用委托模式。

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

交互式界面会引导你完成提供商选择、API 密钥输入和模型配置,然后自动测试连通性。

关于 CLI 配置、环境变量、自定义提供商及其他高级配置,请参阅配置。

2. 审查

cd your-project

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

# Branch range — reviews feature-branch's changes since it diverged from main (merge-base mode)
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
ocr scan --resume <session-id>   # resume an interrupted full-file scan

# Save results to a file (recommended for AI host agents)
ocr review --format json --output result.json

# 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

文档

完整文档位于 open-codereview.ai/docs:

  • 快速入门 —— 安装并运行你的第一次审查
  • 安装 —— 所有平台与包管理器
  • CLI 参考 —— 所有命令与选项
  • 审查规则 —— 通过路径过滤与目标定向自定义审查规则
  • 配置 —— 配置项和环境变量
  • MCP 服务器 —— 使用外部工具扩展审查智能体
  • 编码智能体集成 —— 选择你使用的平台
  • Claude Code —— 安装包含审查斜杠命令的插件
  • Codex —— 安装包含可调用审查技能的插件
  • Cursor —— 安装包含可移植审查技能的插件
  • Kimi Code —— 安装包含审查斜杠命令和技能的插件
  • OpenCode —— 安装原生审查工具和斜杠命令
  • QCA Forward —— 使用 QCA 宿主模型和可直接发布的模板运行委托模式
  • 兼容 Skill 的智能体 —— 安装可移植的智能体技能
  • 审查执行模式 —— 集成后,选择由哪个 LLM 执行审查
  • 默认(OCR 管理) —— OCR 使用其配置的 LLM 运行审查
  • 委托模式 —— 你的编码智能体使用自己的 LLM 运行审查,无需 OCR API 密钥
  • CI/CD 集成 —— 支持 GitHub Actions、GitLab CI、GitFlic CI 和 Gerrit 集成
  • 会话查看器 —— 在浏览器中浏览和回放审查会话,将评论标记为已修复或已忽略,并在处理审查发现时隐藏它们
  • 遥测 —— 集成 OpenTelemetry 以实现可观测性
  • FAQ —— 常见问题与故障排查

参与贡献

本项目感谢所有贡献者。有关开发环境搭建、编码规范以及如何提交 Pull Request,请参阅 CONTRIBUTING.md。

许可证

Apache-2.0 — 版权所有 2026 Alibaba

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 op/open-code-review