coderabbit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCodeRabbit CLI and Configuration
CodeRabbit CLI 与配置
Local-first AI code review: catch issues before they reach the PR. The CodeRabbit CLI (, alias ) reviews working-tree or branch changes locally, so the PR-side review becomes confirmation instead of iteration -- this saves billable PR review rounds (both CodeRabbit's own quota and any Copilot credits). Covers the CLI surface and tuning. PR-side mechanics (threads, re-requests, the bot loop) live in the skill.
coderabbitcr.coderabbit.yamlgit-pr本地优先的AI代码审查:在问题进入PR之前发现它们。 CodeRabbit CLI(,别名)可在本地审查工作区或分支变更,让PR端审查变成确认环节而非迭代环节——这能节省可计费的PR审查次数(包括CodeRabbit自身的配额以及Copilot credits)。本文涵盖CLI的使用方法与的调优。PR端的机制(线程、重新请求、机器人循环)请查看技能文档。
coderabbitcr.coderabbit.yamlgit-prWhen to Use
使用场景
- Reviewing local changes -- "review my changes", "run coderabbit", pre-commit/pre-push/pre-PR checks
- Driving a review-fix loop -- run review, fix valid findings, re-run to verify
- Configuring CodeRabbit -- create or tune , reduce review noise, disable redundant linters
.coderabbit.yaml - Checking limits -- rate limits per plan, review budgeting
- Setting up the CLI -- install, auth, headless/CI usage
- 审查本地变更 —— "审查我的变更"、"运行coderabbit"、提交前/推送前/PR创建前检查
- 执行审查-修复循环 —— 运行审查、修复有效的审查结果、重新运行以验证
- 配置CodeRabbit —— 创建或调整、减少审查干扰、禁用冗余的代码检查工具
.coderabbit.yaml - 查看限制信息 —— 各套餐的速率限制、审查预算
- 设置CLI —— 安装、认证、无头模式/CI环境使用
Critical Rules
关键规则
- Reviews upload code to CodeRabbit's service. A review sends the diff (and context) to CodeRabbit. On a repo with sensitive/unpublished code, confirm the user is OK with that before the first run.
- Reviews consume a per-hour quota (Free: 3/hour CLI reviews). Scope deliberately (/
--committed,--uncommitted) and use--baseto replay the last result without spending a review.coderabbit review findings - Use output when driving fixes programmatically; the default plain-text mode is for humans.
--agent - Validate findings before fixing -- same rule as PR reviews: judge each finding on its merits; never blind-fix to silence the tool.
- CodeRabbit is optional -- check the Code Review Policy first (repo AGENTS.md/CLAUDE.md, falling back to the user's global agent instructions; see skill) for the preferred reviewer and checkpoints. Never install, authenticate, or run it on a project whose policy or user hasn't opted in.
git-pr
- 审查会将代码上传至CodeRabbit服务。审查会将代码差异(及上下文)发送给CodeRabbit。对于包含敏感/未发布代码的仓库,在首次运行前请确认用户是否同意此操作。
- 审查会消耗每小时配额(免费版:每小时3次CLI审查)。请合理设定审查范围(使用/
--committed、--uncommitted参数),并使用--base重放上次审查结果,无需消耗审查配额。coderabbit review findings - 程序化修复时使用输出;默认的纯文本模式面向人类用户。
--agent - 修复前验证审查结果 —— 与PR审查规则相同:根据实际情况判断每个审查结果的合理性;切勿盲目修复以消除工具提示。
- CodeRabbit为可选工具——请先查看代码审查政策(仓库的AGENTS.md/CLAUDE.md文件,若无则参考用户的全局代理指令;详见技能文档),确认首选的审查者与检查点。切勿在未获得项目政策或用户许可的情况下安装、认证或运行该工具。
git-pr
Setup
安装设置
bash
curl -fsSL https://cli.coderabbit.ai/install.sh | sh # or: brew install coderabbit
coderabbit auth login # browser OAuth; --agent emits JSON for agent-driven login
coderabbit auth status # verify
coderabbit doctor # diagnose runtime/auth/connectivity issuesauth login--api-key <key>--region us|eu--self-hostedauth orgNo paid plan required: the Free plan includes CLI reviews (3/hour) after with a free account -- paid plans add org context, learnings, and higher limits. Headless/CI: env var with an Agentic API key (requires the usage-based add-on on paid plans), or per call. self-updates.
coderabbit auth loginCODERABBIT_API_KEY--api-keycoderabbit updateThe CLI must run inside a git repository. is a shorthand alias for .
crcoderabbitbash
curl -fsSL https://cli.coderabbit.ai/install.sh | sh # 或:brew install coderabbit
coderabbit auth login # 浏览器OAuth认证;--agent参数会输出JSON以支持代理驱动的登录
coderabbit auth status # 验证认证状态
coderabbit doctor # 诊断运行时/认证/连接问题auth login--api-key <key>--region us|eu--self-hostedauth org无需付费套餐:免费账户完成后,免费版即可使用CLI审查(每小时3次)——付费套餐增加了组织上下文、学习功能和更高的限制。无头模式/CI环境:使用环境变量(需付费套餐的基于使用量的附加组件),或每次调用时使用参数。可自动更新CLI。
coderabbit auth loginCODERABBIT_API_KEY--api-keycoderabbit updateCLI必须在git仓库内运行。是的简写别名。
crcoderabbitReview Scopes and Checkpoints
审查范围与检查点
| Checkpoint | Command | Reviews |
|---|---|---|
| Before commit | | Staged + unstaged tracked changes |
| Before push | | Local commits not in the base branch |
| Before PR (full branch) | | Working tree + branch commits vs base |
| Subdirectory only | | Changes under a path |
| Vs specific commit | | Changes since a commit |
| Include untracked files | | Also files not yet added to git |
Defaults (CLI v0.7): all tracked changes, base = repository default branch, plain-text output. v0.7 removed the older and flags () -- scope with /, and plain is simply the default. runs a faster, lighter review policy for quick local iteration.
--type <scope>--plainerror: unknown option--committed--uncommitted--light| 检查点 | 命令 | 审查内容 |
|---|---|---|
| 提交前 | | 已暂存+未暂存的已跟踪变更 |
| 推送前 | | 本地仓库中未同步到基准分支的提交 |
| PR创建前(全分支) | | 工作区+分支提交与基准分支的差异 |
| 仅子目录 | | 指定路径下的变更 |
| 与特定提交对比 | | 自指定提交以来的变更 |
| 包含未跟踪文件 | | 还包含尚未添加到git的文件 |
默认设置(CLI v0.7):所有已跟踪变更,基准分支为仓库默认分支,纯文本输出。v0.7版本移除了旧版的和参数(会提示)——请使用/指定范围,纯文本为默认输出模式。参数会运行更快、更轻量化的审查策略,适用于快速本地迭代。
--type <scope>--plainerror: unknown option--committed--uncommitted--lightOutput Modes
输出模式
- Default (no mode flag) -- detailed plain-text feedback with fix suggestions, non-interactive.
- -- JSON-lines: one object per line. Finding objects carry
--agent,type: "finding"(severity),critical|major|minor|trivial|info,fileName, andsuggestions(written for coding agents -- follow them when fixing); acodegenInstructionsfield appears whencommentis empty. Heartbeat events appear during long reviews; a finalcodegenInstructionsevent carriescomplete(statuswith"review_skipped"when the scope has no changes).findings: 0 - -- replay cached findings from the most recent local review that produced findings (clean sessions are skipped), with no new analysis and no quota cost (
coderabbit review findingsreads a scoped review's cache). Use between fix iterations; only re-run a real review to verify at the end.--dir <path> - -- print the AI prompts from the most recent local review, no new review.
coderabbit review --show-prompts - -- review statistics (
coderabbit statsrescans review history).--rebuild
- 默认模式(无模式参数)—— 详细的纯文本反馈,包含修复建议,非交互式。
- 模式 —— JSON行格式:每行一个对象。审查结果对象包含
--agent、type: "finding"(severity)、critical|major|minor|trivial|info、fileName和suggestions(为编码代理编写的指令——修复时请遵循这些指令);当codegenInstructions为空时会出现codegenInstructions字段。长时间审查过程中会出现心跳事件;最终的comment事件包含complete(当审查范围无变更时,status为status且"review_skipped")。findings: 0 - —— 重放最近一次本地审查产生的缓存结果(无结果的会话会被跳过),无需重新分析,不消耗配额(
coderabbit review findings会读取指定范围审查的缓存)。适用于修复迭代过程中;仅在最后阶段重新运行正式审查以验证修复效果。--dir <path> - —— 打印最近一次本地审查使用的AI提示词,不会启动新的审查。
coderabbit review --show-prompts - —— 查看审查统计信息(
coderabbit stats参数会重新扫描审查历史)。--rebuild
The Local Review-Fix Loop
本地审查-修复循环流程
- Run (or
coderabbit review --committed --base {base} --agentpre-commit; background it -- reviews take minutes).--uncommitted - Parse findings; triage by . Address
severityandcriticalfirst.major - Validate each finding against the codebase (conventions, actual behavior, project docs). Fix valid ones per ; note invalid ones with a one-line rationale for the user.
codegenInstructions - Re-run the same review command to verify fixes. Stop when no valid /
criticalfindings remain, or the hourly bucket is exhausted (the CLI reports the limit -- wait or stop, never hammer).major - Then push / create the PR; the PR-side review (if any) should come back clean or near-clean.
Commit fixes by what they change, never by what prompted them -- , not or (see the skill). Fixes must not add code comments that restate what the code already reads.
fix: validate empty page cursorfix: coderabbit fixesfix: review round 2git-commitTwo passes (review, fix, verify) is the normal shape. More than three passes means findings are being treated as noise -- re-evaluate validity or tune config (see ).
references/configuration.md- 运行(提交前使用
coderabbit review --committed --base {base} --agent;可后台运行——审查需要数分钟时间)。--uncommitted - 解析审查结果;按优先级处理。优先解决
severity和critical级别的问题。major - 针对代码库验证每个审查结果(遵循代码规范、实际行为、项目文档)。根据修复有效的问题;为无效问题添加一行说明供用户参考。
codegenInstructions - 重新运行相同的审查命令以验证修复效果。当没有有效的/
critical级问题,或每小时配额耗尽时停止(CLI会提示限制信息——请等待配额重置,切勿频繁重试)。major - 然后推送代码/创建PR;PR端的审查(若有)应返回无问题或基本无问题的结果。
提交修复时应描述变更内容,而非触发修复的原因——例如提交信息应为,而非或(详见技能文档)。修复时不得添加重复代码含义的注释。
fix: validate empty page cursorfix: coderabbit fixesfix: review round 2git-commit正常流程为两次循环(审查、修复、验证)。若超过三次循环,说明审查结果被视为干扰——请重新评估结果的有效性或调整配置(详见)。
references/configuration.mdRate Limits (Per Developer, Per Hour)
速率限制(每位开发者每小时)
| Plan | CLI reviews | PR reviews | Files/review |
|---|---|---|---|
| Free | 3 | 1 (summary only) | 150 |
| Pro | 5 | 5 | 300 |
| Pro+ | 10 | 10 | 300 |
| Enterprise | 12 | 12 | 300 |
The Lite plan was retired (June 2026); Free / Pro / Pro+ / Enterprise are current. Beyond the hourly allowance, the usage-based add-on bills $0.25 per reviewed file (Pro and up). Open-source public repos get free reviews with popularity-based limits.
| 套餐 | CLI审查次数 | PR审查次数 | 每次审查文件数 |
|---|---|---|---|
| 免费版 | 3 | 1(仅摘要) | 150 |
| Pro版 | 5 | 5 | 300 |
| Pro+版 | 10 | 10 | 300 |
| 企业版 | 12 | 12 | 300 |
Lite套餐已停用(2026年6月);当前可用套餐为免费版/Pro版/Pro+版/企业版。超出每小时限额后,基于使用量的附加组件将按每份审查文件0.25美元计费(Pro版及以上)。开源公共仓库可免费获得审查服务,限额基于仓库热度。
Configuration
配置说明
.coderabbit.yaml-c <file>CLAUDE.mdprofiletone_instructionspath_filterscoderabbit config validate [file]Reference: Seefor the full schema highlights, config precedence, the low-noise template for typed/linted projects, and PR-side commands (references/configuration.mdvs@coderabbitai review, pause/resume, config dump).full review
仓库根目录下的文件同时管控PR端和CLI端的审查(CLI还支持通过参数加载额外的指令文件,例如)。对于类型化、已配置代码检查的项目,目标是仅获取高价值的审查结果:设置、,禁用与CI重复的代码检查工具,为生成文件设置。提交配置修改前,请使用(对照官方最新 schema 检查)验证编辑内容。
.coderabbit.yaml-c <file>CLAUDE.mdprofiletone_instructionspath_filterscoderabbit config validate [file]参考文档:完整的schema要点、配置优先级、适用于类型化/已配置代码检查项目的低干扰模板,以及PR端命令(vs@coderabbitai review、暂停/恢复、配置导出)请查看full review。references/configuration.md
Key Gotchas
常见陷阱
- needs commits,
--committedneeds a dirty tree -- reviewing the wrong scope silently reviews nothing (--uncommitted); match the scope to the checkpoint.review_skipped - replays, it does not re-review -- after fixing, cached findings still show; only a fresh review verifies fixes. It also skips clean sessions: even after a clean verify run, it replays the older findings, which is not a regression.
coderabbit review findings - The quota is per-hour, not per-day -- a "limit reached" message means wait for the window, not stop for the day. Plan verify runs so the final pass fits the bucket.
- CLI reviews and PR reviews draw from separate buckets -- burning CLI reviews locally does not reduce the PR-side allowance, which is the point of the local-first flow.
- Org context needs matching access -- on a repo not linked to your CodeRabbit org, reviews run in limited free mode (no learnings/org context); results differ from PR-side reviews on the same code.
- emits JSON lines, not a JSON document -- parse line-by-line; do not
--agentthe whole output.JSON.parse - and
--type <scope>no longer exist (removed in v0.7;--plain) -- older docs and allowlists reference them; useerror: unknown option/--committedand rely on the plain default.--uncommitted
Reference: Seeforreferences/configuration.mdtuning and PR commands Reference: See.coderabbit.yamlfor auto-approval patterns Reference: PR-side review loops, thread handling:references/allowlist.mdskill (git-pr)references/bot-review-loop.md
- 需要已提交的变更,
--committed需要未提交的工作区变更 —— 若审查范围错误,会静默地不执行任何审查(--uncommitted);请确保审查范围与检查点匹配。review_skipped - 仅重放结果,不重新审查 —— 修复后,缓存结果仍会显示之前的问题;只有重新运行正式审查才能验证修复效果。该命令还会跳过无结果的会话:即使完成了无问题的验证运行,它仍会重放旧的审查结果,这不属于回归问题。
coderabbit review findings - 配额按小时计算,而非按天 —— 出现"限额已达"提示意味着需等待配额重置窗口,而非当天停止使用。请合理安排验证运行时间,确保最终的验证环节能在配额内完成。
- CLI审查与PR审查使用独立的配额池 —— 在本地消耗CLI审查配额不会减少PR端的可用次数,这正是本地优先流程的意义所在。
- 组织上下文需要匹配访问权限 —— 对于未关联到你的CodeRabbit组织的仓库,审查将以受限的免费模式运行(无学习功能/组织上下文);结果会与同一代码的PR端审查结果不同。
- 模式输出JSON行,而非JSON文档 —— 请逐行解析;不要对整个输出执行
--agent。JSON.parse - 和
--type <scope>参数已不存在(v0.7版本移除;会提示--plain)—— 旧文档和允许列表中可能会提到这些参数;请使用error: unknown option/--committed指定范围,并依赖默认的纯文本输出。--uncommitted
参考文档:调优与PR命令请查看.coderabbit.yaml参考文档:自动批准模式请查看references/configuration.md参考文档:PR端审查循环、线程处理:references/allowlist.md技能(git-pr)references/bot-review-loop.md