home / skills / google-gemini / gemini-cli / code-reviewer

code-reviewer skill

/.gemini/skills/code-reviewer

This skill guides you through professional code reviews, targeting local changes or remote PRs to improve correctness and maintainability.

npx playbooks add skill google-gemini/gemini-cli --skill code-reviewer

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.1 KB
---
name: code-reviewer
description:
  Use this skill to review code. It supports both local changes (staged or working tree)
  and remote Pull Requests (by ID or URL). It focuses on correctness, maintainability,
  and adherence to project standards.
---

# Code Reviewer

This skill guides the agent in conducting professional and thorough code reviews for both local development and remote Pull Requests.

## Workflow

### 1. Determine Review Target
*   **Remote PR**: If the user provides a PR number or URL (e.g., "Review PR #123"), target that remote PR.
*   **Local Changes**: If no specific PR is mentioned, or if the user asks to "review my changes", target the current local file system states (staged and unstaged changes).

### 2. Preparation

#### For Remote PRs:
1.  **Checkout**: Use the GitHub CLI to checkout the PR.
    ```bash
    gh pr checkout <PR_NUMBER>
    ```
2.  **Preflight**: Execute the project's standard verification suite to catch automated failures early.
    ```bash
    npm run preflight
    ```
3.  **Context**: Read the PR description and any existing comments to understand the goal and history.

#### For Local Changes:
1.  **Identify Changes**:
    *   Check status: `git status`
    *   Read diffs: `git diff` (working tree) and/or `git diff --staged` (staged).
2.  **Preflight (Optional)**: If the changes are substantial, ask the user if they want to run `npm run preflight` before reviewing.

### 3. In-Depth Analysis
Analyze the code changes based on the following pillars:

*   **Correctness**: Does the code achieve its stated purpose without bugs or logical errors?
*   **Maintainability**: Is the code clean, well-structured, and easy to understand and modify in the future? Consider factors like code clarity, modularity, and adherence to established design patterns.
*   **Readability**: Is the code well-commented (where necessary) and consistently formatted according to our project's coding style guidelines?
*   **Efficiency**: Are there any obvious performance bottlenecks or resource inefficiencies introduced by the changes?
*   **Security**: Are there any potential security vulnerabilities or insecure coding practices?
*   **Edge Cases and Error Handling**: Does the code appropriately handle edge cases and potential errors?
*   **Testability**: Is the new or modified code adequately covered by tests (even if preflight checks pass)? Suggest additional test cases that would improve coverage or robustness.

### 4. Provide Feedback

#### Structure
*   **Summary**: A high-level overview of the review.
*   **Findings**:
    *   **Critical**: Bugs, security issues, or breaking changes.
    *   **Improvements**: Suggestions for better code quality or performance.
    *   **Nitpicks**: Formatting or minor style issues (optional).
*   **Conclusion**: Clear recommendation (Approved / Request Changes).

#### Tone
*   Be constructive, professional, and friendly.
*   Explain *why* a change is requested.
*   For approvals, acknowledge the specific value of the contribution.

### 5. Cleanup (Remote PRs only)
*   After the review, ask the user if they want to switch back to the default branch (e.g., `main` or `master`).

Overview

This skill reviews code changes for both local development and remote Pull Requests. It focuses on correctness, maintainability, readability, efficiency, security, edge cases, and testability. The goal is actionable feedback framed as summary, findings (critical, improvements, nitpicks), and a clear recommendation.

How this skill works

For remote PRs, the skill checks out the PR (via GitHub CLI), runs the project's preflight suite, and reads the PR description and comments for context. For local changes, it inspects the working tree and staged diffs, optionally prompting to run preflight checks. It then analyzes changes against core review pillars and returns a structured report with suggested fixes and test recommendations.

When to use it

  • Review a remote Pull Request by number or URL.
  • Review local staged or unstaged changes before committing.
  • Get a focused audit for correctness, security, or performance concerns.
  • Prepare feedback before merging a feature branch.
  • Validate that tests and edge-case handling are sufficient.

Best practices

  • Provide the PR number or URL to target a remote review explicitly.
  • Run the project’s preflight/test suite when reviewing substantial changes.
  • Share any project-specific style or architecture guidelines up front.
  • Limit reviews to a single concern set (e.g., bugfix, refactor) per run for clarity.
  • Ask for missing context (design decisions, intended behavior) before making major suggestions.

Example use cases

  • "Review PR #123" — checkout PR, run preflight, and produce a structured review.
  • "Review my working changes" — inspect git diff and staged files, then report issues to fix before commit.
  • Security check — focus the review on potential vulnerabilities and insecure patterns.
  • Performance audit — identify obvious bottlenecks and suggest optimizations.
  • Test coverage recommendations — propose unit or integration tests for uncovered edge cases.

FAQ

Can you review both staged and unstaged changes?

Yes. By default the skill inspects the working tree and staged changes; it can focus only on staged files if requested.

Do you run tests automatically for remote PRs?

For remote PRs the skill runs the project’s standard preflight/test script (e.g., npm run preflight) to surface automated failures before manual review.