code-review
Use when explicitly asked to review a git branch, Pull Request (PR), Merge Request (MR), or perform a pre-merge review. Do not use for inline code critiques.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when explicitly asked to review a git branch, Pull Request (PR), Merge Request (MR), or perform a pre-merge review. Do not use for inline code critiques.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when explicitly asked to critique code, find bugs, audit code quality, analyze performance, or review a specific code snippet for security issues. Do not use for full branch or PR reviews.
Auto-apply when the user asks for any git version control operations, including commit, push, pull, branch, merge, rebase, squash, reset, revert, cherry-pick, stash, tag, undo, amend, diff, log, or blame.
Auto-apply whenever reading, outputting, or sharing file contents that may contain sensitive data, including secrets, API keys, passwords, tokens, credentials, .env files, private keys, certificates, or PII. Enforces strict file-type allowlist and redacts sensitive data.
| name | code-review |
| description | Use when explicitly asked to review a git branch, Pull Request (PR), Merge Request (MR), or perform a pre-merge review. Do not use for inline code critiques. |
| license | MIT |
Perform comprehensive code reviews of a branch against the base branch, providing actionable feedback on code quality, security, performance, and best practices.
Activate this skill when:
Two Review Modes:
Current Branch Review (default when no branch specified)
Other Branch Review (when branch name specified)
If a branch name is provided (e.g., "review feature/payment"):
git fetch originIf no branch name is provided (e.g., just "review"):
git diff --cachedgit diffWhen reviewing a branch that isn't the current branch, use a git worktree to avoid disturbing the current working state:
Create a worktree directory at <repo-root>/.worktrees/<branch-name>:
git worktree add .worktrees/<branch-name> origin/<branch-name>
Perform all review operations within the worktree directory
After the review is complete, remove the worktree:
git worktree remove .worktrees/<branch-name>
Important: Always use the worktree path when reading files or running git commands during the review.
When setting up a worktree, install dependencies if you need to run checks (tests, type checking, linting):
Detect package manager: Check for pnpm-lock.yaml, Cargo.lock, go.mod
Install dependencies:
cd <worktree-path> && pnpm install
Run checks (optional, if needed for thorough review)
When to install dependencies:
When to skip dependency installation:
If the worktree already exists:
git worktree remove .worktrees/<branch-name> --force 2>/dev/null || true
git worktree add .worktrees/<branch-name> origin/<branch-name>
If no matching branch is found:
Always clean up worktrees:
git worktree list to verify cleanup was successfulThe .worktrees directory should be added to .gitignore.
First, gather essential information about the branch to review:
DEFAULT_BRANCH=""
for branch in main master; do
if git merge-base --is-ancestor origin/$branch HEAD 2>/dev/null; then
DEFAULT_BRANCH=$branch
break
fi
done
if [ -z "$DEFAULT_BRANCH" ]; then
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
fi
if [ -z "$DEFAULT_BRANCH" ]; then
if git show-ref --verify --quiet refs/remotes/origin/main; then
DEFAULT_BRANCH="main"
elif git show-ref --verify --quiet refs/remotes/origin/master; then
DEFAULT_BRANCH="master"
fi
fi
[ -z "$DEFAULT_BRANCH" ] && DEFAULT_BRANCH="main"
You MUST use git merge-base to find the common ancestor. This ensures you only review commits that were made in THIS branch.
MERGE_BASE=$(git merge-base origin/$DEFAULT_BRANCH HEAD)
git log --oneline $MERGE_BASE..HEAD
git diff --name-status $MERGE_BASE..HEAD
git diff $MERGE_BASE..HEAD
Why this matters:
git diff origin/main..HEAD shows ALL differences between main and HEAD, including changes from OTHER branchesgit diff $(git merge-base origin/main HEAD)..HEAD shows ONLY the changes introduced in THIS branchAlways use the merge-base approach for:
git log - to list commitsgit diff - to see changesgit diff --stat - for change statisticsgit diff --cached --name-status
git diff --cached --stat
git diff --name-status
git diff --stat
Do not review lock files. Filter them out:
pnpm-lock.yamlpackage-lock.jsonyarn.lockbun.lockbgo.sumCargo.lockpoetry.lockPipfile.lockpdm.lockGemfile.lockcomposer.lockdeno.lockflake.lockIf diff is very large, ask for confirmation before proceeding:
Current branch: Always run checks. Worktree: Ask the user before running checks.
Run the bundled check script. It auto-detects the project type (Nx, Rust, Go, Node.js) and runs the appropriate linters, formatters, and tests with a 5-minute timeout per check. Failures are reported but do not stop the review.
~/.copilot/skills/code-review/run-checks.sh "$MERGE_BASE" [WORKTREE_PATH]
Capture the output and include results in the review report.
Conduct a thorough review of only the changes introduced in this branch.
git diff $(git merge-base origin/$DEFAULT_BRANCH HEAD)..HEAD -- <file> to review each modified filegit show <commit-hash>Create a structured code review report with:
After completing the review:
Frame all feedback as questions, not commands.
❌ Don't write:
✅ Do write: