Investigate — Root Cause Analysis Engine
Systematic deep investigation protocol. Finds the REAL cause, not the surface symptom.
Core principle: Never fix what you don't understand. Every fix must trace to a proven root cause with evidence.
Pre-Flight Gate
Activation is decided by the frontmatter description alone — this file is read only AFTER the skill
has been selected. Nothing here can prevent over-triggering, so this gate is a post-selection
redirect, not a filter.
Before proceeding, check the ABORT and ROUTE OUT conditions below. If any holds, STOP, say in one
line which one fired, and take the redirect instead of starting the 8-phase protocol. Being
invoked — including a literal /investigate or "find the root cause" — does NOT override an ABORT:
the phrasing that selected this skill is not evidence the cause is unknown.
- Run the 8-phase protocol only for a real bug / unexpected behavior whose root cause is UNKNOWN.
- ABORT: a bug whose cause is already known (just fix it), a feature request, an obvious-cause config/syntax error, or anything not actually broken.
- ROUTE OUT: a live production outage — service down, users impacted, an active incident — goes to incident-commander FIRST. Mitigate and restore service, then run
/investigate for the root cause. An unknown cause does NOT admit an outage to this protocol: diagnosis-before-mitigation is paid for in downtime.
Protocol
Process every /investigate invocation through these 8 phases in strict order. Never skip a phase. Never jump to Phase 7 (FIX) without completing Phases 1-6 and satisfying the Phase 6 consent gate. Phase 6 is a hard halt: stopping there for approval is a correct completion of the protocol, not a skipped phase.
Phase 1: OBSERVE — Gather All Symptoms
Collect every observable fact before forming any theory.
Parse $ARGUMENTS as the symptom description
Extract the available facts from $ARGUMENTS and note which are unknown — capture gaps rather than prompting interactively (see the fork note under "Tool Usage by Phase"):
- Expected vs actual behavior
- When it started / what changed recently
- Consistent or intermittent
- Error messages, logs, or stack traces
If a gap blocks the investigation, exhaust the codebase, git history, and tests first; only then surface the specific questions in the final report (per the Phase 5 gate).
Check memory files for known pitfalls related to this area:
- Read MEMORY.md and any topic-specific memory files
- Check CLAUDE.md for documented patterns
Gather environmental context:
- Run
git log --oneline -20 to see recent changes
- Run
git diff --stat HEAD~5 to see what files changed recently
- Check for any failing tests with the project's test runner
Output: A symptom report listing every observable fact, recent changes, and any relevant memory entries.
Gate: Do NOT theorize yet. Only facts.
Phase 2: REPRODUCE — Confirm the Issue
An issue you cannot reproduce is an issue you cannot prove you fixed.
- Identify the shortest path to trigger the symptom:
- Run existing tests that cover the affected area
- If no test exists, attempt manual reproduction via Bash
- For UI issues, use Playwright MCP for precise reproduction:
playwright_navigate to the affected page
playwright_screenshot to capture initial state
- Replay the interaction sequence (
playwright_click, playwright_fill, etc.)
playwright_screenshot to capture the error state
playwright_console_logs with type: "error" to capture JS errors
- Use
start_codegen_session to record the reproduction as a reusable test
- Document the reproduction steps precisely
- If the issue is intermittent:
- Flag it as potentially timing-dependent (race condition, async, state)
- Look for concurrent access, shared mutable state, missing locks/guards
- Check for dependency on external state (network, filesystem, database)
- If the issue cannot be reproduced:
- Shift to forensic investigation (logs, git history, code review)
- Do NOT skip remaining phases — proceed with available evidence
Output: Reproduction steps, or explicit documentation of why reproduction failed.
Gate: Issue confirmed (or forensic mode declared). Proceed.
Phase 3: TRACE — Follow the Execution Path
Start from the symptom and trace backward to the origin.
- Locate the symptom — find the exact file and line where the error occurs:
- Use Grep for error messages, exception types, log strings
- Explore agent for broad searches if the location is unclear — unavailable when forked; batch parallel Grep/Glob calls inline instead
- Trace the call chain — read every file in the execution path:
- Use LSP
goToDefinition and findReferences to navigate the call chain precisely
- Use LSP
incomingCalls/outgoingCalls to map the full call hierarchy
- From error site → caller → caller's caller → entry point
- Read each file fully with Read tool — do NOT skim
- Document the complete flow: input → transform → output
- Trace the data flow — follow the data that caused the error:
- What value caused the crash? Where did it come from?
- Trace the value backward: variable → assignment → source → input
- Map dependencies — what else touches this code path:
- Use LSP
findReferences to find all callers of the failing function (more precise than Grep)
- Fall back to Grep if LSP is unavailable for the file type
- Check for shared state, singletons, global variables
- Look for recent changes in dependencies with
git log --oneline -- <file>
- Check git forensics — when was the problem introduced:
git log --oneline -- <affected-files> — who changed these files and when?
git blame <file> on the suspicious lines — what commit introduced them?
- If a clear suspect commit is found, read its full diff
Output: Complete execution trace with file paths and line numbers. Data flow map. Git timeline.
Gate: The full code path from entry point to symptom is mapped and understood.
Phase 4: HYPOTHESIZE — Deep Reasoning with 5 Whys
This phase MUST use the sequential-thinking MCP server for structured multi-step reasoning.
- Start the sequential-thinking chain with the symptom and all evidence from Phases 1-3
- Apply the 5 Whys method — for each answer, ask "but why does THAT happen?":
Symptom: App crashes when tapping a document
Why 1: DocumentDetailView accesses a deleted NSManagedObject
Why 2: The object was deleted from Core Data while the view held a reference
Why 3: context.delete() was called from a background operation
Why 4: The background sync didn't check if the view was still displaying the object
Why 5: There's no soft-delete pattern — objects are hard-deleted immediately
ROOT CAUSE: Missing soft-delete guard in the sync pipeline
- Generate at least 2 competing hypotheses — don't lock on the first theory:
- Categorize each by type: Code Logic | Data State | Timing/Race | Environment | Dependency | Configuration
- For each hypothesis, define what evidence would prove or disprove it
- Use branching in sequential-thinking to explore alternative explanations:
branchFromThought: 3, branchId: "alternative-cause"
- Rank hypotheses by likelihood based on available evidence
Output: Ranked list of hypotheses with evidence requirements for each.
Gate: At least 2 hypotheses generated. Each has defined proof criteria.
Phase 5: PROVE — Test Each Hypothesis with Evidence
Systematically confirm or eliminate each hypothesis. No guessing.
For each hypothesis (highest-ranked first):
- Gather confirming evidence:
- Read the specific code paths predicted by the hypothesis
- Check logs/output for patterns the hypothesis predicts
- Run targeted tests that would pass if the hypothesis is correct
- Use
git blame / git log to check if timing matches
- Gather disconfirming evidence:
- Look for code paths that should also fail if the hypothesis is correct but don't
- Check edge cases that contradict the hypothesis
- Check external sources:
- Use WebSearch for known issues in the library/framework version
- Use library-docs skill (context7 MCP) to verify correct API usage
- Search GitHub issues for the library:
mcp__github__search_issues
- Verdict per hypothesis:
- CONFIRMED — evidence supports it, no contradictions
- ELIMINATED — evidence contradicts it
- INCONCLUSIVE — need more evidence (define what)
If all hypotheses are eliminated: Return to Phase 4 with new evidence. Generate new hypotheses.
Output: Evidence log per hypothesis. One confirmed root cause (or request for more data).
Gate: Exactly one root cause confirmed with evidence. Or an explicit statement that the cause requires additional data from the user (with specific questions).
Phase 6: ROOT CAUSE — Document the Causal Chain
Write the definitive explanation before touching any code.
- Document the complete causal chain:
ROOT CAUSE: <the deepest systemic issue>
→ causes: <intermediate effect>
→ causes: <intermediate effect>
→ manifests as: <the symptom the user reported>
- Explain why this is the root cause (not just a proximate cause):
- If fixed, would it prevent recurrence? (yes = root cause)
- Is there a deeper cause? (if yes, keep digging)
- Identify the blast radius — what else is affected:
- Are there similar patterns elsewhere in the codebase?
- Use Grep to find analogous code that may have the same bug
- Present the root cause analysis for approval before proceeding to fix
Output: Root cause statement, causal chain, blast radius assessment.
Gate — HARD HALT. Consent is required, and silence is never consent. Phase 7 may begin only after the user has seen this diagnosis and approved a fix.
- Forked run (
context: fork — the default): STOP HERE. End the run at Phase 6, return the root-cause report as the final answer, and do NOT enter Phase 7 or Phase 8. Consent cannot be obtained mid-run because a forked run cannot use AskUserQuestion, so the fix is out of scope for this invocation by construction. Close the report with: "Root cause proven — approve to proceed with the fix (Phases 7-8)."
- Un-forked only: present the diagnosis, obtain the user's explicit agreement, then continue to Phase 7. No agreement, no fix — stop here instead.
- Resuming: Phases 7-8 run in a subsequent invocation that carries the user's approval of this diagnosis. The approval must be present in that invocation; never infer it from the fact that an investigation already ran.
Phase 7: FIX — Address the Root Cause
Fix the root cause, not the symptom. Minimal, targeted change.
Precondition — do not start without it: the Phase 6 consent gate is satisfied, i.e. this invocation carries the user's approval of the diagnosis. A forked run has already ended at Phase 6 and never reaches this phase. If you cannot point to that approval, stop and return the Phase 6 report instead.
- Design the fix:
- What is the minimum change that eliminates the root cause?
- Does the fix handle all cases in the blast radius (Phase 6)?
- Does the fix introduce any new risks?
- Implement the fix:
- Read every file before modifying it
- Make the smallest change possible
- Add inline comments only where the fix is non-obvious
- Verify the fix:
- Run the reproduction steps from Phase 2 — symptom should be gone
- Run existing tests — no regressions
- Run code-quality agent on modified files if the change is substantial
- Check for similar patterns:
- If the bug was a pattern (e.g., missing null check), search for the same pattern elsewhere
- Fix all instances, not just the reported one
Output: Code changes with explanation of what was changed and why.
Phase 8: PREVENT — Ensure It Never Recurs
The investigation isn't complete until recurrence is prevented.
- Add a regression test that would have caught this bug:
- The test must fail without the fix and pass with it
- Use test-automation agent for comprehensive test generation
- Update project memory if a new pitfall was discovered:
- Add to MEMORY.md under Common Pitfalls
- Include the pattern, why it's dangerous, and the safe alternative
- Suggest structural improvements (optional, only if the bug reveals a design flaw):
- Propose architectural changes that make this class of bug impossible
- Present as a suggestion, not an immediate action
- Write the investigation summary:
## Investigation Report
**Symptom:** <what was reported>
**Root Cause:** <the deepest systemic issue>
**Causal Chain:** root cause → ... → symptom
**Fix:** <what was changed, which files>
**Blast Radius:** <other areas checked/fixed>
**Regression Test:** <test added>
**Prevention:** <memory updated, guard added, pattern documented>
**Time:** <phases completed, hypotheses tested>
Tool Usage by Phase
| Phase |
Primary Tools |
When to Use Agents |
| 1. OBSERVE |
Read, Grep, Bash (git log) |
— |
| 2. REPRODUCE |
Bash (test runner), Playwright MCP |
— |
| 3. TRACE |
Read, Grep, Glob, Bash (git blame) |
Explore agent for broad searches (un-forked only) |
| 4. HYPOTHESIZE |
sequential-thinking MCP |
deep-analysis skill |
| 5. PROVE |
Read, Grep, Bash, WebSearch, context7 MCP |
library-docs skill, GitHub MCP |
| 6. ROOT CAUSE |
Read, Grep |
Explore agent for blast radius (un-forked only) |
| 7. FIX |
Read, Edit, Write, Bash |
code-quality agent for review |
| 8. PREVENT |
Write, Edit, Bash |
test-automation agent for tests |
Fork note: /investigate runs forked (context: fork) for context isolation — the deep trace/evidence stays out of the main conversation and only the root-cause report returns. Forked subagents cannot use the Agent launcher or AskUserQuestion, so the "When to Use Agents" column (Explore / code-quality / test-automation) and any user clarification apply only when this protocol is run un-forked. When forked (the default), perform those steps inline with the Primary Tools and surface any needed user input in the final report. Because consent cannot be collected mid-run, Phase 6 is a hard halt when forked — the run ends with the root-cause report, and Phases 7-8 wait for a subsequent, approval-carrying invocation (see the Phase 6 gate, which is authoritative). (Core RCA runs on Primary Tools — Read/Grep/Bash/sequential-thinking/Playwright/context7/GitHub/LSP — all available to subagents, so fork costs nothing for the core.)
Anti-Patterns — What This Skill Prevents
| Bad Habit |
What /investigate Does Instead |
| Jump straight to fixing |
Forces Phases 1-6 before any code change |
| Fix the symptom |
5 Whys drills to root cause |
| Single theory tunnel vision |
Requires 2+ competing hypotheses |
| "It works now" without understanding |
Demands evidence-based proof |
| Fix one instance, miss others |
Blast radius analysis in Phase 6 |
| No regression test |
Phase 8 mandates a test |
| Knowledge lost |
Memory update in Phase 8 |
When to Use /investigate vs Other Tools
| Situation |
Use |
| Bug, crash, error, unexpected behavior |
/investigate |
| Live production outage — service down, users impacted, active incident |
incident-commander FIRST — mitigate and restore, then /investigate for the RCA |
| Build a new feature |
/execute |
| Quick "what does this code do?" |
Explore agent directly (main session only) |
| Performance slow but unclear why |
/investigate (treat slowness as symptom) |
| Known fix, just need to apply it |
Direct Edit — no investigation needed |
| Security vulnerability found |
/investigate + security-scan |
References
See references/investigation-frameworks.md for detailed methodology guides.
1---2name: investigate3description: Deep root cause analysis engine for defects whose cause is genuinely unknown. Runs an 8-phase diagnostic protocol — observe, reproduce, trace, hypothesize, prove, root cause, fix, prevent — using sequential-thinking MCP, multi-pass code reading, git forensics, competing hypotheses, and the 5 Whys, proving the cause with evidence before any fix. Returns a proven root-cause report; the fix runs only after that diagnosis is approved. Use when the user runs /investigate, or when a bug, crash, exception, stack trace, regression, flaky or intermittent failure, data corruption, memory leak, or unexplained slowness needs its root cause found and nobody knows why. Expensive — do not select it when the cause is already known, for a typo, syntax, import or config mistake, for a feature request or refactor, for "what does this code do", or for applying a fix the user already chose; handle those directly. For a live production outage, route to incident-commander first and investigate after service is restored.4---56# Investigate — Root Cause Analysis Engine78Systematic deep investigation protocol. Finds the REAL cause, not the surface symptom.910**Core principle:** Never fix what you don't understand. Every fix must trace to a proven root cause with evidence.1112## Pre-Flight Gate1314Activation is decided by the frontmatter description alone — this file is read only AFTER the skill15has been selected. Nothing here can prevent over-triggering, so this gate is a **post-selection16redirect**, not a filter.1718**Before proceeding, check the ABORT and ROUTE OUT conditions below. If any holds, STOP, say in one19line which one fired, and take the redirect instead of starting the 8-phase protocol.** Being20invoked — including a literal `/investigate` or "find the root cause" — does NOT override an ABORT:21the phrasing that selected this skill is not evidence the cause is unknown.2223- Run the 8-phase protocol only for a real bug / unexpected behavior whose root cause is UNKNOWN.24- ABORT: a bug whose cause is already known (just fix it), a feature request, an obvious-cause config/syntax error, or anything not actually broken.25- ROUTE OUT: a **live production outage** — service down, users impacted, an active incident — goes to **incident-commander FIRST**. Mitigate and restore service, then run `/investigate` for the root cause. An unknown cause does NOT admit an outage to this protocol: diagnosis-before-mitigation is paid for in downtime.2627## Protocol2829Process every `/investigate` invocation through these 8 phases in strict order. Never skip a phase. Never jump to Phase 7 (FIX) without completing Phases 1-6 **and** satisfying the Phase 6 consent gate. Phase 6 is a hard halt: stopping there for approval is a correct completion of the protocol, not a skipped phase.3031---3233### Phase 1: OBSERVE — Gather All Symptoms3435Collect every observable fact before forming any theory.36371. Parse `$ARGUMENTS` as the symptom description382. Extract the available facts from `$ARGUMENTS` and note which are unknown — capture gaps rather than prompting interactively (see the fork note under "Tool Usage by Phase"):39 - Expected vs actual behavior40 - When it started / what changed recently41 - Consistent or intermittent42 - Error messages, logs, or stack traces4344 If a gap blocks the investigation, exhaust the codebase, git history, and tests first; only then surface the specific questions in the final report (per the Phase 5 gate).453. Check memory files for known pitfalls related to this area:46 - Read MEMORY.md and any topic-specific memory files47 - Check CLAUDE.md for documented patterns484. Gather environmental context:49 - Run `git log --oneline -20` to see recent changes50 - Run `git diff --stat HEAD~5` to see what files changed recently51 - Check for any failing tests with the project's test runner5253**Output:** A symptom report listing every observable fact, recent changes, and any relevant memory entries.5455**Gate:** Do NOT theorize yet. Only facts.5657---5859### Phase 2: REPRODUCE — Confirm the Issue6061An issue you cannot reproduce is an issue you cannot prove you fixed.62631. Identify the shortest path to trigger the symptom:64 - Run existing tests that cover the affected area65 - If no test exists, attempt manual reproduction via Bash66 - For UI issues, use Playwright MCP for precise reproduction:67 1. `playwright_navigate` to the affected page68 2. `playwright_screenshot` to capture initial state69 3. Replay the interaction sequence (`playwright_click`, `playwright_fill`, etc.)70 4. `playwright_screenshot` to capture the error state71 5. `playwright_console_logs` with `type: "error"` to capture JS errors72 6. Use `start_codegen_session` to record the reproduction as a reusable test732. Document the reproduction steps precisely743. If the issue is **intermittent**:75 - Flag it as potentially timing-dependent (race condition, async, state)76 - Look for concurrent access, shared mutable state, missing locks/guards77 - Check for dependency on external state (network, filesystem, database)784. If the issue **cannot be reproduced**:79 - Shift to forensic investigation (logs, git history, code review)80 - Do NOT skip remaining phases — proceed with available evidence8182**Output:** Reproduction steps, or explicit documentation of why reproduction failed.8384**Gate:** Issue confirmed (or forensic mode declared). Proceed.8586---8788### Phase 3: TRACE — Follow the Execution Path8990Start from the symptom and trace backward to the origin.91921. **Locate the symptom** — find the exact file and line where the error occurs:93 - Use Grep for error messages, exception types, log strings94 - Explore agent for broad searches if the location is unclear — unavailable when forked; batch parallel Grep/Glob calls inline instead952. **Trace the call chain** — read every file in the execution path:96 - Use LSP `goToDefinition` and `findReferences` to navigate the call chain precisely97 - Use LSP `incomingCalls`/`outgoingCalls` to map the full call hierarchy98 - From error site → caller → caller's caller → entry point99 - Read each file fully with Read tool — do NOT skim100 - Document the complete flow: input → transform → output1013. **Trace the data flow** — follow the data that caused the error:102 - What value caused the crash? Where did it come from?103 - Trace the value backward: variable → assignment → source → input1044. **Map dependencies** — what else touches this code path:105 - Use LSP `findReferences` to find all callers of the failing function (more precise than Grep)106 - Fall back to Grep if LSP is unavailable for the file type107 - Check for shared state, singletons, global variables108 - Look for recent changes in dependencies with `git log --oneline -- <file>`1095. **Check git forensics** — when was the problem introduced:110 - `git log --oneline -- <affected-files>` — who changed these files and when?111 - `git blame <file>` on the suspicious lines — what commit introduced them?112 - If a clear suspect commit is found, read its full diff113114**Output:** Complete execution trace with file paths and line numbers. Data flow map. Git timeline.115116**Gate:** The full code path from entry point to symptom is mapped and understood.117118---119120### Phase 4: HYPOTHESIZE — Deep Reasoning with 5 Whys121122**This phase MUST use the sequential-thinking MCP server** for structured multi-step reasoning.1231241. Start the sequential-thinking chain with the symptom and all evidence from Phases 1-31252. Apply the **5 Whys method** — for each answer, ask "but why does THAT happen?":126 ```127 Symptom: App crashes when tapping a document128 Why 1: DocumentDetailView accesses a deleted NSManagedObject129 Why 2: The object was deleted from Core Data while the view held a reference130 Why 3: context.delete() was called from a background operation131 Why 4: The background sync didn't check if the view was still displaying the object132 Why 5: There's no soft-delete pattern — objects are hard-deleted immediately133 ROOT CAUSE: Missing soft-delete guard in the sync pipeline134 ```1353. Generate **at least 2 competing hypotheses** — don't lock on the first theory:136 - Categorize each by type: Code Logic | Data State | Timing/Race | Environment | Dependency | Configuration137 - For each hypothesis, define what evidence would prove or disprove it1384. Use **branching** in sequential-thinking to explore alternative explanations:139 ```140 branchFromThought: 3, branchId: "alternative-cause"141 ```1425. Rank hypotheses by likelihood based on available evidence143144**Output:** Ranked list of hypotheses with evidence requirements for each.145146**Gate:** At least 2 hypotheses generated. Each has defined proof criteria.147148---149150### Phase 5: PROVE — Test Each Hypothesis with Evidence151152Systematically confirm or eliminate each hypothesis. No guessing.153154**For each hypothesis (highest-ranked first):**1551561. **Gather confirming evidence:**157 - Read the specific code paths predicted by the hypothesis158 - Check logs/output for patterns the hypothesis predicts159 - Run targeted tests that would pass if the hypothesis is correct160 - Use `git blame` / `git log` to check if timing matches1612. **Gather disconfirming evidence:**162 - Look for code paths that should also fail if the hypothesis is correct but don't163 - Check edge cases that contradict the hypothesis1643. **Check external sources:**165 - Use WebSearch for known issues in the library/framework version166 - Use library-docs skill (context7 MCP) to verify correct API usage167 - Search GitHub issues for the library: `mcp__github__search_issues`1684. **Verdict per hypothesis:**169 - **CONFIRMED** — evidence supports it, no contradictions170 - **ELIMINATED** — evidence contradicts it171 - **INCONCLUSIVE** — need more evidence (define what)172173**If all hypotheses are eliminated:** Return to Phase 4 with new evidence. Generate new hypotheses.174175**Output:** Evidence log per hypothesis. One confirmed root cause (or request for more data).176177**Gate:** Exactly one root cause confirmed with evidence. Or an explicit statement that the cause requires additional data from the user (with specific questions).178179---180181### Phase 6: ROOT CAUSE — Document the Causal Chain182183Write the definitive explanation before touching any code.1841851. Document the complete causal chain:186 ```187 ROOT CAUSE: <the deepest systemic issue>188 → causes: <intermediate effect>189 → causes: <intermediate effect>190 → manifests as: <the symptom the user reported>191 ```1922. Explain **why** this is the root cause (not just a proximate cause):193 - If fixed, would it prevent recurrence? (yes = root cause)194 - Is there a deeper cause? (if yes, keep digging)1953. Identify the **blast radius** — what else is affected:196 - Are there similar patterns elsewhere in the codebase?197 - Use Grep to find analogous code that may have the same bug1984. Present the root cause analysis for approval before proceeding to fix199200**Output:** Root cause statement, causal chain, blast radius assessment.201202**Gate — HARD HALT. Consent is required, and silence is never consent.** Phase 7 may begin only after the user has seen this diagnosis and approved a fix.203204- **Forked run (`context: fork` — the default): STOP HERE.** End the run at Phase 6, return the root-cause report as the final answer, and do NOT enter Phase 7 or Phase 8. Consent cannot be obtained mid-run because a forked run cannot use AskUserQuestion, so the fix is out of scope for this invocation by construction. Close the report with: "Root cause proven — approve to proceed with the fix (Phases 7-8)."205- **Un-forked only:** present the diagnosis, obtain the user's explicit agreement, then continue to Phase 7. No agreement, no fix — stop here instead.206- **Resuming:** Phases 7-8 run in a *subsequent* invocation that carries the user's approval of this diagnosis. The approval must be present in that invocation; never infer it from the fact that an investigation already ran.207208---209210### Phase 7: FIX — Address the Root Cause211212Fix the root cause, not the symptom. Minimal, targeted change.213214**Precondition — do not start without it:** the Phase 6 consent gate is satisfied, i.e. this invocation carries the user's approval of the diagnosis. A forked run has already ended at Phase 6 and never reaches this phase. If you cannot point to that approval, stop and return the Phase 6 report instead.2152161. Design the fix:217 - What is the minimum change that eliminates the root cause?218 - Does the fix handle all cases in the blast radius (Phase 6)?219 - Does the fix introduce any new risks?2202. Implement the fix:221 - Read every file before modifying it222 - Make the smallest change possible223 - Add inline comments only where the fix is non-obvious2243. Verify the fix:225 - Run the reproduction steps from Phase 2 — symptom should be gone226 - Run existing tests — no regressions227 - Run code-quality agent on modified files if the change is substantial2284. Check for similar patterns:229 - If the bug was a pattern (e.g., missing null check), search for the same pattern elsewhere230 - Fix all instances, not just the reported one231232**Output:** Code changes with explanation of what was changed and why.233234---235236### Phase 8: PREVENT — Ensure It Never Recurs237238The investigation isn't complete until recurrence is prevented.2392401. **Add a regression test** that would have caught this bug:241 - The test must fail without the fix and pass with it242 - Use test-automation agent for comprehensive test generation2432. **Update project memory** if a new pitfall was discovered:244 - Add to MEMORY.md under Common Pitfalls245 - Include the pattern, why it's dangerous, and the safe alternative2463. **Suggest structural improvements** (optional, only if the bug reveals a design flaw):247 - Propose architectural changes that make this class of bug impossible248 - Present as a suggestion, not an immediate action2494. **Write the investigation summary:**250251```252## Investigation Report253254**Symptom:** <what was reported>255**Root Cause:** <the deepest systemic issue>256**Causal Chain:** root cause → ... → symptom257**Fix:** <what was changed, which files>258**Blast Radius:** <other areas checked/fixed>259**Regression Test:** <test added>260**Prevention:** <memory updated, guard added, pattern documented>261**Time:** <phases completed, hypotheses tested>262```263264---265266## Tool Usage by Phase267268| Phase | Primary Tools | When to Use Agents |269|-------|--------------|-------------------|270| 1. OBSERVE | Read, Grep, Bash (git log) | — |271| 2. REPRODUCE | Bash (test runner), Playwright MCP | — |272| 3. TRACE | Read, Grep, Glob, Bash (git blame) | Explore agent for broad searches (un-forked only) |273| 4. HYPOTHESIZE | sequential-thinking MCP | deep-analysis skill |274| 5. PROVE | Read, Grep, Bash, WebSearch, context7 MCP | library-docs skill, GitHub MCP |275| 6. ROOT CAUSE | Read, Grep | Explore agent for blast radius (un-forked only) |276| 7. FIX | Read, Edit, Write, Bash | code-quality agent for review |277| 8. PREVENT | Write, Edit, Bash | test-automation agent for tests |278279> **Fork note:** `/investigate` runs forked (`context: fork`) for context isolation — the deep trace/evidence stays out of the main conversation and only the root-cause report returns. Forked subagents cannot use the `Agent` launcher or `AskUserQuestion`, so the "When to Use Agents" column (Explore / code-quality / test-automation) and any user clarification apply only when this protocol is run un-forked. When forked (the default), perform those steps inline with the Primary Tools and surface any needed user input in the final report. Because consent cannot be collected mid-run, **Phase 6 is a hard halt when forked** — the run ends with the root-cause report, and Phases 7-8 wait for a subsequent, approval-carrying invocation (see the Phase 6 gate, which is authoritative). (Core RCA runs on Primary Tools — Read/Grep/Bash/sequential-thinking/Playwright/context7/GitHub/LSP — all available to subagents, so fork costs nothing for the core.)280281## Anti-Patterns — What This Skill Prevents282283| Bad Habit | What `/investigate` Does Instead |284|-----------|--------------------------------|285| Jump straight to fixing | Forces Phases 1-6 before any code change |286| Fix the symptom | 5 Whys drills to root cause |287| Single theory tunnel vision | Requires 2+ competing hypotheses |288| "It works now" without understanding | Demands evidence-based proof |289| Fix one instance, miss others | Blast radius analysis in Phase 6 |290| No regression test | Phase 8 mandates a test |291| Knowledge lost | Memory update in Phase 8 |292293## When to Use `/investigate` vs Other Tools294295| Situation | Use |296|-----------|-----|297| Bug, crash, error, unexpected behavior | `/investigate` |298| **Live production outage** — service down, users impacted, active incident | **incident-commander FIRST** — mitigate and restore, then `/investigate` for the RCA |299| Build a new feature | `/execute` |300| Quick "what does this code do?" | Explore agent directly (main session only) |301| Performance slow but unclear why | `/investigate` (treat slowness as symptom) |302| Known fix, just need to apply it | Direct Edit — no investigation needed |303| Security vulnerability found | `/investigate` + security-scan |304305## References306307See [references/investigation-frameworks.md](references/investigation-frameworks.md) for detailed methodology guides.