OpenCodeReview

repository·main·Indexed 27 days ago

https://github.com/alibaba/open-code-review

An AI-powered code review CLI tool that uses a hybrid approach of deterministic engineering and LLM agents to provide high-precision, low-token reviews of Git diffs, entire files, or specific commits. It includes a VS Code extension GUI, integration with OpenCode via slash commands and tools (ocr_review, ocr_health), and a configurable LLM backend.

Tokens
48.7K
Snippets
142
Records
318
Agent score
93%

What's inside OpenCodeReview

  1. Overview of Open Code Review

    main

    Open Code Review is a CLI-based AI code review tool originally developed as an internal assistant for Alibaba Group. It uses a hybrid approach combining deterministic engineering (for file selection, bundling, and rule matching) with an AI agent (for dynamic context retrieval and scenario-specific reasoning).

    Key Capabilities:

    • Git Diff Review: Reads git diffs and generates structured, line-accurate review comments using a tool-use enabled LLM.
    • Deep Context: The agent can read full file contents, search the codebase, and cross-reference multiple files to provide deep reviews rather than superficial diff comments.
    • ocr scan: Allows for full-file scanning, which is useful for auditing unfamiliar codebases or directories without significant diffs.
    • High Precision: Designed to prioritize precision and minimize noise/false positives, consuming significantly fewer tokens (~1/9) compared to general-purpose agents like Claude Code.
  2. Overview of OCR Built-in Tools

    main

    OCR provides six built-in tools that an LLM can call during a code review. These tools are categorized by their availability during the plan phase (read-only) and the main task phase.

    ToolPlanMainPurpose
    task_doneSignal "I'm finished" — terminates the loop.
    code_commentEmit a review comment with line range + suggestion.
    file_readRead a slice of a file from the post-change snapshot.
    file_read_diffRead another file's diff to confirm a cross-file concern.
    file_findLocate files by filename keyword.
    code_searchGrep across the repo (literal or regex).

    Note: Context tools (file_read, file_read_diff, file_find, and code_search) are read-only and cannot be used to target comments in files other than the one currently under review. Cross-file concerns can only be surfaced as comments if they are observable from the current file's diff.

    To override the default tool registry, use the --tools <path> CLI flag with a JSON file matching the internal schema.

  3. Understand agent limitations and behavior

    main

    To maintain determinism and predictable costs, the agent operates with the following constraints:

    • No Endpoint Fallback: If a complete (URL, token, model) triple cannot be resolved from config, environment variables, or RC files, the agent exits with a non-zero code. It will not attempt to guess endpoints.
    • Isolated Failures: If a sub-agent fails while reviewing a specific file, it produces a warning and continues with the rest of the files. Retries should be handled by your CI pipeline.
    • No Cross-File Reasoning: Each file is reviewed in its own isolated LLM conversation. While the agent can use tools like file_read_diff or code_search to understand context, it cannot target findings in other files as comment targets. It is instructed to ignore issues that surface in files outside the current diff.
  4. Use Open Code Review VSCode Extension features

    main

    The extension integrates AI code review capabilities directly into your editor via a Preact-based WebView sidebar. Key features include:

    • Review Modes:
      • Workspace Changes: Review staged, unstaged, and untracked changes.
      • Branch Comparison: Compare two refs using --from and --to.
      • Single Commit: Review a specific commit using --commit.
    • File Preview: View changed files based on Git status; clicking a file opens the native VSCode diff view.
    • Custom Prompts: Append custom instructions to a review using the --background flag.
    • Streaming Logs: View real-time CLI output during the review process.
    • Two-way Sync: Review comments are displayed in the sidebar and rendered as CommentThread in the editor. Actions like 'Apply', 'Ignore', or 'Mark as False Positive' are synchronized between the sidebar and the editor.
  5. Planned features for H2 2026

    main

    The following features are planned for the second half of 2026:

    • JetBrains Plugin: Bringing AI code review to IntelliJ IDEA, GoLand, PyCharm, and other JetBrains IDEs.
    • Delegate Mode: A subscription-friendly, opt-in mode where ocr does not require a standalone LLM API key. Instead, ocr prepares a structured review task (resolving scope, applying excludes, loading rules, injecting context, and collecting diffs) and hands it off to a host coding agent (like Claude Code) to execute using its own agent loop and subscription.
    • Ultra Mode: An opt-in, higher-recall review mode designed for security-sensitive or high-risk changesets. It trades increased token consumption and longer review times for a significantly higher issue recall rate.
  6. Planned features for H1 2027

    main

    The following feature is planned for the first half of 2027:

    • Domain-Specific Long-Term Memory: Enables the review engine to accumulate persistent, domain-specific knowledge (such as recurring patterns, past review decisions, and project-specific conventions) to improve relevance and reduce repeated feedback in future reviews.
  7. Understand the Plan Task System Prompt Structure

    main

    The plan_task_system prompt is used by the agent to act as an expert in code review task planning. It instructs the agent to analyze code changes, identify risk points, and plan tool-calling strategies.

    Core Logic:

    • Scope: The agent only analyzes newly added and modified code, ignoring deleted code.
    • Severity Levels: Issues are categorized as high (security, data loss, crashes), medium (performance, maintainability), or low (style, readability).
    • Analysis Requirements: Each issue description must include the problem location, the nature of the problem, and the potential impact.
    • Tool Usage: The agent does not invoke tools directly in this phase; instead, it provides tool_guidance describing the intent and arguments for subsequent steps.
  8. Review Comment Processing Pipeline

    main

    Comments generated via code_comment tool calls are processed through a multi-step pipeline to ensure accuracy:

    1. Line Resolution: Matches existing_code against the diff to find start_line and end_line. If matching fails, lines default to 0 (unanchored).
    2. Re-location Task (Fallback): If resolution fails on non-trivial diffs, the model is asked to re-anchor the snippet.
    3. Review Filter: An LLM (REVIEW_FILTER_TASK) inspects comments against the diff to remove provably incorrect ones.
    4. Second Line-Resolution Pass: A final pass is run after Agent.Run completes to catch comments spanning multiple files or updated by re-location.
    5. Render: Final output is formatted as text or JSON.
  9. Understand OCR privacy and data transmission

    main

    OCR only sends your diffs and optional read-tool snippets to your configured LLM endpoint. All other data, including session JSONLs and rule files, remains local to your machine.

    Regarding telemetry: the content_logging flag is currently reserved and does not affect code paths; prompt and response content is never exported to collectors regardless of this flag's value. It is recommended to leave content_logging set to false in production.

  10. Understand the Claude Code OCR Workflow

    main

    The Claude Code plugin follows a three-step automated workflow designed for a "review and clean up" experience:

    1. Run the review: It executes ocr review --audience agent using flags inferred from your prompt. It includes a 5-minute timeout for output capture.
    2. Filter and evaluate: Findings are classified as High, Medium, or Low. Low-confidence comments (potential false positives or nitpicks) are silently dropped to reduce noise.
    3. Fix: The command automatically applies fixes for High and Medium priority items.

    Note: Unlike the standard Agent Skill, this specific Claude Code command is designed to auto-fix by default. To change this behavior (e.g., to ask before touching code), you must edit your local copy of the open-code-review.md prompt file.

  11. Understand the OpenCodeReview project structure

    main

    The repository is organized as follows:

    • cmd/opencodereview/: CLI entry point
    • internal/: Core logic
      • agent/: Review agent logic
      • config/: Configuration management
      • diff/: Git diff parsing
      • llm/: LLM API clients (Anthropic & OpenAI)
      • model/: Data models
      • session/: Review session management
      • tool/: Built-in tools (e.g., file_read, code_search)
      • telemetry/: OpenTelemetry integration
      • viewer/: WebUI session viewer
    • pages/: WebUI frontend
    • scripts/: Build & installation scripts
    • bin/: NPM wrapper
  12. Understand the Open Code Review High-Level Pipeline

    main

    The ocr review process follows a structured pipeline to transform code changes into review comments:

    1. Bootstrap: Resolves LLM endpoints (via config, env, or rc files) and loads templates, tool registries, and system rules.
    2. Diff Provider: Generates diffs using Git (Workspace, Commit, or Range modes).
    3. Filter & Rules: Applies a 5-gate filter to drop binaries, excluded paths, and unsupported extensions.
    4. Subtask Dispatch: Dispatches parallel sub-agents for each file (bounded by --concurrency). Each sub-agent performs an optional Plan phase followed by a Main loop (tool-use).
    5. Output Writer: Resolves line numbers and filters comments, then renders the final output as text or JSON based on --format or --audience.