
Root Cause Tracing
- 41 installs
- 16 repo stars
- Updated November 20, 2025
- jackspace/claudeskillz
Trace a bug backward through the call stack, adding instrumentation as needed, to find the original trigger of invalid data.
About
This skill systematically traces bugs backward through the call stack to locate their original source. Developers use it when errors surface deep in execution and need to find the true trigger of invalid data or behavior.
- Traces bugs backward through the call stack to the source
- Adds instrumentation when needed to pinpoint invalid data
Root Cause Tracing by the numbers
- 41 all-time installs (skills.sh)
- Ranked #331 of 597 Debugging skills by installs in the Skillselion catalog
- Data as of Aug 2, 2026 (Skillselion catalog sync)
npx skills add https://github.com/jackspace/claudeskillz --skill root-cause-tracingAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 41 |
|---|---|
| repo stars | ★ 16 |
| Last updated | November 20, 2025 |
| Repository | jackspace/claudeskillz ↗ |
What it does
Trace a bug backward through the call stack, adding instrumentation as needed, to find the original trigger of invalid data.
Files
Root Cause Tracing
Overview
Bugs often manifest deep in the call stack (git init in wrong directory, file created in wrong location, database opened with wrong path). Your instinct is to fix where the error appears, but that's treating a symptom.
Core principle: Trace backward through the call chain until you find the original trigger, then fix at the source.
When to Use
digraph when_to_use {
"Bug appears deep in stack?" [shape=diamond];
"Can trace backwards?" [shape=diamond];
"Fix at symptom point" [shape=box];
"Trace to original trigger" [shape=box];
"BETTER: Also add defense-in-depth" [shape=box];
"Bug appears deep in stack?" -> "Can trace backwards?" [label="yes"];
"Can trace backwards?" -> "Trace to original trigger" [label="yes"];
"Can trace backwards?" -> "Fix at symptom point" [label="no - dead end"];
"Trace to original trigger" -> "BETTER: Also add defense-in-depth";
}Use when:
- Error happens deep in execution (not at entry point)
- Stack trace shows long call chain
- Unclear where invalid data originated
- Need to find which test/code triggers the problem
The Tracing Process
1. Observe the Symptom
Error: git init failed in /Users/jesse/project/packages/core2. Find Immediate Cause
What code directly causes this?
await execFileAsync('git', ['init'], { cwd: projectDir });3. Ask: What Called This?
WorktreeManager.createSessionWorktree(projectDir, sessionId)
→ called by Session.initializeWorkspace()
→ called by Session.create()
→ called by test at Project.create()4. Keep Tracing Up
What value was passed?
projectDir = ''(empty string!)- Empty string as
cwdresolves toprocess.cwd() - That's the source code directory!
5. Find Original Trigger
Where did empty string come from?
const context = setupCoreTest(); // Returns { tempDir: '' }
Project.create('name', context.tempDir); // Accessed before beforeEach!Adding Stack Traces
When you can't trace manually, add instrumentation:
// Before the problematic operation
async function gitInit(directory: string) {
const stack = new Error().stack;
console.error('DEBUG git init:', {
directory,
cwd: process.cwd(),
nodeEnv: process.env.NODE_ENV,
stack,
});
await execFileAsync('git', ['init'], { cwd: directory });
}Critical: Use console.error() in tests (not logger - may not show)
Run and capture:
npm test 2>&1 | grep 'DEBUG git init'Analyze stack traces:
- Look for test file names
- Find the line number triggering the call
- Identify the pattern (same test? same parameter?)
Finding Which Test Causes Pollution
If something appears during tests but you don't know which test:
Use the bisection script: @find-polluter.sh
./find-polluter.sh '.git' 'src/**/*.test.ts'Runs tests one-by-one, stops at first polluter. See script for usage.
Real Example: Empty projectDir
Symptom: .git created in packages/core/ (source code)
Trace chain: 1. git init runs in process.cwd() ← empty cwd parameter 2. WorktreeManager called with empty projectDir 3. Session.create() passed empty string 4. Test accessed context.tempDir before beforeEach 5. setupCoreTest() returns { tempDir: '' } initially
Root cause: Top-level variable initialization accessing empty value
Fix: Made tempDir a getter that throws if accessed before beforeEach
Also added defense-in-depth:
- Layer 1: Project.create() validates directory
- Layer 2: WorkspaceManager validates not empty
- Layer 3: NODE_ENV guard refuses git init outside tmpdir
- Layer 4: Stack trace logging before git init
Key Principle
digraph principle {
"Found immediate cause" [shape=ellipse];
"Can trace one level up?" [shape=diamond];
"Trace backwards" [shape=box];
"Is this the source?" [shape=diamond];
"Fix at source" [shape=box];
"Add validation at each layer" [shape=box];
"Bug impossible" [shape=doublecircle];
"NEVER fix just the symptom" [shape=octagon, style=filled, fillcolor=red, fontcolor=white];
"Found immediate cause" -> "Can trace one level up?";
"Can trace one level up?" -> "Trace backwards" [label="yes"];
"Can trace one level up?" -> "NEVER fix just the symptom" [label="no"];
"Trace backwards" -> "Is this the source?";
"Is this the source?" -> "Trace backwards" [label="no - keeps going"];
"Is this the source?" -> "Fix at source" [label="yes"];
"Fix at source" -> "Add validation at each layer";
"Add validation at each layer" -> "Bug impossible";
}NEVER fix just where the error appears. Trace back to find the original trigger.
Stack Trace Tips
In tests: Use console.error() not logger - logger may be suppressed Before operation: Log before the dangerous operation, not after it fails Include context: Directory, cwd, environment variables, timestamps Capture stack: new Error().stack shows complete call chain
Real-World Impact
From debugging session (2025-10-03):
- Found root cause through 5-level trace
- Fixed at source (getter validation)
- Added 4 layers of defense
- 1847 tests passed, zero pollution
#!/bin/bash
# Bisection script to find which test creates unwanted files/state
# Usage: ./find-polluter.sh <file_or_dir_to_check> <test_pattern>
# Example: ./find-polluter.sh '.git' 'src/**/*.test.ts'
set -e
if [ $# -ne 2 ]; then
echo "Usage: $0 <file_to_check> <test_pattern>"
echo "Example: $0 '.git' 'src/**/*.test.ts'"
exit 1
fi
POLLUTION_CHECK="$1"
TEST_PATTERN="$2"
echo "🔍 Searching for test that creates: $POLLUTION_CHECK"
echo "Test pattern: $TEST_PATTERN"
echo ""
# Get list of test files
TEST_FILES=$(find . -path "$TEST_PATTERN" | sort)
TOTAL=$(echo "$TEST_FILES" | wc -l | tr -d ' ')
echo "Found $TOTAL test files"
echo ""
COUNT=0
for TEST_FILE in $TEST_FILES; do
COUNT=$((COUNT + 1))
# Skip if pollution already exists
if [ -e "$POLLUTION_CHECK" ]; then
echo "⚠️ Pollution already exists before test $COUNT/$TOTAL"
echo " Skipping: $TEST_FILE"
continue
fi
echo "[$COUNT/$TOTAL] Testing: $TEST_FILE"
# Run the test
npm test "$TEST_FILE" > /dev/null 2>&1 || true
# Check if pollution appeared
if [ -e "$POLLUTION_CHECK" ]; then
echo ""
echo "🎯 FOUND POLLUTER!"
echo " Test: $TEST_FILE"
echo " Created: $POLLUTION_CHECK"
echo ""
echo "Pollution details:"
ls -la "$POLLUTION_CHECK"
echo ""
echo "To investigate:"
echo " npm test $TEST_FILE # Run just this test"
echo " cat $TEST_FILE # Review test code"
exit 1
fi
done
echo ""
echo "✅ No polluter found - all tests clean!"
exit 0
{
"sections": {
"Real Example: Empty projectDir": "**Symptom:** `.git` created in `packages/core/` (source code)\r\n\r\n**Trace chain:**\r\n1. `git init` runs in `process.cwd()` ← empty cwd parameter\r\n2. WorktreeManager called with empty projectDir\r\n3. Session.create() passed empty string\r\n4. Test accessed `context.tempDir` before beforeEach\r\n5. setupCoreTest() returns `{ tempDir: '' }` initially\r\n\r\n**Root cause:** Top-level variable initialization accessing empty value\r\n\r\n**Fix:** Made tempDir a getter that throws if accessed before beforeEach\r\n\r\n**Also added defense-in-depth:**\r\n- Layer 1: Project.create() validates directory\r\n- Layer 2: WorkspaceManager validates not empty\r\n- Layer 3: NODE_ENV guard refuses git init outside tmpdir\r\n- Layer 4: Stack trace logging before git init",
"Finding Which Test Causes Pollution": "If something appears during tests but you don't know which test:\r\n\r\nUse the bisection script: @find-polluter.sh\r\n\r\n```bash\r\n./find-polluter.sh '.git' 'src/**/*.test.ts'\r\n```\r\n\r\nRuns tests one-by-one, stops at first polluter. See script for usage.",
"When to Use": "```dot\r\ndigraph when_to_use {\r\n \"Bug appears deep in stack?\" [shape=diamond];\r\n \"Can trace backwards?\" [shape=diamond];\r\n \"Fix at symptom point\" [shape=box];\r\n \"Trace to original trigger\" [shape=box];\r\n \"BETTER: Also add defense-in-depth\" [shape=box];\r\n\r\n \"Bug appears deep in stack?\" -> \"Can trace backwards?\" [label=\"yes\"];\r\n \"Can trace backwards?\" -> \"Trace to original trigger\" [label=\"yes\"];\r\n \"Can trace backwards?\" -> \"Fix at symptom point\" [label=\"no - dead end\"];\r\n \"Trace to original trigger\" -> \"BETTER: Also add defense-in-depth\";\r\n}\r\n```\r\n\r\n**Use when:**\r\n- Error happens deep in execution (not at entry point)\r\n- Stack trace shows long call chain\r\n- Unclear where invalid data originated\r\n- Need to find which test/code triggers the problem",
"Overview": "Bugs often manifest deep in the call stack (git init in wrong directory, file created in wrong location, database opened with wrong path). Your instinct is to fix where the error appears, but that's treating a symptom.\r\n\r\n**Core principle:** Trace backward through the call chain until you find the original trigger, then fix at the source.",
"The Tracing Process": "### 1. Observe the Symptom\r\n```\r\nError: git init failed in /Users/jesse/project/packages/core\r\n```\r\n\r\n### 2. Find Immediate Cause\r\n**What code directly causes this?**\r\n```typescript\r\nawait execFileAsync('git', ['init'], { cwd: projectDir });\r\n```\r\n\r\n### 3. Ask: What Called This?\r\n```typescript\r\nWorktreeManager.createSessionWorktree(projectDir, sessionId)\r\n → called by Session.initializeWorkspace()\r\n → called by Session.create()\r\n → called by test at Project.create()\r\n```\r\n\r\n### 4. Keep Tracing Up\r\n**What value was passed?**\r\n- `projectDir = ''` (empty string!)\r\n- Empty string as `cwd` resolves to `process.cwd()`\r\n- That's the source code directory!\r\n\r\n### 5. Find Original Trigger\r\n**Where did empty string come from?**\r\n```typescript\r\nconst context = setupCoreTest(); // Returns { tempDir: '' }\r\nProject.create('name', context.tempDir); // Accessed before beforeEach!\r\n```",
"Key Principle": "```dot\r\ndigraph principle {\r\n \"Found immediate cause\" [shape=ellipse];\r\n \"Can trace one level up?\" [shape=diamond];\r\n \"Trace backwards\" [shape=box];\r\n \"Is this the source?\" [shape=diamond];\r\n \"Fix at source\" [shape=box];\r\n \"Add validation at each layer\" [shape=box];\r\n \"Bug impossible\" [shape=doublecircle];\r\n \"NEVER fix just the symptom\" [shape=octagon, style=filled, fillcolor=red, fontcolor=white];\r\n\r\n \"Found immediate cause\" -> \"Can trace one level up?\";\r\n \"Can trace one level up?\" -> \"Trace backwards\" [label=\"yes\"];\r\n \"Can trace one level up?\" -> \"NEVER fix just the symptom\" [label=\"no\"];\r\n \"Trace backwards\" -> \"Is this the source?\";\r\n \"Is this the source?\" -> \"Trace backwards\" [label=\"no - keeps going\"];\r\n \"Is this the source?\" -> \"Fix at source\" [label=\"yes\"];\r\n \"Fix at source\" -> \"Add validation at each layer\";\r\n \"Add validation at each layer\" -> \"Bug impossible\";\r\n}\r\n```\r\n\r\n**NEVER fix just where the error appears.** Trace back to find the original trigger.",
"Real-World Impact": "From debugging session (2025-10-03):\r\n- Found root cause through 5-level trace\r\n- Fixed at source (getter validation)\r\n- Added 4 layers of defense\r\n- 1847 tests passed, zero pollution",
"Adding Stack Traces": "When you can't trace manually, add instrumentation:\r\n\r\n```typescript\r\n// Before the problematic operation\r\nasync function gitInit(directory: string) {\r\n const stack = new Error().stack;\r\n console.error('DEBUG git init:', {\r\n directory,\r\n cwd: process.cwd(),\r\n nodeEnv: process.env.NODE_ENV,\r\n stack,\r\n });\r\n\r\n await execFileAsync('git', ['init'], { cwd: directory });\r\n}\r\n```\r\n\r\n**Critical:** Use `console.error()` in tests (not logger - may not show)\r\n\r\n**Run and capture:**\r\n```bash\r\nnpm test 2>&1 | grep 'DEBUG git init'\r\n```\r\n\r\n**Analyze stack traces:**\r\n- Look for test file names\r\n- Find the line number triggering the call\r\n- Identify the pattern (same test? same parameter?)",
"Stack Trace Tips": "**In tests:** Use `console.error()` not logger - logger may be suppressed\r\n**Before operation:** Log before the dangerous operation, not after it fails\r\n**Include context:** Directory, cwd, environment variables, timestamps\r\n**Capture stack:** `new Error().stack` shows complete call chain"
},
"id": "root-cause-tracing_obra",
"name": "root-cause-tracing",
"description": "Use when errors occur deep in execution and you need to trace back to find the original trigger - systematically traces bugs backward through call stack, adding instrumentation when needed, to identify source of invalid data or incorrect behavior"
}---
name: root-cause-tracing
description: Use when errors occur deep in execution and you need to trace back to find the original trigger - systematically traces bugs backward through call stack, adding instrumentation when needed, to identify source of invalid data or incorrect behavior
---
# Root Cause Tracing
## Overview
Bugs often manifest deep in the call stack (git init in wrong directory, file created in wrong location, database opened with wrong path). Your instinct is to fix where the error appears, but that's treating a symptom.
**Core principle:** Trace backward through the call chain until you find the original trigger, then fix at the source.
## When to Use
```dot
digraph when_to_use {
"Bug appears deep in stack?" [shape=diamond];
"Can trace backwards?" [shape=diamond];
"Fix at symptom point" [shape=box];
"Trace to original trigger" [shape=box];
"BETTER: Also add defense-in-depth" [shape=box];
"Bug appears deep in stack?" -> "Can trace backwards?" [label="yes"];
"Can trace backwards?" -> "Trace to original trigger" [label="yes"];
"Can trace backwards?" -> "Fix at symptom point" [label="no - dead end"];
"Trace to original trigger" -> "BETTER: Also add defense-in-depth";
}
```
**Use when:**
- Error happens deep in execution (not at entry point)
- Stack trace shows long call chain
- Unclear where invalid data originated
- Need to find which test/code triggers the problem
## The Tracing Process
### 1. Observe the Symptom
```
Error: git init failed in /Users/jesse/project/packages/core
```
### 2. Find Immediate Cause
**What code directly causes this?**
```typescript
await execFileAsync('git', ['init'], { cwd: projectDir });
```
### 3. Ask: What Called This?
```typescript
WorktreeManager.createSessionWorktree(projectDir, sessionId)
→ called by Session.initializeWorkspace()
→ called by Session.create()
→ called by test at Project.create()
```
### 4. Keep Tracing Up
**What value was passed?**
- `projectDir = ''` (empty string!)
- Empty string as `cwd` resolves to `process.cwd()`
- That's the source code directory!
### 5. Find Original Trigger
**Where did empty string come from?**
```typescript
const context = setupCoreTest(); // Returns { tempDir: '' }
Project.create('name', context.tempDir); // Accessed before beforeEach!
```
## Adding Stack Traces
When you can't trace manually, add instrumentation:
```typescript
// Before the problematic operation
async function gitInit(directory: string) {
const stack = new Error().stack;
console.error('DEBUG git init:', {
directory,
cwd: process.cwd(),
nodeEnv: process.env.NODE_ENV,
stack,
});
await execFileAsync('git', ['init'], { cwd: directory });
}
```
**Critical:** Use `console.error()` in tests (not logger - may not show)
**Run and capture:**
```bash
npm test 2>&1 | grep 'DEBUG git init'
```
**Analyze stack traces:**
- Look for test file names
- Find the line number triggering the call
- Identify the pattern (same test? same parameter?)
## Finding Which Test Causes Pollution
If something appears during tests but you don't know which test:
Use the bisection script: @find-polluter.sh
```bash
./find-polluter.sh '.git' 'src/**/*.test.ts'
```
Runs tests one-by-one, stops at first polluter. See script for usage.
## Real Example: Empty projectDir
**Symptom:** `.git` created in `packages/core/` (source code)
**Trace chain:**
1. `git init` runs in `process.cwd()` ← empty cwd parameter
2. WorktreeManager called with empty projectDir
3. Session.create() passed empty string
4. Test accessed `context.tempDir` before beforeEach
5. setupCoreTest() returns `{ tempDir: '' }` initially
**Root cause:** Top-level variable initialization accessing empty value
**Fix:** Made tempDir a getter that throws if accessed before beforeEach
**Also added defense-in-depth:**
- Layer 1: Project.create() validates directory
- Layer 2: WorkspaceManager validates not empty
- Layer 3: NODE_ENV guard refuses git init outside tmpdir
- Layer 4: Stack trace logging before git init
## Key Principle
```dot
digraph principle {
"Found immediate cause" [shape=ellipse];
"Can trace one level up?" [shape=diamond];
"Trace backwards" [shape=box];
"Is this the source?" [shape=diamond];
"Fix at source" [shape=box];
"Add validation at each layer" [shape=box];
"Bug impossible" [shape=doublecircle];
"NEVER fix just the symptom" [shape=octagon, style=filled, fillcolor=red, fontcolor=white];
"Found immediate cause" -> "Can trace one level up?";
"Can trace one level up?" -> "Trace backwards" [label="yes"];
"Can trace one level up?" -> "NEVER fix just the symptom" [label="no"];
"Trace backwards" -> "Is this the source?";
"Is this the source?" -> "Trace backwards" [label="no - keeps going"];
"Is this the source?" -> "Fix at source" [label="yes"];
"Fix at source" -> "Add validation at each layer";
"Add validation at each layer" -> "Bug impossible";
}
```
**NEVER fix just where the error appears.** Trace back to find the original trigger.
## Stack Trace Tips
**In tests:** Use `console.error()` not logger - logger may be suppressed
**Before operation:** Log before the dangerous operation, not after it fails
**Include context:** Directory, cwd, environment variables, timestamps
**Capture stack:** `new Error().stack` shows complete call chain
## Real-World Impact
From debugging session (2025-10-03):
- Found root cause through 5-level trace
- Fixed at source (getter validation)
- Added 4 layers of defense
- 1847 tests passed, zero pollution