71 added, 69 removed. Audit A to A.
---
name: code-investigate
description: Dual-perspective code investigation. Claude explores independently, then Codex explores independently (no feeding), finally integrate both conclusions.
allowed-tools: Read, Grep, Glob, Bash, mcp__codex__codex
context: fork
---
# Code Investigate Skill
## Trigger
- - Keywords: 調查代碼, investigate code, 功能怎麼運作, 追蹤實作, 雙重確認, 深入了解, code 怎麼運作, 這段代碼做什麼, 調研代碼, 代碼調研
+ - Keywords: investigate code, how feature works, trace implementation, dual confirmation, deep dive, how code works, what this code does, code research
## When NOT to Use
- - 只需快速查找(直接用 Grep/Glob)
- - 代碼審查(用 codex-review)
- - 系統驗證(用 feature-verify)
- - Git 歷史追蹤(用 git-investigate)
+ - Just need quick lookup (use Grep/Glob directly)
+ - Code review (use codex-review)
+ - System verification (use feature-verify)
+ - Git history tracking (use git-investigate)
## Core Principle
```
- ⚠️ Codex 必須獨立探索,禁止 Claude 餵養結論 ⚠️
+ Codex must explore independently. Feeding Claude's conclusions to Codex is prohibited.
```
```
┌─────────────────┐ ┌─────────────────┐
- │ Claude 獨立調查 │ │ Codex 獨立調查 │
- │ (Phase 1-2) │ │ (Phase 3) │
+ │ Claude Explores │ │ Codex Explores │
+ │ Independently │ │ Independently │
+ │ (Phase 1-2) │ │ (Phase 3) │
└────────┬────────┘ └────────┬────────┘
│ │
▼ ▼
┌───────────┐ ┌───────────┐
│ Claude │ │ Codex │
- │ 結論 │ │ 結論 │
+ │ Conclusion│ │ Conclusion│
└─────┬─────┘ └─────┬─────┘
│ │
└───────────┬───────────┘
▼
┌─────────────┐
- │ 整合報告 │
+ │ Consolidated│
+ │ Report │
│ (Phase 4) │
└─────────────┘
```
## Workflow
- | Phase | 名稱 | 動作 | 產出 |
- | ----- | --------------- | ----------------------- | ---------------- |
- | 1 | Claude Explore | Grep/Glob/Read 搜尋代碼 | 相關檔案清單 |
- | 2 | Claude Conclude | 分析邏輯、形成理解 | 初步結論(內部) |
- | 3 | Codex Explore | 調用 Codex MCP 獨立探索 | Codex 分析報告 |
- | 4 | Integrate | 比對雙方視角、標示差異 | 整合報告 |
+ | Phase | Name | Action | Output |
+ | ----- | --------------- | ----------------------------------- | --------------------------- |
+ | 1 | Claude Explore | Grep/Glob/Read to search code | Related files list |
+ | 2 | Claude Conclude | Analyze logic, form understanding | Initial conclusion (internal)|
+ | 3 | Codex Explore | Invoke Codex MCP to explore independently | Codex analysis report |
+ | 4 | Integrate | Compare both perspectives, mark differences | Consolidated report |
- ## Codex 調用規則
+ ## Codex Invocation Rules
- ### 必要參數
+ ### Required Parameters
- | 參數 | 值 | 說明 |
- | ----------------- | ----------- | -------- |
- | `sandbox` | `read-only` | 強制只讀 |
- | `approval-policy` | `never` | 自動執行 |
- | `cwd` | 專案根目錄 | 探索起點 |
+ | Parameter | Value | Description |
+ | ----------------- | ----------- | --------------- |
+ | `sandbox` | `read-only` | Force read-only |
+ | `approval-policy` | `never` | Auto-execute |
+ | `cwd` | Project root| Exploration start point |
- ### 正確方式
+ ### Correct Approach
```typescript
mcp__codex__codex({
- prompt: `# 代碼調查任務
+ prompt: `# Code Investigation Task
- ## 問題
+ ## Question
${userQuestion}
- ## 專案資訊
- - 路徑:${cwd}
- - 技術棧:{FRAMEWORK} + TypeScript + {DATABASE}
+ ## Project Info
+ - Path: ${cwd}
+ - Tech Stack: {FRAMEWORK} + TypeScript + {DATABASE}
- 請**獨立探索**代碼庫,回答:
- 1. 相關檔案有哪些?
- 2. 核心邏輯如何運作?
- 3. 資料流是什麼?
- 4. 有哪些關鍵依賴?
+ Please **independently explore** the codebase and answer:
+ 1. What files are related?
+ 2. How does the core logic work?
+ 3. What is the data flow?
+ 4. What are the key dependencies?
- 請自行 grep/read 探索,給出你的分析。`,
+ Please grep/read and explore on your own, then provide your analysis.`,
cwd: '/path/to/project',
sandbox: 'read-only',
'approval-policy': 'never',
});
```
- ### 禁止方式
+ ### Prohibited Approaches
- | 模式 | 問題 | 範例 |
- | ---------- | ----------------------- | ---------------------------------- |
- | 餵養結論 | Claude 結論洩漏給 Codex | `Claude 發現這些檔案:${findings}` |
- | 引導性問題 | 預設答案 | `我認為問題出在 cache,請驗證` |
- | 限制範圍 | 阻止獨立探索 | `只看 src/service/` |
+ | Pattern | Problem | Example |
+ | ------------------ | --------------------------------- | ------------------------------------------- |
+ | Feeding conclusion | Claude's findings leak to Codex | `Claude found these files: ${findings}` |
+ | Leading question | Presupposes answer | `I think the problem is in cache, verify` |
+ | Scope restriction | Prevents independent exploration | `Only look at src/service/` |
## Verification Checklist
- | 檢查項 | 標準 |
- | ----------------- | ----------------------------------- |
- | Claude 獨立結論 | Phase 2 形成結論,未輸出給用戶 |
- | Codex prompt 乾淨 | 只含問題 + 專案路徑,無 Claude 發現 |
- | 報告視角分離 | Claude / Codex 結論分開呈現 |
- | 整合完整 | 標示共識點、差異點、可能遺漏 |
+ | Check | Standard |
+ | ------------------------- | --------------------------------------------- |
+ | Claude independent conclusion | Phase 2 forms conclusion, not output to user |
+ | Codex prompt is clean | Contains only question + project path, no Claude findings |
+ | Report perspectives separated | Claude / Codex conclusions presented separately |
+ | Integration is complete | Marks agreement, differences, possible gaps |
## References
- | 檔案 | 用途 | 何時讀 |
- | ------------------------------- | ----------------- | -------------- |
- | `references/prompts.md` | Codex prompt 模板 | Phase 3 調用前 |
- | `references/output-template.md` | 報告格式 | Phase 4 整合時 |
+ | File | Purpose | When to Read |
+ | ------------------------------- | -------------------- | ------------------ |
+ | `references/prompts.md` | Codex prompt templates | Before Phase 3 |
+ | `references/output-template.md` | Report format | During Phase 4 |
## Examples
- ### 功能調查
+ ### Feature Investigation
```
- 輸入:調查 訂單處理流程怎麼運作的
- Phase 1: Grep "processOrder" → Read src/service/order/*.ts
- Phase 2: 形成理解:Controller → Service → Repository 寫入
- Phase 3: Codex 獨立探索(只給問題 + 路徑)
- Phase 4: 整合報告 → 標示雙方視角
+ Input: Investigate how order processing works
+ Phase 1: Grep "processOrder" -> Read src/service/order/*.ts
+ Phase 2: Form understanding: Controller -> Service -> Repository write
+ Phase 3: Codex explores independently (only given question + path)
+ Phase 4: Consolidated report -> mark both perspectives
```
- ### 機制理解
+ ### Mechanism Understanding
```
- 輸入:API 的快取機制怎麼運作?
- Phase 1: Grep "cache" + "portfolio" → Read 相關檔案
- Phase 2: 理解 Redis TTL + fallback 機制
- Phase 3: Codex 獨立調查
- Phase 4: 比對差異 → 輸出整合報告
+ Input: How does the API caching mechanism work?
+ Phase 1: Grep "cache" + "portfolio" -> Read related files
+ Phase 2: Understand Redis TTL + fallback mechanism
+ Phase 3: Codex investigates independently
+ Phase 4: Compare differences -> output consolidated report
```
- ### 問題診斷
+ ### Problem Diagnosis
```
- 輸入:為什麼 token price 有時候是 null?
- Phase 1: 搜尋 price 相關邏輯 + error handling
- Phase 2: 識別可能的 fallback 路徑
- Phase 3: Codex 獨立診斷
- Phase 4: 綜合雙方發現 → 列出可能原因
+ Input: Why is token price sometimes null?
+ Phase 1: Search price-related logic + error handling
+ Phase 2: Identify possible fallback paths
+ Phase 3: Codex diagnoses independently
+ Phase 4: Synthesize both findings -> list possible causes
```