mcpbeat Sign in

Static Bug Detector Agent Skill

Analyze source code statically to detect potential functional bugs including null dereferences, incorrect condition checks, unreachable code, inconsistent state updates, logic errors, resource leaks, and type mismatches. Report suspicious code locations with detailed explanations, severity levels, and confidence assessments. Use when reviewing code for bugs, performing code audits, or when the user asks to find bugs, detect issues, analyze code for problems, or perform static analysis.

8k tokens
context cost
the whole folder, loaded on every use
2
files
instructions only
0
copies elsewhere
how many repositories repackaged it
141
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill static-bug-detector

The instruction itself

29 sections, as written by the author

Static Bug Detector

Overview

Perform static analysis on source code to identify potential functional bugs. Detect common bug patterns, analyze control flow and data flow, and report suspicious locations with explanations, severity levels, and confidence assessments.

Bug Detection Workflow

Step 1: Understand the Code

Analyze the code structure and semantics:

  • Identify language:
  • Determine programming language
  • Understand language-specific semantics
  • Note language idioms and conventions
  • Parse code structure:
  • Functions/methods
  • Classes/types
  • Control flow (if, loops, etc.)
  • Data flow (assignments, returns)
  • Build context:
  • Variable declarations and types
  • Function signatures
  • Class hierarchies
  • Dependencies
  • Identify scope:
  • What code to analyze
  • Entry points
  • Critical paths

Step 2: Detect Bug Patterns

Scan for common bug patterns:

  • Null dereference bugs:
  • Variables from nullable sources
  • Dereferences without null checks
  • Null checks after use
  • Undocumented null returns
  • Incorrect conditions:
  • Always true/false conditions
  • Assignment in condition (= vs ==)
  • Redundant conditions
  • Inverted logic
  • Wrong operators
  • Unreachable code:
  • Code after return/throw
  • Always-false branches
  • Dead code paths
  • Inconsistent state:
  • Partial state updates
  • Updates without validation
  • Non-atomic operations
  • Broken invariants
  • Logic errors:
  • Off-by-one errors
  • Wrong operator precedence
  • Infinite loops
  • Incorrect boolean logic
  • Resource issues:
  • Resource leaks
  • Double free/close
  • Use after free/close
  • Type issues:
  • Type mismatches
  • Implicit coercion
  • Invalid casts

Step 3: Analyze Severity

Assess the impact of each bug:

High Severity:

  • Causes crashes or exceptions
  • Data corruption
  • Security vulnerabilities
  • Guaranteed runtime errors

Medium Severity:

  • Incorrect behavior
  • Potential errors (context-dependent)
  • Performance issues
  • Maintainability problems

Low Severity:

  • Code smells
  • Redundant code
  • Minor inefficiencies
  • Style issues that might hide bugs

Step 4: Assess Confidence

Determine confidence in the bug report:

High Confidence (90-100%):

  • Clear violation of language semantics
  • Guaranteed to cause error
  • Well-known bug pattern
  • No ambiguity

Medium Confidence (60-89%):

  • Likely bug but context-dependent
  • May be intentional in rare cases
  • Suspicious pattern
  • Needs verification

Low Confidence (30-59%):

  • Unusual but possibly valid
  • Could be intentional design
  • Needs more context
  • Style issue that might hide bug

Factors:

  • Code context available
  • Language semantics clarity
  • Pattern recognition
  • Documentation consistency

Step 5: Generate Report

Produce structured bug report:

  • For each bug:
  • Bug type/category
  • Location (file, line, range)
  • Severity level
  • Confidence level
  • Description
  • Why it's a bug
  • Potential impact
  • Recommendation/fix
  • Organize by:
  • Severity (high first)
  • Confidence (high first)
  • Location (file order)
  • Bug type (grouped)
  • Include:
  • Code context
  • Example fixes
  • Related bugs
  • Summary statistics

Bug Categories

For detailed patterns and examples, see detection_patterns.md.

Quick Reference

| Bug Category | Common Patterns | Severity | Detection Difficulty |

|--------------|----------------|----------|---------------------|

| Null Dereference | No null check, null after use | High | Easy |

| Incorrect Conditions | = vs ==, always true/false | High-Medium | Easy |

| Unreachable Code | After return, dead branch | Low | Easy |

| Inconsistent State | Partial update, no validation | High-Medium | Medium |

| Logic Errors | Off-by-one, wrong precedence | High-Medium | Medium |

| Resource Issues | Leaks, double close | Medium | Medium |

| Type Issues | Mismatch, implicit coercion | Medium-Low | Easy |

Examples

Example 1: Null Dereference

Input Code (Java):

public String getUserName(int userId) {
    User user = userRepository.findById(userId);
    return user.getName();
}

Analysis Output:

## Bug: Potential null dereference

**Location:** line 3
**Severity:** High
**Confidence:** High (95%)

### Description
Variable 'user' may be null but is dereferenced without null check.

### Why This Is a Bug
Method 'findById' may return null if user not found. Calling 'getName()'
on null will throw NullPointerException.

### Potential Impact
- Runtime NullPointerException
- Application crash
- Poor user experience

### Recommendation
Add null check before dereferencing:

public String getUserName(int userId) {

User user = userRepository.findById(userId);

if (user == null) {

return null; // or throw exception

}

return user.getName();

}


Or use Optional:

public Optional<String> getUserName(int userId) {

return Optional.ofNullable(userRepository.findById(userId))

.map(User::getName);

}

Example 2: Incorrect Condition

Input Code (C):

int status = getStatus();
if (status = SUCCESS) {
    printf("Operation successful\n");
}

Analysis Output:

## Bug: Assignment in condition

**Location:** line 2
**Severity:** High
**Confidence:** High (98%)

### Description
Using assignment operator '=' instead of comparison operator '==' in condition.

### Why This Is a Bug
Expression 'status = SUCCESS' assigns SUCCESS to status and evaluates to
SUCCESS value. This is almost always a typo for 'status == SUCCESS'.

### Potential Impact
- Condition always evaluates to true (if SUCCESS is non-zero)
- Original status value lost
- Logic error in program flow

### Recommendation
Change to comparison operator:

if (status == SUCCESS) {

printf("Operation successful\n");

}


Most compilers warn about this. Enable warnings: -Wall -Wextra

Example 3: Off-by-One Error

Input Code (Python):

def process_array(arr):
    for i in range(len(arr) + 1):
        print(arr[i])

Analysis Output:

## Bug: Off-by-one error (array index out of bounds)

**Location:** line 2-3
**Severity:** High
**Confidence:** High (100%)

### Description
Loop iterates one past the end of array, causing IndexError.

### Why This Is a Bug
range(len(arr) + 1) produces indices 0 to len(arr) inclusive. Array
indices are 0 to len(arr)-1, so arr[len(arr)] is out of bounds.

### Potential Impact
- IndexError exception
- Program crash
- Incorrect behavior

### Recommendation
Remove the +1:

def process_array(arr):

for i in range(len(arr)):

print(arr[i])


Or use idiomatic iteration:

def process_array(arr):

for item in arr:

print(item)

Example 4: Resource Leak

Input Code (Python):

def read_config(path):
    f = open(path)
    config = json.load(f)
    return config

Analysis Output:

## Bug: Resource leak

**Location:** line 2
**Severity:** Medium
**Confidence:** High (90%)

### Description
File opened but never closed, causing resource leak.

### Why This Is a Bug
File handle opened on line 2 is never closed. If exception occurs during
json.load or in normal execution, file remains open.

### Potential Impact
- File descriptor leak
- Resource exhaustion with many calls
- File locking issues on Windows

### Recommendation
Use context manager to ensure cleanup:

def read_config(path):

with open(path) as f:

config = json.load(f)

return config


Or ensure close in finally:

def read_config(path):

f = open(path)

try:

config = json.load(f)

return config

finally:

f.close()

Example 5: Inconsistent State Update

Input Code (Java):

public class BankAccount {
    private double balance;

    public void transfer(BankAccount target, double amount) {
        this.balance -= amount;
        // Missing: target.balance += amount
    }
}

Analysis Output:

## Bug: Incomplete state update

**Location:** line 5
**Severity:** High
**Confidence:** Medium (75%)

### Description
Transfer method deducts from source but doesn't add to target, leaving
system in inconsistent state.

### Why This Is a Bug
Money is removed from source account but never added to target account.
This violates the invariant that total money in system is constant.

### Potential Impact
- Money disappears from system
- Data corruption
- Accounting errors
- Loss of funds

### Recommendation
Complete the transfer operation:

public void transfer(BankAccount target, double amount) {

if (this.balance < amount) {

throw new InsufficientFundsException();

}

this.balance -= amount;

target.balance += amount;

}


Consider making atomic with synchronization or transactions.

Example 6: Unreachable Code

Input Code (JavaScript):

function calculate(x) {
    if (x < 0) {
        return -x;
    }
    return x;
    console.log("Calculated");  // Unreachable
}

Analysis Output:

## Bug: Unreachable code

**Location:** line 6
**Severity:** Low
**Confidence:** High (100%)

### Description
Statement is unreachable because function returns unconditionally on line 5.

### Why This Is a Bug
All code paths return before line 6. The console.log statement can never
execute, indicating dead code or logic error.

### Potential Impact
- Dead code clutters codebase
- May indicate incomplete refactoring
- Confusing for maintainers

### Recommendation
Remove unreachable code:

function calculate(x) {

if (x < 0) {

return -x;

}

return x;

}


Or if logging was intended, move before return:

function calculate(x) {

let result = x < 0 ? -x : x;

console.log("Calculated");

return result;

}

Report Format

Summary Section

# Static Analysis Report

**Files Analyzed:** X
**Bugs Found:** Y
**High Severity:** A
**Medium Severity:** B
**Low Severity:** C

## Summary by Category
- Null Dereference: X bugs
- Incorrect Conditions: Y bugs
- Unreachable Code: Z bugs
- Inconsistent State: A bugs
- Logic Errors: B bugs
- Resource Issues: C bugs
- Type Issues: D bugs

Individual Bug Reports

## Bug #N: [Bug Type]

**Location:** [File]:[Line] or [Line Range]
**Severity:** [High/Medium/Low]
**Confidence:** [High/Medium/Low] ([Percentage]%)

### Description
[What the bug is]

### Why This Is a Bug
[Explanation of the problem]

### Potential Impact
[What could go wrong]

### Recommendation
[How to fix it]

### Code Context

[Code snippet with line numbers]


### Example Fix

[Corrected code]

Best Practices

Analysis Guidelines

  • Be thorough: Check all common bug patterns
  • Be precise: Provide exact locations
  • Be clear: Explain why it's a bug
  • Be helpful: Suggest concrete fixes
  • Be honest: Indicate confidence levels
  • Be practical: Prioritize by severity
  • Be respectful: Avoid judgmental language

Reporting Guidelines

  • Prioritize: High severity and confidence first
  • Group: Related bugs together
  • Contextualize: Show relevant code
  • Explain: Why it's a bug, not just what
  • Suggest: Concrete fixes, not just problems
  • Quantify: Confidence and severity levels
  • Summarize: Overall statistics

Confidence Calibration

Report High Confidence when:

  • Clear language violation
  • Guaranteed runtime error
  • Well-documented bug pattern
  • No reasonable alternative interpretation

Report Medium Confidence when:

  • Suspicious but context-dependent
  • Likely bug but could be intentional
  • Requires domain knowledge
  • Multiple interpretations possible

Report Low Confidence when:

  • Unusual but possibly valid
  • Style issue that might hide bug
  • Insufficient context
  • Language-specific idiom

Limitations

What This Skill Can Detect

✅ Null dereferences

✅ Incorrect conditions

✅ Unreachable code

✅ Logic errors

✅ Resource leaks

✅ Type mismatches

✅ Off-by-one errors

✅ Inconsistent state updates

What This Skill Cannot Detect

❌ Concurrency bugs (race conditions, deadlocks)

❌ Performance issues (without profiling)

❌ Security vulnerabilities (requires specialized analysis)

❌ Design flaws (architectural issues)

❌ Business logic errors (requires domain knowledge)

❌ Integration issues (requires runtime context)

False Positives

Some reported bugs may be intentional:

  • Defensive programming patterns
  • Language-specific idioms
  • Framework conventions
  • Performance optimizations

Always verify bugs in context before fixing.

Resources

  • Detection patterns: See detection_patterns.md for comprehensive bug patterns and examples
  • Static analysis tools: Compare with automated tools (ESLint, PyLint, FindBugs, etc.)
  • Code review best practices: Guidelines for manual code review

Other skills for the same job

different authors, same section of the catalogue
Receiving Code Review
by ZhanlinCui
×7

Use when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation

2k tokens
Requesting Code Review
by ZhanlinCui
×6

Use when completing tasks, implementing major features, or before merging to verify work meets requirements

2k tokens
Git Commit
by github
vendor ×3

Execute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical grouping

799 tokens
Github Code Review
by ComeOnOliver
×3

Comprehensive GitHub code review with AI-powered swarm coordination

13k tokens
Karpathy Guidelines
by hyyhf
×3

Behavioral guidelines to reduce common LLM coding mistakes. Use when writing, reviewing, or refactoring code to avoid overcomplication, make surgical changes, surface assumptions, and define verifiable success criteria.

629 tokens
Code Reviewer
by google-gemini
vendor ×2

Use this skill to review code. It supports both local changes (staged or working tree) and remote Pull Requests (by ID or URL). It focuses on correctness, maintainability, and adherence to project standards.

795 tokens
Agent MD Refactor
by softaworks
×2

Refactor bloated AGENTS.md, CLAUDE.md, or similar agent instruction files to follow progressive disclosure principles. Splits monolithic files into organized, linked documentation.

4k tokens
Commit Work
by softaworks
×2

Create high-quality git commits: review/stage intended changes, split into logical commits, and write clear commit messages (including Conventional Commits). Use when the user asks to commit, craft a commit message, stage changes, or split work into multiple commits.

2k tokens

How to use it

Copy the folder

Take arabelatso/static-bug-detector from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.