### Install Dependencies and Start Watch Mode Source: https://github.com/alibaba/open-code-review/blob/main/extensions/vscode/README.md Navigate to the VS Code extension directory, install dependencies using Yarn, and start the watch-mode development build. ```bash cd extensions/vscode yarn install yarn watch ``` -------------------------------- ### Configure LLM Interactively Source: https://github.com/alibaba/open-code-review/blob/main/README.md Guides the user through selecting an LLM provider and model. This is the recommended method for initial setup. ```bash ocr config provider # Select a built-in provider or add a custom one ocr config model # Pick a model for the active provider ``` -------------------------------- ### Install CLI from Source Source: https://github.com/alibaba/open-code-review/blob/main/README.md Clones the repository, builds the project, and installs the binary to /usr/local/bin/ocr. ```bash git clone https://github.com/alibaba/open-code-review.git cd open-code-review make build sudo cp dist/opencodereview /usr/local/bin/ocr ``` -------------------------------- ### Install CLI from GitHub Release (macOS/Linux) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Installs the latest binary for your OS/architecture using a curl script. The script verifies the checksum and installs 'ocr' in /usr/local/bin. ```bash curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh | sh ``` -------------------------------- ### Setup Workflow File Source: https://github.com/alibaba/open-code-review/blob/main/examples/github_actions/README.md Copy the provided workflow file to your repository's .github/workflows/ directory to enable OpenCodeReview integration. ```bash mkdir -p .github/workflows cp ocr-review.yml .github/workflows/ocr-review.yml ``` -------------------------------- ### Install CLI from GitHub Release with Custom Directory/Version Source: https://github.com/alibaba/open-code-review/blob/main/README.md Installs the CLI from a GitHub release, allowing customization of the installation directory and specific version. ```bash OCR_INSTALL_DIR="$HOME/.local/bin" OCR_VERSION=v1.3.13 \ sh -c "$(curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh)" ``` -------------------------------- ### Build and Test Project Source: https://github.com/alibaba/open-code-review/blob/main/CONTRIBUTING.md Follow these commands to build the project and run tests after cloning the repository. Ensure you have Go, Git, and Make installed. ```bash git clone https://github.com//open-code-review.git cd open-code-review git remote add upstream https://github.com/alibaba/open-code-review.git make build make test ``` -------------------------------- ### Install OCR as a Codex Plugin (Marketplace) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Commands to install the OCR plugin for local Codex from the marketplace. ```bash codex plugin marketplace add alibaba/open-code-review codex /plugins ``` -------------------------------- ### Commit Message Examples Source: https://github.com/alibaba/open-code-review/blob/main/CONTRIBUTING.md Examples demonstrating the Conventional Commits format for various types of changes. ```text feat(agent): add support for custom tool definitions ``` ```text fix(llm): handle timeout errors in Anthropic API calls ``` ```text docs(README): update configuration examples ``` -------------------------------- ### Install OCR CLI Source: https://github.com/alibaba/open-code-review/blob/main/skills/open-code-review/SKILL.md Installs the open-code-review CLI globally using npm. Run this if the 'ocr' command is not found. ```bash npm install -g @alibaba-group/open-code-review ``` -------------------------------- ### Manual Download and Install CLI (Linux x86_64) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Manually downloads the binary for Linux on x86_64 architecture, makes it executable, and moves it to /usr/local/bin. ```bash # Linux (x86_64) curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-linux-amd64 chmod +x ocr && sudo mv ocr /usr/local/bin/ocr ``` -------------------------------- ### Install Extension Locally Source: https://github.com/alibaba/open-code-review/blob/main/extensions/vscode/README.md Use this command to install the generated .vsix file locally. Alternatively, you can install it via the VS Code Extensions panel by selecting 'Install from VSIX…'. ```bash code --install-extension open-code-review-vscode-.vsix ``` -------------------------------- ### Manual Download and Install CLI (Linux ARM64) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Manually downloads the binary for Linux on ARM64 architecture, makes it executable, and moves it to /usr/local/bin. ```bash # Linux (ARM64) curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-linux-arm64 chmod +x ocr && sudo mv ocr /usr/local/bin/ocr ``` -------------------------------- ### Install OCR CLI Globally Source: https://github.com/alibaba/open-code-review/blob/main/extensions/vscode/README.md Install the Open Code Review CLI tool globally using npm. ```bash npm i -g @alibaba-group/open-code-review ``` -------------------------------- ### Manual Download and Install CLI (macOS Intel) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Manually downloads the binary for macOS on Intel processors, makes it executable, and moves it to /usr/local/bin. ```bash # macOS (Intel) curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-darwin-amd64 chmod +x ocr && sudo mv ocr /usr/local/bin/ocr ``` -------------------------------- ### Manual Download and Install CLI (Windows x86_64) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Manually downloads the Windows x86_64 binary. The user needs to move 'ocr.exe' to a directory in their PATH. ```bash # Windows (x86_64) — move ocr.exe to a directory in your PATH curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-windows-amd64.exe ``` -------------------------------- ### Manual Download and Install CLI (Windows ARM64) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Manually downloads the Windows ARM64 binary. The user needs to move 'ocr.exe' to a directory in their PATH. ```bash # Windows (ARM64) — move ocr.exe to a directory in your PATH curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-windows-arm64.exe ``` -------------------------------- ### Install OCR as a Codex Plugin (Local Checkout) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Commands to install the OCR plugin for local Codex from a local checkout or fork. ```bash codex plugin marketplace add . codex /plugins ``` -------------------------------- ### Install OCR as a Skill using npx Source: https://github.com/alibaba/open-code-review/blob/main/README.md Use this command to install the OCR skill into your project, enabling your coding agent to invoke OCR for code reviews. ```bash npx skills add alibaba/open-code-review --skill open-code-review ``` -------------------------------- ### Manual Download and Install CLI (macOS Apple Silicon) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Manually downloads the binary for macOS on Apple Silicon, makes it executable, and moves it to /usr/local/bin. ```bash # macOS (Apple Silicon) curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-darwin-arm64 chmod +x ocr && sudo mv ocr /usr/local/bin/ocr ``` -------------------------------- ### GitLab CI Workflow Example Source: https://github.com/alibaba/open-code-review/blob/main/examples/gitlab_ci/README.md Illustrates the automated workflow triggered by Merge Request events, leading to code review and discussion posting. ```text MR Created/Updated → GitLab Pipeline Triggered → OCR Reviews Diff → Discussions Posted on MR ``` -------------------------------- ### Invoke OCR in Codex Source: https://github.com/alibaba/open-code-review/blob/main/README.md Examples of how to invoke the installed Open Code Review plugin in Codex for various review scenarios. ```text @Open Code Review review my current changes @Open Code Review review this branch against main @Open Code Review review and fix high-confidence issues ``` -------------------------------- ### Check OCR CLI Installation and LLM Connectivity Source: https://github.com/alibaba/open-code-review/blob/main/skills/open-code-review/SKILL.md Verifies if the 'ocr' CLI is installed and if it can connect to the configured LLM. Run these commands before initiating a code review. ```bash which ocr || echo "NOT INSTALLED" ocr llm test ``` -------------------------------- ### Rule File Format Example Source: https://github.com/alibaba/open-code-review/blob/main/README.md Defines rules for code review, specifying file paths and associated rule descriptions. Supports glob patterns like ** and brace expansion. ```json { "rules": [ { "path": "force-api/**/*.java", "rule": "All new methods must validate required parameters for null values" }, { "path": "**/*mapper*.xml", "rule": "Check SQL for injection risks, parameter errors, and missing closing tags" } ] } ``` -------------------------------- ### Install OCR as a Claude Code Plugin Source: https://github.com/alibaba/open-code-review/blob/main/README.md Commands to install the OCR plugin for Claude Code, registering the \/open-code-review:review slash command. ```bash /plugin marketplace add alibaba/open-code-review /plugin install open-code-review@open-code-review ``` -------------------------------- ### Configure GitLab CI for OpenCodeReview Source: https://github.com/alibaba/open-code-review/blob/main/examples/gitlab_ci/README.md This snippet shows how to install OpenCodeReview, configure its settings, and use a Python wrapper script to conditionally run reviews based on existing comments. It helps prevent re-reviewing MRs on every push. ```yaml script: # Install OpenCodeReview - npm install -g @alibaba-group/open-code-review # Configure OCR - mkdir -p ~/.open-code-review - | ocr config set llm.url $OCR_LLM_URL ocr config set llm.auth_token $OCR_LLM_AUTH_TOKEN ocr config set llm.model $OCR_LLM_MODEL ocr config set llm.use_anthropic false ocr config set llm.extra_body '{"thinking": {"type": "disabled"}}' # Check for existing OCR reviews and run review only if not found - | python3 << 'WRAPPER_SCRIPT' import json import os import subprocess import sys import urllib.request GITLAB_URL = os.environ.get("CI_SERVER_URL", "https://gitlab.com") PROJECT_ID = os.environ["CI_PROJECT_ID"] MR_IID = os.environ["CI_MERGE_REQUEST_IID"] API_TOKEN = os.environ["GITLAB_API_TOKEN"] SOURCE_BRANCH = os.environ["CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"] TARGET_BRANCH = os.environ["CI_MERGE_REQUEST_TARGET_BRANCH_NAME"] # Check for existing OCR reviews url = f"{GITLAB_URL}/api/v4/projects/{PROJECT_ID}/merge_requests/{MR_IID}/notes?per_page=100" req = urllib.request.Request(url, headers={"PRIVATE-TOKEN": API_TOKEN}) with urllib.request.urlopen(req) as resp: notes = json.loads(resp.read().decode("utf-8")) for note in notes: if "OpenCodeReview" in note.get("body", ""): print("⏭️ OCR has already reviewed this MR. Skipping to save tokens.") print("Delete previous OCR comments to re-trigger review.") sys.exit(0) # No existing review found - run OCR print("🔍 No existing OCR review found. Running review...") COMMIT_SHA = os.environ["CI_COMMIT_SHA"] result = subprocess.run([ "ocr", "review", "--from", f"origin/{TARGET_BRANCH}", "--to", COMMIT_SHA, "--format", "json", "--audience", "agent" ], capture_output=True, text=True) # Save output for the posting script with open("/tmp/ocr-result.json", "w") as f: f.write(result.stdout) with open("/tmp/ocr-stderr.log", "w") as f: f.write(result.stderr) print("OCR review completed.") WRAPPER_SCRIPT # Post review comments to MR - | python3 << 'PYTHON_SCRIPT' ...existing post script... PYTHON_SCRIPT ``` -------------------------------- ### GitHub Suggestion Syntax Example Source: https://github.com/alibaba/open-code-review/blob/main/examples/github_actions/README.md Demonstrates how OCR uses GitHub's native suggestion syntax for inline code review comments. Reviewers can apply suggested fixes with a single click. ```markdown **Suggestion:** ```suggestion // Fixed code here ``` ``` -------------------------------- ### Install Specific OCR Version Source: https://github.com/alibaba/open-code-review/blob/main/examples/gitlab_ci/README.md Install a specific version of the Open Code Review package using npm. ```yaml script: - npm install -g @alibaba-group/open-code-review@1.0.0 ``` -------------------------------- ### Install Specific Open Code Review Version Source: https://github.com/alibaba/open-code-review/blob/main/examples/github_actions/README.md Specify the exact version of the OpenCodeReview package to install using npm. This ensures consistent behavior across runs. ```yaml - name: Install OpenCodeReview run: npm install -g @alibaba-group/open-code-review@1.0.0 ``` -------------------------------- ### Run Code Review with Business Context Source: https://github.com/alibaba/open-code-review/blob/main/plugins/open-code-review/skills/open-code-review/SKILL.md Execute the OCR review command, providing business context via the --background flag for improved review quality. Always use --audience agent to suppress UI and get only the final summary. ```bash ocr review --audience agent --background "business context here" [user-args] ``` -------------------------------- ### Use Custom Review Rules with OCR Source: https://github.com/alibaba/open-code-review/blob/main/README.md Apply custom review rules defined in a JSON file to guide the code review process. ```bash ocr review --rule /path/to/my-rules.json ``` -------------------------------- ### Build Production Artifacts Source: https://github.com/alibaba/open-code-review/blob/main/extensions/vscode/README.md Run this command to create production-ready artifacts for the extension host and webview. The output files are located in the 'out/' directory. ```bash yarn build # production build (webpack production) ``` -------------------------------- ### Configure OCR Provider and Model Source: https://github.com/alibaba/open-code-review/blob/main/README.md Use these commands to interactively set up the code review provider and model. You can also list available LLM providers. ```bash ocr config provider ocr config model ocr llm providers ``` -------------------------------- ### Preview Files to be Reviewed Source: https://github.com/alibaba/open-code-review/blob/main/plugins/open-code-review/skills/open-code-review/SKILL.md Use the --preview or -p flag to see which files would be included in the review process without actually running the LLM analysis. This is useful for dry-runs. ```bash ocr review --preview ``` -------------------------------- ### Configure LLM Settings via CLI Source: https://github.com/alibaba/open-code-review/blob/main/extensions/vscode/README.md Configure Language Model settings such as URL, authentication token, model name, and provider using the OCR CLI. ```bash ocr config set llm.url https://api.anthropic.com/v1/messages ``` ```bash ocr config set llm.auth_token sk-... ``` ```bash ocr config set llm.model claude-opus-4-6 ``` ```bash ocr config set llm.use_anthropic true ``` -------------------------------- ### Run Code Review with Business Context Source: https://github.com/alibaba/open-code-review/blob/main/skills/open-code-review/SKILL.md Initiates a code review using the 'ocr review' command. It's recommended to provide business context via the --background flag for improved review quality. The --audience agent flag suppresses UI and outputs only the summary. ```bash ocr review --audience agent --background "business context here" [user-args] ``` -------------------------------- ### Copying GitLab CI Pipeline File Source: https://github.com/alibaba/open-code-review/blob/main/examples/gitlab_ci/README.md Demonstrates how to copy the OpenCodeReview GitLab CI pipeline configuration file to your project's repository. ```bash cp .gitlab-ci.yml /path/to/your/repo/.gitlab-ci.yml ``` -------------------------------- ### Run Development Scripts Source: https://github.com/alibaba/open-code-review/blob/main/extensions/vscode/README.md Available scripts for development builds, testing, linting, and packaging the VS Code extension. ```bash yarn compile yarn watch yarn build yarn test yarn lint yarn package ``` -------------------------------- ### Configure Telemetry Settings Source: https://github.com/alibaba/open-code-review/blob/main/README.md Use these commands to enable and configure OpenTelemetry integration for observability. Set the exporter to 'otlp' and specify the endpoint. ```bash ocr config set telemetry.enabled true ocr config set telemetry.exporter otlp ocr config set telemetry.otlp_endpoint localhost:4317 ``` -------------------------------- ### Perform OCR Review with Default Settings Source: https://github.com/alibaba/open-code-review/blob/main/README.md Initiate a code review of your workspace changes using the default configuration. ```bash ocr review ``` -------------------------------- ### Perform Code Review (Workspace Mode) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Reviews all staged, unstaged, and untracked changes in the current project directory. ```bash cd your-project # Workspace mode — review all staged, unstaged, and untracked changes ocr review ``` -------------------------------- ### Including GitLab CI Pipeline File Source: https://github.com/alibaba/open-code-review/blob/main/examples/gitlab_ci/README.md Shows how to include the OpenCodeReview GitLab CI pipeline configuration using GitLab's `include` feature in an existing `.gitlab-ci.yml` file. ```yaml include: - local: 'ci_demo/gitlab_ci/.gitlab-ci.yml' ``` -------------------------------- ### Preview Files to be Reviewed Source: https://github.com/alibaba/open-code-review/blob/main/skills/open-code-review/SKILL.md Performs a dry-run to preview which files would be reviewed without invoking the LLM. Use the --preview flag. ```bash ocr review --preview ``` -------------------------------- ### Package Release (.vsix) Source: https://github.com/alibaba/open-code-review/blob/main/extensions/vscode/README.md This command builds a release package (.vsix) for the extension. It first triggers a production build, then excludes unnecessary files, and finally produces the .vsix file in the current directory. The packaging tool used is @vscode/vsce. ```bash yarn package # = vsce package --no-yarn ``` -------------------------------- ### Code Quality Checks Source: https://github.com/alibaba/open-code-review/blob/main/CONTRIBUTING.md Run these commands to ensure code quality, format the code, lint, and test the project. These checks should pass before submitting changes. ```bash # Format and lint (Go standard tooling) go fmt ./... go vet ./... # Run tests with race detection make test # Build successfully make build ``` -------------------------------- ### Preview Rule Application Source: https://github.com/alibaba/open-code-review/blob/main/plugins/open-code-review/skills/open-code-review/SKILL.md Checks which rule applies to a specific file before initiating a review. Ensure the file path is correct. ```bash ocr rules check src/main/java/com/example/Foo.java ``` -------------------------------- ### Preview Files for OCR Review Source: https://github.com/alibaba/open-code-review/blob/main/README.md Before performing a full review, preview which files will be analyzed without making any LLM calls. This is useful for understanding the scope of the review. ```bash ocr review --preview ocr review -c abc123 -p ``` -------------------------------- ### Secure OCR Viewer with Host Header Allowlist Source: https://github.com/alibaba/open-code-review/blob/main/README.md Configure the OCR viewer to serve session data securely by enforcing a Host-header allowlist. This prevents DNS-rebinding attacks. Non-loopback hostnames must be added via the OCR_VIEWER_ALLOWED_HOSTS environment variable. ```bash OCR_VIEWER_ALLOWED_HOSTS=review.internal,ocr.lan ocr viewer --addr :3000 ``` -------------------------------- ### Review Branch Comparison Source: https://github.com/alibaba/open-code-review/blob/main/skills/open-code-review/SKILL.md Compares two branches (e.g., 'main' and a feature branch) for code review. Provide business context with -b and use --audience agent for agent-only output. ```bash ocr review --audience agent -b "context" --from main --to ``` -------------------------------- ### Test LLM Connectivity Source: https://github.com/alibaba/open-code-review/blob/main/README.md Runs a test to verify that the configured LLM is reachable and responsive. ```bash ocr llm test ``` -------------------------------- ### Configure LLM Auth Header (Anthropic) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Sets the HTTP header for the API key when using Anthropic. Defaults to 'authorization', but should be 'x-api-key' for standard keys. ```bash ocr config set llm.auth_header x-api-key ``` -------------------------------- ### Review Working Copy Changes Source: https://github.com/alibaba/open-code-review/blob/main/skills/open-code-review/SKILL.md Reviews staged, unstaged, and untracked changes in the working directory. Use the -b flag for business context and --audience agent for agent-only output. ```bash ocr review --audience agent -b "context" ``` -------------------------------- ### Configure LLM using Environment Variables Source: https://github.com/alibaba/open-code-review/blob/main/skills/open-code-review/SKILL.md Sets environment variables for LLM configuration, including URL, token, model, and Anthropic usage. This method has the highest priority and is recommended for CI environments. ```bash export OCR_LLM_URL=https://api.anthropic.com/v1/messages export OCR_LLM_TOKEN= export OCR_LLM_MODEL=claude-opus-4-6 export OCR_USE_ANTHROPIC=true ``` -------------------------------- ### Configure LLM via Environment Variables Source: https://github.com/alibaba/open-code-review/blob/main/README.md Sets LLM configuration using environment variables, which take the highest priority. Also compatible with Claude Code environment variables. ```bash export OCR_LLM_URL=https://api.anthropic.com/v1/messages export OCR_LLM_TOKEN=your-api-key-here export OCR_LLM_MODEL=claude-opus-4-6 export OCR_USE_ANTHROPIC=true ``` -------------------------------- ### Custom Rule File Format Source: https://github.com/alibaba/open-code-review/blob/main/plugins/open-code-review/skills/open-code-review/SKILL.md Defines project-specific rules for code review. Use glob patterns for file paths and descriptive strings for rules. ```json { "rules": [ { "path": "**/*.java", "rule": "All new methods must validate required parameters for null" }, { "path": "**/*mapper*.xml", "rule": "Check SQL for injection risks and missing closing tags" } ] } ``` -------------------------------- ### Configure Retry and Delay Settings Source: https://github.com/alibaba/open-code-review/blob/main/examples/github_actions/README.md Adjust repository variables like `OCR_RETRY_BASE_DELAY`, `OCR_RETRY_MAX_DELAY`, and `OCR_MAX_RETRIES` to fine-tune the rate-limit handling and retry behavior when posting review comments individually. ```yaml # Example of setting variables in GitHub Actions workflow (not directly in code snippet, but relevant context) # These are configured in repository settings -> Actions -> Variables ``` -------------------------------- ### Provide Requirement Context for OCR Review Source: https://github.com/alibaba/open-code-review/blob/main/README.md Enhance review targeting by providing background context or requirements for the changes being reviewed. ```bash ocr review --background "Adding rate limiting to the login API" ``` -------------------------------- ### Select or Override Model for OCR Review Source: https://github.com/alibaba/open-code-review/blob/main/README.md Specify a particular LLM model for the review, either generally or for a specific commit. ```bash ocr review --model claude-opus-4-6 ocr review --commit abc123 --model claude-sonnet-4-6 ``` -------------------------------- ### Configure LLM Manually Source: https://github.com/alibaba/open-code-review/blob/main/README.md Sets LLM configuration parameters directly via the CLI. Configuration is stored in ~/.opencodereview/config.json. ```bash ocr config set llm.url https://api.anthropic.com/v1/messages ocr config set llm.auth_token your-api-key-here ocr config set llm.model claude-opus-4-6 ocr config set llm.use_anthropic true ``` -------------------------------- ### Check Rule Application to a File Source: https://github.com/alibaba/open-code-review/blob/main/README.md Verify which custom review rule would apply to a specific file, or check a file against a specified rule. ```bash ocr rules check src/main/java/com/example/Foo.java ocr rules check --rule custom.json src/main/resources/mapper/UserMapper.xml ``` -------------------------------- ### Perform Code Review (Branch Range) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Compares two Git references (branches or tags) and reviews the changes between them. ```bash # Branch range — compare two refs ocr review --from main --to feature-branch ``` -------------------------------- ### Add Custom Review Rules Source: https://github.com/alibaba/open-code-review/blob/main/examples/github_actions/README.md Use the `--rule` flag with the `ocr review` command to specify a custom JSON file containing your review rules. This allows for tailored code analysis. ```yaml - name: Run OCR review run: ocr review --rule ./my-rules.json --from origin/${{ github.base_ref }} --to origin/${{ github.head_ref }} ``` -------------------------------- ### Configure LLM using Persistent Config Source: https://github.com/alibaba/open-code-review/blob/main/skills/open-code-review/SKILL.md Sets LLM configuration persistently using the 'ocr config set' command. This includes URL, authentication token, model, and Anthropic usage. ```bash ocr config set llm.url https://api.anthropic.com/v1/messages ocr config set llm.auth_token ocr config set llm.model claude-opus-4-6 ocr config set llm.use_anthropic true ``` -------------------------------- ### Review Working Copy Source: https://github.com/alibaba/open-code-review/blob/main/plugins/open-code-review/skills/open-code-review/SKILL.md Use this command to review staged, unstaged, and untracked changes in your working directory. The -b flag is used for providing business context. ```bash ocr review --audience agent -b "context" ``` -------------------------------- ### Review Specific Commit with Verbose JSON Output Source: https://github.com/alibaba/open-code-review/blob/main/README.md Perform a review on a specific commit, outputting the results in verbose JSON format and targeting an agent audience. ```bash ocr review --commit abc123 --format json --audience agent ``` -------------------------------- ### Rule File with Path Filtering Source: https://github.com/alibaba/open-code-review/blob/main/README.md Includes rules along with 'include' and 'exclude' fields to control which files are considered for review. 'Exclude' patterns take precedence over 'include'. ```json { "rules": [ {"path": "**/*.java", "rule": "Check for null safety"} ], "include": ["src/main/**/*.java", "lib/**/*.kt"], "exclude": ["**/generated/**", "vendor/**"] } ``` -------------------------------- ### Add Custom Review Rules Source: https://github.com/alibaba/open-code-review/blob/main/examples/gitlab_ci/README.md Execute OCR review with a custom rules JSON file. Ensure the rules file is accessible within the CI environment. ```yaml script: - ocr review --rule ./my-rules.json --from origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME --to $CI_COMMIT_SHA ``` -------------------------------- ### Copy OCR Command File for Claude Code (Project-level) Source: https://github.com/alibaba/open-code-review/blob/main/README.md Command to copy the OCR command file to a project's .claude/commands directory for team-wide use. ```bash mkdir -p .claude/commands curl -o .claude/commands/open-code-review.md \ https://raw.githubusercontent.com/alibaba/open-code-review/main/plugins/open-code-review/commands/review.md ``` -------------------------------- ### Provide Background Context for Review Source: https://github.com/alibaba/open-code-review/blob/main/examples/github_actions/README.md Use the `--background` flag with the `ocr review` command to pass additional context, such as the PR title, to help OCR better understand the changes and provide more relevant comments. ```yaml - name: Run OCR review run: ocr review --background "${{ github.event.pull_request.title }}" --from origin/${{ github.base_ref }} --to origin/${{ github.head_ref }} ``` -------------------------------- ### Proper malloc/free Pairing in C Source: https://github.com/alibaba/open-code-review/blob/main/internal/config/rules/rule_docs/c.md Ensure every allocated memory block using malloc is freed using free. Set the pointer to NULL after freeing to prevent double-freeing. ```c // Bad char* buffer = malloc(1024); // use buffer... // forgot to free memory // Good char* buffer = malloc(1024); if (buffer != NULL) { // use buffer... free(buffer); buffer = NULL; } ```