| name | pi-opencodereview |
| description | Run Alibaba OpenCodeReview (`ocr`) from pi for AI code review of Git workspace changes, branch ranges, or commits. Use when the user asks to review code, review a PR/diff/commit, find code quality issues, or review and optionally fix findings using OpenCodeReview. |
| license | Apache-2.0 |
| compatibility | Requires pi plus the `ocr` CLI from `@alibaba-group/open-code-review`; OCR requires its own Anthropic/OpenAI-compatible LLM configuration. |
| metadata | {"homepage":"https://github.com/reoring/pi-opencodereview","upstream":"https://github.com/alibaba/open-code-review"} |
Pi OpenCodeReview
Use this skill to run Alibaba OpenCodeReview (ocr) from pi.
OpenCodeReview reads Git diffs, runs deterministic file selection and per-file review subtasks, and emits line-level comments. In pi, prefer the bundled ocr_review extension tool when it is available because it forces JSON output and returns parsed details. The package also provides /ocr-review, which parses common OCR-like flags and asks pi to call ocr_review with structured parameters.
Safety contract
- A plain "review" request is read-only. Do not edit files.
- Only apply fixes when the user explicitly asks to fix, e.g. "review and fix", "修正して", "直して".
- If fixes are requested, focus on High and clear Medium findings.
- Ask before making broad, risky, or ambiguous changes.
- Never invent OCR/LLM credentials.
Prerequisites
Before the first review, verify:
which ocr || echo "ocr is not installed"
ocr version
ocr llm test
If ocr is missing, tell the user to install it:
npm install -g @alibaba-group/open-code-review
If ocr llm test fails, OCR needs its own LLM configuration. It does not automatically use pi's selected model.
Environment-variable setup example:
export OCR_LLM_URL=https://api.anthropic.com/v1/messages
export OCR_LLM_TOKEN=<api-key>
export OCR_LLM_MODEL=claude-opus-4-6
export OCR_USE_ANTHROPIC=true
Persistent config example:
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
Stop and ask the user to configure credentials if they are missing.
Preferred workflow
1. Understand the requested review target
Determine the mode:
| User intent | OCR mode |
|---|
| "review my changes" / "workspace" | no extra mode flags |
| "review this PR" / "compare branch" | --from <base> --to <head> |
| "review commit abc123" | --commit abc123 |
| "what would be reviewed?" | --preview |
Gather concise requirement/business context when available. Pass it as background / --background.
2. Run OCR
Prefer the extension tool if it exists:
Use the ocr_review tool with repo/from/to/commit/background/preview parameters.
For direct user invocation, /ocr-review supports these forms:
/ocr-review
/ocr-review --preview
/ocr-review --from main --to HEAD
/ocr-review --commit abc123 --background "payment retry bugfix"
/ocr-review --from main --to HEAD --fix
If the extension tool is not available, use bash:
ocr review --format json --audience agent --background "<context>" [mode flags]
Common examples:
ocr review --format json --audience agent
ocr review --format json --audience agent --from main --to HEAD
ocr review --format json --audience agent --commit abc123
ocr review --preview
Use --format json --audience agent for machine-readable output whenever not in preview mode.
3. Interpret and report
For each OCR comment, classify it:
- High: clear bug, security issue, data loss, crash, broken behavior, or precise high-confidence fix.
- Medium: plausible but context-dependent issue, edge case, maintainability/performance problem, or useful fix needing judgement.
- Low: likely false positive, style/nit, insufficient context, weak suggestion.
Report High and Medium findings grouped by priority. Mention Low only if the user asks for all findings.
Suggested format:
## OpenCodeReview Results
**Files reviewed**: N
**Issues found**: H high / M medium
### High
- `path/to/file.ts:42-45` — short issue summary
- Recommendation: concrete fix
### Medium
- `path/to/file.go:88` — short issue summary
- Recommendation: concrete fix or manual check
If no relevant findings remain:
OpenCodeReview complete — no high/medium issues found in N reviewed files.
4. Fix only when requested
When the user explicitly requested fixes:
- Read the relevant source files yourself before editing.
- Apply safe, local fixes for High and clear Medium findings.
- Run appropriate verification/tests.
- Summarize what changed and what remains manual.
When OCR returns start_line = 0 and end_line = 0, line positioning failed. Use the comment plus existing_code to locate the right code before editing.
Useful OCR flags
--repo <path>: target repository root.
--from <ref> --to <ref>: branch/ref range.
--commit <sha> / -c <sha>: single commit.
--background <text> / -b <text>: requirement context.
--preview / -p: preview target files without LLM.
--rule <path>: custom review rules.
--tools <path>: custom OCR tool definitions.
--concurrency <n>: reduce if rate-limited.
--timeout <minutes>: per-file timeout.
--skip-llm-test: extension-tool option to skip preflight when OCR is already known healthy.
--fix / --apply-fixes: /ocr-review command signal that the user explicitly requested fixes.
Gotchas
- OCR reviews untracked files in workspace mode.
- OCR uses its own LLM config (
OCR_LLM_*, ANTHROPIC_*, or ~/.opencodereview/config.json).
- Very large diffs may be skipped or warned by OCR token thresholds.
- OCR may return warnings for per-file subtask errors; include important warnings in the report.
/ocr-review --preview is the fastest smoke test because it checks target-file selection without requiring LLM calls.