Perform deep, thorough code review using Gemini AI. Use this Skill when user explicitly requests 'gemini review', 'thorough review', 'detailed review', or 'deep review'. Default reviewer for code reviews per CLAUDE.md preferences.
Resources
2Install
npx skillscat add tomwangowa/agent-skills/code-review-gemini Install via the SkillsCat registry.
Code Review with Gemini
Purpose
This Skill performs a structured code review on staged changes by:
- Collecting the git diff of staged changes (
git diff --cached) - Running an external review script that invokes the Gemini CLI
- Summarizing the findings in a clear, prioritized manner
The Skill is designed to be deterministic, auditable, and suitable for pre-commit workflows.
Instructions
When the user expresses intent to review staged changes (for example: reviewing staged files, checking code before commit, or analyzing changes about to be committed), follow the steps below strictly.
Please note that do not specify the gemini model in the instructions, as it will be handled in the script.
Execution steps
Determine the skill base directory from the skill invocation context (provided when the skill is loaded).
Run the script from the skill directory:
<skill_base_directory>/scripts/review_with_gemini.sh.For example, if the skill base directory is
/Users/tom_wang/.claude/skills/code-review-gemini,
the full path should be/Users/tom_wang/.claude/skills/code-review-gemini/scripts/review_with_gemini.sh.Important: Always use the full absolute path to the script, not a relative path, since the current
working directory may be the user's project directory, not the skill directory.Observe the script output carefully.
The script will first print a "Review Scope" section that includes:- Current branch name
- Review target (Staged changes)
- List of staged files
Before summarizing the review, pay close attention to the "Review Scope" section and ensure that all findings align strictly with the listed staged files.
- If a finding does not clearly map to a file in the review scope, treat it as low confidence.
- Do not introduce issues, suggestions, or risks that are unrelated to the displayed diff.
- Avoid speculative or generalized advice that cannot be justified by the reviewed changes.
After verifying alignment with the review scope, summarize the Gemini review results for the user.
Output requirements
Your final response should be structured and concise, and must include:
High priority issues
Issues that may cause bugs, security risks, crashes, or data loss.Medium priority concerns
Design issues, maintainability problems, or potential performance risks.Low priority or stylistic suggestions
Readability, naming, formatting, or minor best-practice improvements.Actionable next steps
Concrete recommendations that the developer can realistically act on.Adversarial findings (tagged
[ADVERSARIAL])
Issues discovered through active probing — edge-case inputs, unvalidated assumptions, tests that don't actually verify what they claim.Assumptions identified
Implicit assumptions the code makes but does not validate (e.g., input shape, ordering, environment state, "this path won't be reached").
Do not repeat the full raw Gemini output verbatim unless explicitly asked.
Your role is to act as a senior reviewer who filters, validates, and prioritizes the findings.
Constraints
- Only review code that appears in the provided diff.
- Do not assume project architecture or conventions beyond what is visible in the changes.
- Do not suggest large-scale refactors unless a clear, high-risk issue justifies it.
- Prefer correctness and clarity over exhaustive commentary.
Examples
User:
Review the staged files before I commit.
Expected behavior:
- Run
review_with_gemini.sh - Read the "Review Scope" section
- Validate that review findings match the staged files
- Respond with a prioritized, scoped code review summary
User:
Check the code quality of my staged changes.
Expected behavior:
- Same workflow as above
- Emphasize correctness and risk-related issues first
Workflow
Step 1: Collect Staged Changes
- Run
scripts/review_with_gemini.sh - Script executes
git diff --cachedto get staged changes - Script displays "Review Scope" with branch name and staged files
Step 2: Review Analysis
- Script sends diff to Gemini CLI for analysis
- Gemini reviews code for:
- Security vulnerabilities (XSS, injection, auth issues)
- Logic errors and potential bugs
- Performance concerns
- Code quality and maintainability
- Best practice violations
Step 2.5: Adversarial Review Pass
After receiving Gemini's analysis, actively probe the diff with these four questions:
"What input breaks this?"
For each function or branch in the diff, construct at least one concrete input that could cause unexpected behavior (nil, empty, overflow, concurrent, malformed). If no such input exists, state why."What does this assume that is not validated?"
List every implicit assumption: input types, ordering guarantees, environment variables present, upstream behavior, "this error won't happen". Each is a finding unless explicitly validated in code."Does the test actually test the claim?" (Mirror Test)
For every test in the diff, check whether deleting the implementation would still let the test pass. A test that passes regardless of the code under test is a tautology, not verification. Specific checks:- Is the assertion on the return value / side effect of the code under test, or on a mock/stub?
- Would replacing the function body with
return null/return []/passcause the test to fail? - Does the test assert on behavior, or merely on the absence of errors?
"Is this a fix or a suppression?"
Check whether the change addresses the root cause or merely silences a symptom (e.g., catching and swallowing errors, adding|| defaultto mask nil,@SuppressWarnings,# type: ignore).
Tagging rule: Any issue discovered through this pass is tagged [ADVERSARIAL] in the output. These findings stand alongside (not below) the standard priority categories.
Step 3: Validate Findings
- Read the "Review Scope" section
- Verify all findings map to staged files
- Filter out speculative or unrelated suggestions
- Treat unmapped findings as low confidence
Step 4: Prioritize and Summarize
- Categorize by severity: High, Medium, Low
- Focus on actionable items
- Provide specific line numbers and file references
- Suggest concrete fixes
Step 5: Present Results
- High priority issues first (security, bugs, crashes)
- Medium priority concerns (design, performance)
- Low priority suggestions (style, naming)
- Adversarial findings (
[ADVERSARIAL]tagged, grouped separately) - Assumptions list (implicit assumptions the code does not validate)
- Actionable next steps
Security Considerations
Input Handling
Git Diff Content
- The diff is sourced from local git repository (trusted source)
- No user input directly injected into commands
- Diff size is limited by MAX_DIFF_LINES environment variable (default: 5000)
Script Execution Safety
- review_with_gemini.sh validates environment before execution
- Checks for required tools (git, Gemini CLI)
- Uses
set -euo pipefailfor proper error handling - No arbitrary command execution from user input
Gemini API Security
- Requires valid API key (GEMINI_API_KEY environment variable)
- API calls are made over HTTPS
- No sensitive code should be in diff (user responsibility)
- Review results are saved locally only
Sensitive Information Handling
Code Content
- Warn users not to commit secrets, API keys, passwords in code
- Review process may expose sensitive logic to Gemini API
- Users should be aware code is sent to external AI service
- Consider using
.gitignorefor sensitive files
Review Results
- Saved to local file:
gemini_review_result.txt - Contains code snippets from diff
- Should not be committed to git (add to .gitignore)
- May contain security findings that should be handled carefully
- Saved to local file:
External Dependencies
Gemini CLI
- Official Google tool, regularly updated
- Requires API key for authentication
- Network connectivity required
- API quota limits apply
Git
- Standard version control tool
- Trusted system dependency
- No remote operations performed
Error Handling
Pre-execution Validation
Git Repository Check
- Error if not in a git repository
- Message: "Not a git repository. Please run from within a git project."
- Action: Change directory to git project root
Staged Changes Check
- Error if no staged changes found
- Message: "No staged changes found. Use 'git add' to stage files first."
- Action: User should stage files with
git add
Gemini CLI Check
- Error if Gemini CLI not installed
- Message: "Gemini CLI not found. Install: npm install -g @google/gemini-cli"
- Provide installation link: https://www.npmjs.com/package/@google/gemini-cli
API Key Check
- Error if GEMINI_API_KEY not set
- Message: "GEMINI_API_KEY environment variable not set. Please configure your API key."
- Action: Guide user to set environment variable
Execution Errors
Diff Too Large
- If diff exceeds MAX_DIFF_LINES (default: 5000)
- Warning: "Diff is too large (X lines). Only first 5000 lines will be reviewed."
- Action: Review proceeds with truncated diff
- Recommendation: "Consider reviewing in smaller commits"
Gemini API Failures
- Network timeout or API errors
- Error: "Gemini API request failed: [error details]"
- Action: Check network connection and API key
- Fallback: Suggest manual review or retry
Script Execution Failures
- If review_with_gemini.sh fails
- Capture stderr output
- Display error to user with context
- Provide troubleshooting steps
Output Handling
Empty Review Results
- If Gemini returns no findings
- Message: "No issues found in the staged changes. Code looks good!"
- Clarify: This doesn't guarantee bug-free code, just no obvious issues detected
Malformed Output
- If review result file is corrupted or empty
- Error: "Failed to parse review results. Please try again."
- Action: Check gemini_review_result.txt for details
File Write Errors
- If cannot write gemini_review_result.txt
- Error: "Cannot write to output file. Check disk space and permissions."
- Action: Verify write permissions in current directory
Graceful Degradation
When Gemini CLI is unavailable:
- Inform user that external AI review is not available
- Suggest alternatives: manual review, code-review-assistant (if exists)
- Do not fail the commit workflow (review is advisory, not blocking)
Additional Examples
Example 3: Security-focused review
User: "Review my authentication code for security issues"
Expected behavior:
- Run review_with_gemini.sh
- Focus on security aspects in the summary
- Highlight: SQL injection, XSS, auth bypass, token handling
- Provide security-specific recommendationsExample 4: Performance review
User: "Check if my changes have performance issues"
Expected behavior:
- Run review_with_gemini.sh
- Emphasize performance concerns in summary
- Identify: N+1 queries, memory leaks, inefficient algorithms
- Suggest optimizations with benchmarksExample 5: Before major refactoring
User: "I'm about to refactor the database layer, review the changes"
Expected behavior:
- Run review_with_gemini.sh on staged refactoring
- Check for: breaking changes, data migration needs, backward compatibility
- Validate: test coverage, error handling, rollback strategy
- Confirm architectural alignment