From claudekit
Traces bugs back to root causes through call chain analysis, distinguishing error manifestation from bug origin. Use for deep stack traces, data corruption, indirection, or upstream failures.
npx claudepluginhub duthaho/claudekit --plugin claudekitThis skill uses the workspace's default tool permissions.
- Errors occur far from entry points
Traces bugs backward through call stacks from deep execution errors to find original triggers, adding instrumentation like stack traces to identify invalid data sources.
Traces bugs backward through call stacks to find original triggers. Use for errors deep in execution, long stack traces, unclear data origins, or test pollution.
Mandates invoking relevant skills via tools before any response in coding sessions. Covers access, priorities, and adaptations for Claude Code, Copilot CLI, Gemini CLI.
Share bugs, ideas, or general feedback.
"Trace backward through the call chain until you find the original trigger, then fix at the source."
The error location is rarely the bug location:
User Input → Validation → Service → Repository → Database
^ ^
| |
Bug HERE Error appears HERE
(bad input allowed) (constraint violation)
Fixing at the database layer treats the symptom. Fixing at validation prevents the bug.
Document exactly what you see:
Error: "Cannot insert NULL into column 'user_id'"
Location: database-repository.ts:156
Stack trace: [full trace]
Find the code directly responsible:
// database-repository.ts:156
async function insertOrder(order: Order) {
await db.insert('orders', {
user_id: order.userId, // <- This is NULL
// ...
});
}
Who called this function? What did they pass?
// order-service.ts:89
async function createOrder(orderData: OrderData) {
const order = new Order(orderData);
await repository.insertOrder(order); // <- Called from here
}
Keep going up the call chain:
// order-controller.ts:45
async function handleCreateOrder(req: Request) {
const orderData = req.body; // <- userId might be missing here
await orderService.createOrder(orderData);
}
Reach the entry point where the problem originated:
// The real bug: No validation at entry point
// req.body.userId was never validated
When manual analysis fails, add diagnostic logging:
// Add before suspicious operations
console.error('[TRACE] order-service.createOrder input:', {
orderData,
hasUserId: !!orderData.userId,
stack: new Error().stack
});
// Capture where a value came from
function setUserId(id: string | null) {
if (id === null) {
console.error('[TRACE] userId set to null from:', new Error().stack);
}
this.userId = id;
}
// Log at every system boundary
async function callExternalApi(params) {
console.error('[TRACE] API request:', params);
const response = await fetch(url, params);
console.error('[TRACE] API response:', response.status, await response.text());
return response;
}
console.error('[TRACE] Context:', {
env: process.env.NODE_ENV,
timestamp: new Date().toISOString(),
requestId: context.requestId,
userId: context.user?.id
});
After adding logging:
# Run tests and grep for traces
npm test 2>&1 | grep "\[TRACE\]"
# Or run specific test
npm test -- --grep "failing test" 2>&1 | grep "\[TRACE\]"
| Where Error Appears | Where Bug Often Is |
|---|---|
| Database constraint | Input validation |
| Type error in service | Data transformation |
| Null reference | Optional field handling |
| API timeout | Connection pool config |
| Memory error | Resource cleanup |
After finding root cause, add validation at multiple layers:
// Layer 1: Entry point
function handleRequest(req) {
if (!req.body.userId) {
throw new ValidationError('userId required');
}
}
// Layer 2: Service
function createOrder(data) {
assert(data.userId, 'userId must be provided to createOrder');
}
// Layer 3: Repository
function insertOrder(order) {
assert(order.userId, 'Cannot insert order without userId');
}
See defense-in-depth skill for comprehensive approach.
"NEVER fix just where the error appears."
Fixing at the error location:
Fixing at the source:
systematic-debugging - General debugging methodology; use root-cause-tracing when the bug location differs from the error locationdefense-in-depth - After tracing the root cause, apply multi-layer validation to make the bug structurally impossiblesequential-thinking - Use sequential thinking to systematically document evidence and hypotheses during complex tracing sessions