Performs AI-powered code review on Git changes using the `ocr` CLI from alibaba/open-code-review. Use when the user asks to review code, review a pull request,
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-open-code-review-aae4cd352cfb ,按照其中的说明把「open-code-review」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
This Codex plugin skill intentionally mirrors the canonical skill at
skills/open-code-review/SKILL.md. Keep both files synchronized when updating
OCR agent instructions; a symlink is avoided because plugin installs may only
materialize the plugin subtree.
A skill for invoking open-code-review (ocr) — an open-source AI code review CLI that reads Git diffs and generates structured, line-level review comments.
Analyze the review target (commits, branch, or changes) to extract concise business context. Pass this context via --background to improve review quality.
Do not pre-check whether ocr is installed — skip probes like command -v ocr or ocr --version. Assume the CLI is available and run the review directly; that saves a tool call on the common path. Only if the review fails with command not found should you install it per Troubleshooting.
Run the OCR command with appropriate flags. Always pass business context via --background when available:
ocr review --audience agent --background "business context here" [user-args]
Argument handling:
--background "context" or -b "context" to provide business context for better review quality--commit or -c to review a single commit against its parent--from <ref> and --to <ref> to review diff between two refs--timeout × review rounds. Default --timeout 15 with default effort medium (2 rounds) gives 30 minutes; low/high give 15/45 minutes.--concurrency <n> if rate limits are hit--preview or -p to preview which files will be reviewed without running the LLM--output <path> to write the full result to a file instead of stdout. If the command fails with unknown flag: --output, do not continue the review with plain stdout. Ask the user whether to upgrade (npm i -g @alibaba-group/open-code-review@latest) and wait for the answer before proceeding. After the user confirms and the upgrade succeeds, rerun with --output.ocr command is not found, install it by running npm i -g @alibaba-group/open-code-reviewCommon invocation patterns:
| User says | Command to run |
|---|---|
| "review my changes" / "review the working copy" | ocr review --audience agent -b "context" |
| "review this PR" / "review feature branch" | ocr review --audience agent -b "context" --from main --to <branch> |
| "review commit abc123" | ocr review --audience agent -b "context" --commit abc123 |
| "what would be reviewed?" (dry-run) | ocr review --preview |
Output mode:
--audience agent to suppress progress UI and emit only the final summary--output /tmp/ocr_out.txt and inspect the file in full via a file reading tool instead of piping stdout through tail or head, which drops earlier review comments.On failure: If ocr review exits non-zero (e.g. an LLM connection error), do not retry blindly — consult the Troubleshooting section below for the matching fix before re-running.
OCR output includes structured severity (critical / high / medium / low) and category (bug / security / performance / maintainability / test / style / documentation / other) on each comment. Present results grouped by severity, discarding low severity items that are likely false positives or nitpicks.
Before applying fixes, check whether the user requested automatic fixes:
When fixing issues and suggestions:
Each comment in OCR's output contains:
path: File pathcontent: Review comment textstart_line / end_line: Line range (both 0 means positioning failed)category: Issue category (bug, security, performance, maintainability, test, style, documentation, other)severity: Issue severity (critical, high, medium, low)suggestion_code: Optional fix suggestionexisting_code: Optional original code snippetthinking: Optional LLM reasoning processPresent results grouped by severity using this template:
## Code Review Results
**Files reviewed**: N
**Issues found**: X critical, Y high, Z medium
### Critical
- **`path/to/file.java:42`** [bug] — Brief description
> Recommendation: How to fix
### High
- **`path/to/file.java:26`** [bug] — Brief description
> Recommendation: How to fix
### Medium
- **`path/to/file.ts:88`** [performance] — Brief description
> Recommendation: How to fix (if applicable)
If no critical, high, or medium severity issues remain after filtering, state: "Review complete — no critical, high, or medium issues found in N files."
Handling mispositioned comments:
When start_line and end_line are both 0, the comment failed to locate the exact position in the file. In such cases:
If the user wants project-specific rules, OCR resolves them in this priority order:
--rule <path> flag (highest)<repo>/.opencodereview/rule.json~/.opencodereview/rule.jsonBy default, the first matching user rule replaces the built-in system rule. Set merge_system_rule: true on a rule entry when the matched system rule and user rule should both be included.
Rule file format:
{
"rules": [
{
"path": "**/*.java",
"rule": "All new methods must validate required parameters for null",
"merge_system_rule": true
},
{
"path": "**/*mapper*.xml",
"rule": "Check SQL for injection risks and missing closing tags"
}
]
}
To preview which rule applies to a file before reviewing:
ocr rules check src/main/java/com/example/Foo.java
Beyond the common flags above, ocr review exposes a few groups of controls. Run ocr review --help for the complete list.
Scoping
--exclude '<patterns>' — comma-separated gitignore-style patterns (for example --exclude '**/generated/*,**/testdata/*'), merged with rule.json excludes.--background-file <path> — read review context from a Markdown file. Takes precedence over --background.Output
--format text|json|sarif — text (default) for humans; json for machine-readable findings; sarif for code-scanning integrations such as GitHub Code Scanning.Model
--provider <name> / --model <name> — override the configured provider/model for this run only (for example, to recheck a diff with a different model; the user names the model, ocr llm providers lists the built-ins).Budget
--max-tokens <n> — per-group prompt ceiling; defaults to the configured value or the template default (200000).--max-tokens-budget <n> — cap total input + output tokens for the run. Checked before every LLM round: a group already over budget gets one final round to submit findings, no further groups are dispatched, partial results are still published, and skipped files are reported as failed(budget).--no-filter — keep all review comments and skip the LLM post-filtering call.ocr review will fail loudly if no LLM is reachable. See the Troubleshooting section below if this happens.ocr review operates on the Git repo at the current directory. Use --repo /path/to/repo to run from elsewhere.ocr review includes staged, unstaged, and untracked changes. Stage selectively if you want narrower scope.MAX_TOKENS sets the prompt budget (200000 in the review template; ocr scan uses 58888); conversation context is compressed to stay within this prompt budget. Model output is capped separately by MAX_COMPLETION_TOKENS (16384). A file whose diff alone exceeds ~80% of MAX_TOKENS is skipped before the LLM is called.PLAN_MODE_LINE_THRESHOLD (default 50) or it holds 2+ files whose combined changed lines reach PLAN_MODE_GROUP_LINE_THRESHOLD (default 100). This adds latency but improves quality.--audience human — it streams progress UI that pollutes output. Always use --audience agent.language config controls review comment language, defaults to English, and accepts any language name (for example English or 中文).tail or head as it drops review comments from earlier sections. Use --output <path> and read it in full; on older CLIs, follow the Output file guidance above.ocr review --resume <id> using the same --from/--to or --commit target (the id is printed as retry with: --resume <id> on failure, or find it with ocr session list). Workspace resume is not supported.After the review completes, verify success by checking:
If errors occurred, check the stderr warnings for details about which files failed and why.
ocr: command not found
Install the CLI:
npm install -g @alibaba-group/open-code-review
unknown flag: --output
The CLI is older than v1.10.0. Do not continue the review with plain stdout. Ask the user whether to upgrade (npm i -g @alibaba-group/open-code-review@latest) and wait for the answer before proceeding. After the user confirms and the upgrade succeeds, rerun with --output.
ocr review fails with LLM connection error
Prompt the user to configure an LLM provider.
Interactive setup (recommended):
ocr config provider
Manual setup (alternative):
ocr config set llm.url https://api.anthropic.com/v1/messages
ocr config set llm.auth_token <api-key>
ocr config set llm.model claude-opus-4-6
ocr config set llm.use_anthropic true
Verify connectivity with ocr llm test. Stop here and ask the user to provide credentials — never invent or hardcode API keys.