second-opinion by trailofbits/skills
npx skills add https://github.com/trailofbits/skills --skill second-opinion通过外部 LLM 命令行工具,借助独立模型进行代码审查。支持 OpenAI Codex CLI 和 Google Gemini CLI。
Gemini CLI 通过 --yolo 参数调用,该参数会自动批准所有工具调用而无需确认。这对于无头(非交互式)操作是必需的,但也意味着 Gemini 将执行其扩展请求的任何工具操作,而不会提示用户。
# Codex (无头执行,输出结构化 JSON)
codex exec --sandbox read-only --ephemeral \
--output-schema codex-review-schema.json \
-o "$output_file" - < "$prompt_file"
# Gemini (代码审查扩展)
gemini -p "/code-review" --yolo -e code-review
# Gemini (无头模式,带差异 — 完整模式见 references/)
git diff HEAD > /tmp/review-diff.txt
{ printf '%s\n\n' 'Review this diff for issues.'; cat /tmp/review-diff.txt; } \
| gemini -p - --yolo -m gemini-3.1-pro-preview
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
使用 AskUserQuestion 一次性收集审查参数。根据用户在调用时已提供的信息调整问题(跳过他们已经回答的问题)。
将所有适用的问题合并到一次 AskUserQuestion 调用中(最多 4 个问题)。
问题 1 — 工具(如果用户已指定则跳过):
header: "审查工具"
question: "应该使用哪个工具运行审查?"
options:
- "同时使用 Codex 和 Gemini (推荐)" → 并行运行两者
- "仅使用 Codex" → codex exec
- "仅使用 Gemini" → gemini CLI
问题 2 — 范围(如果用户已指定则跳过):
header: "审查范围"
question: "应该审查什么内容?"
options:
- "未提交的更改" → git diff HEAD + 未跟踪文件
- "与主分支的差异" → git diff <branch>...HEAD (自动检测默认分支)
- "特定提交" → git diff <sha>~1..<sha> (后续询问 SHA)
问题 3 — 项目上下文(如果仓库根目录中既不存在 CLAUDE.md 也不存在 AGENTS.md,则跳过):
首先检查仓库根目录是否存在 CLAUDE.md,然后是 AGENTS.md。只有当至少一个文件存在时才显示此问题。
header: "项目上下文"
question: "是否包含项目规范文件,以便审查能依据您的标准进行检查?"
options:
- "是,包含它"
- "否,进行标准审查"
问题 4 — 审查重点(始终询问):
header: "审查重点"
question: "审查是否有任何特定的关注领域?"
options:
- "常规审查" → 无自定义提示
- "安全与认证" → 关注安全的提示
- "性能" → 关注性能的提示
- "错误处理" → 关注错误处理的提示
不要预先检查工具可用性。立即运行选定的工具。如果命令因“command not found”或缺少扩展而失败,请报告下方错误处理表中的安装命令并跳过该工具(如果选择了“Both”,则仅运行可用的那个)。
收集答案后,显示差异统计信息:
# 对于未提交的更改(已跟踪 + 未跟踪):
git diff --stat HEAD
git ls-files --others --exclude-standard
# 对于分支差异:
git diff --stat <branch>...HEAD
# 对于特定提交:
git diff --stat <sha>~1..<sha>
如果差异为空,则停止并告知用户。
如果差异非常大(>2000 行更改),警告用户并询问是继续还是缩小范围。
确定差异范围后,跳过实际上未更改的文件所对应的检查。
仅当差异涉及依赖项清单文件时才运行 /security:scan-deps。使用以下命令检查:
git diff --name-only <scope> \
| grep -qiE '(package\.json|package-lock|yarn\.lock|pnpm-lock|Gemfile|\.gemspec|requirements\.txt|setup\.py|setup\.cfg|pyproject\.toml|poetry\.lock|uv\.lock|Cargo\.toml|Cargo\.lock|go\.mod|go\.sum|composer\.json|composer\.lock|Pipfile)'
如果差异中没有依赖项文件,即使选择了安全重点,也跳过扫描。该扫描会分析整个项目的依赖关系树,与差异范围无关,因此当依赖项未被修改时,它会增加大量时间而毫无价值。
对于分支差异范围,检测默认分支名称:
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null \
| sed 's@^refs/remotes/origin/@@' || echo main
有关命令语法、提示词组装和结构化输出模式的完整详细信息,请参阅 references/codex-invocation.md。
摘要:
codex exec(而非 codex review)进行无头操作gpt-5.3-codex,推理级别:xhigh--output-schema 产生结构化的 JSON 发现结果-o 仅捕获最终消息(无思考/执行噪音)gpt-5.2-codextimeout: 600000有关标志、范围映射和扩展用法的完整详细信息,请参阅 references/gemini-invocation.md。
摘要:
gemini-3.1-pro-preview,标志:--yolo,-e,-mgemini -p "/code-review" --yolo -e code-reviewgit diff 管道传输到 gemini -pgemini-cli-security(不是 security)/security:analyze 仅支持交互式 — 改用带有安全提示词的 -p/security:scan-deps(参见差异感知优化)timeout: 600000git diff 的范围映射(Gemini 没有内置的范围标志):
| 范围 | 差异命令 |
|---|---|
| 未提交 | git diff HEAD + 未跟踪文件(参见 codex-invocation.md) |
| 分支差异 | git diff <branch>...HEAD |
| 特定提交 | git diff <sha>~1..<sha> |
当用户选择“Both”(默认选项)时:
## Codex 审查 (gpt-5.3-codex)
<codex 输出>
## Gemini 审查 (gemini-3.1-pro-preview)
<gemini 输出>
总结两次审查一致和不同的地方。| 错误 | 操作 |
|---|---|
codex: command not found | 告知用户:npm i -g @openai/codex |
gemini: command not found | 告知用户:npm i -g @google/gemini-cli |
Gemini code-review 扩展缺失 | 告知用户:gemini extensions install https://github.com/gemini-cli-extensions/code-review |
Gemini gemini-cli-security 扩展缺失 | 告知用户:gemini extensions install https://github.com/gemini-cli-extensions/security |
| 模型身份验证错误 (Codex) | 使用 gpt-5.2-codex 重试 |
| 差异为空 | 告知用户没有可审查的更改 |
| 超时 | 通知用户并建议缩小差异范围 |
| 工具部分不可用 | 仅运行可用的工具,注明跳过的部分 |
两个工具(默认):
用户:/second-opinion
Claude:[询问 4 个问题:工具、范围、上下文、重点]
用户:选择 "Both"、"Branch diff"、"Yes include CLAUDE.md"、"Security"
Claude:[检测默认分支 = main]
Claude:[显示 diff --stat: 6 个文件,+103 -15]
Claude:[组装提示词,包含审查指令 + CLAUDE.md + 安全重点 + 差异]
Claude:[并行运行 codex exec 和 gemini]
Claude:[读取 codex 输出文件,解析结构化发现结果]
Claude:[呈现两次审查,突出显示一致/差异之处]
仅使用 Codex 并带有内联参数:
用户:/second-opinion check uncommitted changes for bugs
Claude:[已知范围:未提交,已知重点:自定义]
Claude:[询问 2 个问题:工具、项目上下文]
用户:选择 "Codex only"、"No context"
Claude:[显示 diff --stat: 3 个文件,+45 -10]
Claude:[编写包含审查指令 + 差异的提示词文件]
Claude:[运行 codex exec,读取结构化 JSON 输出]
Claude:[按优先级呈现发现结果,附带 file:line 引用]
仅使用 Gemini:
用户:/second-opinion
Claude:[询问 4 个问题]
用户:选择 "Gemini only"、"Uncommitted"、"No"、"General"
Claude:[显示 diff --stat: 2 个文件,+20 -5]
Claude:[运行 gemini -p "/code-review" --yolo -e code-review]
Claude:[呈现审查结果]
大差异警告:
用户:/second-opinion
Claude:[询问问题] → 用户选择 "Both"、"Uncommitted"、"General"
Claude:[显示 diff --stat: 45 个文件,+3200 -890]
Claude:"差异很大(3200+ 行)。继续,还是缩小范围?"
用户:"proceed"
Claude:[运行两次审查]
每周安装量
733
仓库
GitHub 星标数
3.9K
首次出现
2026年2月10日
安全审计
安装于
opencode658
codex655
claude-code652
gemini-cli646
github-copilot635
cursor634
Shell out to external LLM CLIs for an independent code review powered by a separate model. Supports OpenAI Codex CLI and Google Gemini CLI.
Gemini CLI is invoked with --yolo, which auto-approves all tool calls without confirmation. This is required for headless (non-interactive) operation but means Gemini will execute any tool actions its extensions request without prompting.
# Codex (headless exec with structured JSON output)
codex exec --sandbox read-only --ephemeral \
--output-schema codex-review-schema.json \
-o "$output_file" - < "$prompt_file"
# Gemini (code review extension)
gemini -p "/code-review" --yolo -e code-review
# Gemini (headless with diff — see references/ for full pattern)
git diff HEAD > /tmp/review-diff.txt
{ printf '%s\n\n' 'Review this diff for issues.'; cat /tmp/review-diff.txt; } \
| gemini -p - --yolo -m gemini-3.1-pro-preview
Use AskUserQuestion to collect review parameters in one shot. Adapt the questions based on what the user already provided in their invocation (skip questions they already answered).
Combine all applicable questions into a single AskUserQuestion call (max 4 questions).
Question 1 — Tool (skip if user already specified):
header: "Review tool"
question: "Which tool should run the review?"
options:
- "Both Codex and Gemini (Recommended)" → run both in parallel
- "Codex only" → codex exec
- "Gemini only" → gemini CLI
Question 2 — Scope (skip if user already specified):
header: "Review scope"
question: "What should be reviewed?"
options:
- "Uncommitted changes" → git diff HEAD + untracked files
- "Branch diff vs main" → git diff <branch>...HEAD (auto-detect default branch)
- "Specific commit" → git diff <sha>~1..<sha> (follow up for SHA)
Question 3 — Project context (skip if neither CLAUDE.md nor AGENTS.md exists):
Check for CLAUDE.md first, then AGENTS.md in the repo root. Only show this question if at least one exists.
header: "Project context"
question: "Include project conventions file so the review
checks against your standards?"
options:
- "Yes, include it"
- "No, standard review"
Question 4 — Review focus (always ask):
header: "Review focus"
question: "Any specific focus areas for the review?"
options:
- "General review" → no custom prompt
- "Security & auth" → security-focused prompt
- "Performance" → performance-focused prompt
- "Error handling" → error handling-focused prompt
Do not pre-check tool availability. Run the selected tool immediately. If the command fails with "command not found" or an extension is missing, report the install command from the Error Handling table below and skip that tool (if "Both" was selected, run only the available one).
After collecting answers, show the diff stats:
# For uncommitted (tracked + untracked):
git diff --stat HEAD
git ls-files --others --exclude-standard
# For branch diff:
git diff --stat <branch>...HEAD
# For specific commit:
git diff --stat <sha>~1..<sha>
If the diff is empty, stop and tell the user.
If the diff is very large (>2000 lines changed), warn the user and ask whether to proceed or narrow the scope.
After determining the diff scope, skip checks that don't apply to the files actually changed.
Only run /security:scan-deps when the diff touches dependency manifest files. Check with:
git diff --name-only <scope> \
| grep -qiE '(package\.json|package-lock|yarn\.lock|pnpm-lock|Gemfile|\.gemspec|requirements\.txt|setup\.py|setup\.cfg|pyproject\.toml|poetry\.lock|uv\.lock|Cargo\.toml|Cargo\.lock|go\.mod|go\.sum|composer\.json|composer\.lock|Pipfile)'
If no dependency files are in the diff, skip the scan even when security focus is selected. The scan analyzes the entire project's dependency tree regardless of diff scope, so it adds significant time for zero value when dependencies weren't touched.
For branch diff scope, detect the default branch name:
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null \
| sed 's@^refs/remotes/origin/@@' || echo main
See references/codex-invocation.md for full details on command syntax, prompt assembly, and the structured output schema.
Summary:
codex exec (not codex review) for headless operationgpt-5.3-codex, reasoning: xhigh--output-schema produces structured JSON findings-o captures only the final message (no thinking/exec noise)gpt-5.2-codex on auth errorstimeout: 600000 on the Bash callSee references/gemini-invocation.md for full details on flags, scope mapping, and extension usage.
Summary:
gemini-3.1-pro-preview, flags: --yolo, -e, -mgemini -p "/code-review" --yolo -e code-reviewgit diff into gemini -pgemini-cli-security (not security)/security:analyze is interactive-only — use with a security prompt insteadScope mapping forgit diff (Gemini has no built-in scope flags):
| Scope | Diff command |
|---|---|
| Uncommitted | git diff HEAD + untracked (see codex-invocation.md) |
| Branch diff | git diff <branch>...HEAD |
| Specific commit | git diff <sha>~1..<sha> |
When the user picks "Both" (the default):
## Codex Review (gpt-5.3-codex)
<codex output>
## Gemini Review (gemini-3.1-pro-preview)
<gemini output>
Summarize where the two reviews agree and differ.
| Error | Action |
|---|---|
codex: command not found | Tell user: npm i -g @openai/codex |
gemini: command not found | Tell user: npm i -g @google/gemini-cli |
Gemini code-review extension missing | Tell user: gemini extensions install https://github.com/gemini-cli-extensions/code-review |
Gemini gemini-cli-security extension missing |
Both tools (default):
User: /second-opinion
Claude: [asks 4 questions: tool, scope, context, focus]
User: picks "Both", "Branch diff", "Yes include CLAUDE.md", "Security"
Claude: [detects default branch = main]
Claude: [shows diff --stat: 6 files, +103 -15]
Claude: [assembles prompt with review instructions + CLAUDE.md + security focus + diff]
Claude: [runs codex exec and gemini in parallel]
Claude: [reads codex output file, parses structured findings]
Claude: [presents both reviews, highlights agreements/differences]
Codex only with inline args:
User: /second-opinion check uncommitted changes for bugs
Claude: [scope known: uncommitted, focus known: custom]
Claude: [asks 2 questions: tool, project context]
User: picks "Codex only", "No context"
Claude: [shows diff --stat: 3 files, +45 -10]
Claude: [writes prompt file with review instructions + diff]
Claude: [runs codex exec, reads structured JSON output]
Claude: [presents findings by priority with file:line refs]
Gemini only:
User: /second-opinion
Claude: [asks 4 questions]
User: picks "Gemini only", "Uncommitted", "No", "General"
Claude: [shows diff --stat: 2 files, +20 -5]
Claude: [runs gemini -p "/code-review" --yolo -e code-review]
Claude: [presents review]
Large diff warning:
User: /second-opinion
Claude: [asks questions] → user picks "Both", "Uncommitted", "General"
Claude: [shows diff --stat: 45 files, +3200 -890]
Claude: "Large diff (3200+ lines). Proceed, or narrow the scope?"
User: "proceed"
Claude: [runs both reviews]
Weekly Installs
733
Repository
GitHub Stars
3.9K
First Seen
Feb 10, 2026
Security Audits
Gen Agent Trust HubFailSocketFailSnykPass
Installed on
opencode658
codex655
claude-code652
gemini-cli646
github-copilot635
cursor634
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
103,800 周安装
-p/security:scan-deps only when security focus is selected AND the diff touches dependency manifest files (see Diff-Aware Optimizations)timeout: 600000 on the Bash callTell user: gemini extensions install https://github.com/gemini-cli-extensions/security |
| Model auth error (Codex) | Retry with gpt-5.2-codex |
| Empty diff | Tell user there are no changes to review |
| Timeout | Inform user and suggest narrowing the diff scope |
| Tool partially unavailable | Run only the available tool, note the skip |