Skip to main content
ClaudeWave
Skill4.3k repo starsupdated 7d ago

bug-detective

Bug Detective is a Claude Code skill that provides systematic debugging workflows for investigating and resolving code errors, exceptions, and failures. Use this skill when users request help debugging code, fixing errors, troubleshooting issues, or investigating why something isn't working. It guides users through understanding problems, analyzing error types, locating sources, and implementing fixes through structured scientific methods.

Install in Claude Code
Copy
git clone --depth 1 https://github.com/Galaxy-Dawn/claude-scholar /tmp/bug-detective && cp -r /tmp/bug-detective/skills/bug-detective ~/.claude/skills/bug-detective
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# Bug Detective

A systematic debugging workflow for investigating and resolving code errors, exceptions, and failures. Provides structured debugging methods and common error pattern recognition.

## Core Philosophy

Debugging is a scientific problem-solving process that requires:
1. **Understand the problem** - Clearly define symptoms and expected behavior
2. **Gather evidence** - Collect error messages, logs, stack traces
3. **Form hypotheses** - Infer possible causes based on evidence
4. **Verify hypotheses** - Confirm or eliminate causes through experiments
5. **Resolve the issue** - Apply fixes and verify

## Debugging Workflow

### Step 1: Understand the Problem

Before starting to debug, clarify the following information:

**Required information to collect:**
- Complete error message content
- Exact location of the error (filename and line number)
- Reproduction steps (how to trigger the error)
- Expected behavior vs actual behavior
- Environment info (OS, versions, dependencies)

**Question template:**
```
1. What is the exact error message?
2. Which file and line does the error occur at?
3. How can this issue be reproduced? Provide detailed steps.
4. What was the expected result? What actually happened?
5. What recent changes might have introduced this issue?
```

### Step 2: Analyze Error Type

Choose a debugging strategy based on error type:

| Error Type | Characteristics | Debugging Method |
|-----------|----------------|-----------------|
| **Syntax Error** | Code cannot be parsed | Check syntax, bracket matching, quotes |
| **Import Error** | ModuleNotFoundError | Check module installation, path config |
| **Type Error** | TypeError | Check data types, type conversions |
| **Attribute Error** | AttributeError | Check if object attribute exists |
| **Key Error** | KeyError | Check if dictionary key exists |
| **Index Error** | IndexError | Check list/array index range |
| **Null Reference** | NoneType/NullPointerException | Check if variable is None |
| **Network Error** | ConnectionError/Timeout | Check network connection, URL, timeout settings |
| **Permission Error** | PermissionError | Check file permissions, user permissions |
| **Resource Error** | FileNotFoundError | Check if file path exists |

### Step 3: Locate the Problem Source

Use the following methods to locate the issue:

**1. Binary Search Method**
- Comment out half the code, check if the problem persists
- Progressively narrow the scope until the problematic code is found

**2. Log Tracing**
- Add print/logging statements at key locations
- Track variable value changes
- Confirm code execution path

**3. Breakpoint Debugging**
- Use debugger breakpoint functionality
- Step through code execution
- Inspect variable state

**4. Stack Trace Analysis**
- Find the call chain from the stack trace in the error message
- Determine the direct cause of the error
- Trace back to the root cause

### Step 4: Form and Verify Hypotheses

**Hypothesis framework:**
```
Hypothesis: [problem description] causes [error phenomenon]

Verification steps:
1. [verification method 1]
2. [verification method 2]

Expected results:
- If hypothesis is correct: [expected phenomenon]
- If hypothesis is wrong: [expected phenomenon]
```

### Step 5: Apply Fix

After fixing, verify:
1. The original error is resolved
2. No new errors have been introduced
3. Related functionality still works correctly
4. Tests added to prevent regression

## Python Common Error Patterns

### 1. Indentation Errors
### 2. Mutable Default Arguments
### 3. Closure Issues in Loops
### 4. Modifying a List While Iterating
### 5. Using `is` for String Comparison
### 6. Forgetting to Call `super().__init__()`

## JavaScript/TypeScript Common Error Patterns

### 1. `this` Binding Issues
### 2. Async Error Handling
### 3. Object Reference Comparison

## Bash/Zsh Common Error Patterns

### 1. Spacing Issues

```bash
# ❌ No spaces allowed in assignment
name = "John"  # Error: tries to run 'name' command

# ✅ Correct assignment
name="John"

# ❌ Missing spaces in conditional test
if[$name -eq 1]; then  # Error

# ✅ Correct
if [ $name -eq 1 ]; then
```

### 2. Quoting Issues

```bash
# ❌ Variables not expanded inside single quotes
echo 'The value is $var'  # Output: The value is $var

# ✅ Use double quotes
echo "The value is $var"  # Output: The value is actual_value

# ❌ Using backticks for command substitution (confusing)
result=`command`

# ✅ Use $()
result=$(command)
```

### 3. Unquoted Variables

```bash
# ❌ Unquoted variable, empty value causes errors
rm -rf $dir/*  # If dir is empty, deletes all files in current directory

# ✅ Always quote variables
[ -n "$dir" ] && rm -rf "$dir"/*

# Or use set -u to prevent undefined variables
set -u  # or set -o nounset
```

### 4. Variable Scope in Loops

```bash
# ❌ Pipe creates subshell, outer variable unchanged
cat file.txt | while read line; do
    count=$((count + 1))  # Outer count won't change
done
echo "Total: $count"  # Outputs 0

# ✅ Use process substitution or redirection
while read line; do
    count=$((count + 1))
done < file.txt
echo "Total: $count"  # Correct output
```

### 5. Array Operations

```bash
# ❌ Incorrect array access
arr=(1 2 3)
echo $arr[1]  # Outputs 1[1]

# ✅ Correct array access
echo ${arr[1]}  # Outputs 2
echo ${arr[@]}  # Outputs all elements
echo ${#arr[@]} # Outputs array length
```

### 6. String Comparison

```bash
# ✅ Use `=` inside POSIX `[` tests and `==` inside Bash `[[ ]]` tests
if [ "$name" = "John" ]; then
if [[ "$name" == "John" ]]; then

# ❌ Using -eq for numeric comparison instead of =
if [ $age = 18 ]; then  # Wrong

# ✅ Use arithmetic operators for numeric comparison
if [ $age -eq 18 ]; then
if (( age == 18 )); then
```

### 7. Command Failure Continues Execution

```bash
# ❌ Execution continues after command failure
cd /nonexistent
rm file.txt  # Deletes file.txt in current directory

# ✅ Use set -e to exit on error
set -e  # or set -o errexit
cd /nonexistent  # Script exits he
code-reviewerSubagent

Expert code review specialist. Proactively reviews code for quality, security, and maintainability. Use immediately after writing or modifying code. MUST BE USED for all code changes.

kaggle-minerSubagent

Use this agent when the user provides a Kaggle competition URL or asks to learn from Kaggle winning solutions. Examples:

literature-reviewerSubagent

Use this agent when the user asks to "conduct literature review", "search for papers", "analyze research papers", "identify research gaps", "review related work", or mentions starting a research project. This agent integrates with Zotero for automated paper collection, organization, and full-text analysis. Examples:

paper-minerSubagent

Use this agent when the user provides a research paper (PDF/DOCX/arXiv link) or asks to learn writing patterns from papers, extract venue-specific writing signals, study paper structure, or mine rebuttal strategies. The agent writes extracted knowledge into the active installed paper-miner writing memory for ml-paper-writing. It does not maintain project-specific writing memory.

rebuttal-writerSubagent

Use this agent when the user asks to "write rebuttal", "respond to reviewers", "analyze review comments", or needs help with academic paper review response. This agent specializes in systematic rebuttal writing with professional tone and structured responses.

tdd-guideSubagent

Test-driven development guide for writing tests first, implementing the smallest passing change, and keeping verification tight. Use when the user explicitly wants TDD or when a task should be driven by failing tests before code.

analyze-resultsSlash Command

Run a blocker-first post-experiment workflow: validate evidence, produce strict statistical analysis when possible, and generate a decision-oriented results report only when the analysis bundle is sufficient. Uses results-analysis + results-report as a gated two-stage workflow.

commitSlash Command

Commit changes following Conventional Commits format (local only, no push).