skills/developer/code-intelligence/debug-with-ai/SKILL.md
Use this skill when debugging code with AI assistance. Activate when the user has a bug, error, unexpected behavior, needs to understand why code isn't working, wants to analyze stack traces, or is troubleshooting issues in their application.
npx skillsauth add latestaiagents/agent-skills debug-with-aiInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Structured debugging workflows using AI as your debugging partner.
┌───────────────────────────────────────────┐
│ 1. REPRODUCE - Can you trigger it? │
├───────────────────────────────────────────┤
│ 2. ISOLATE - Where exactly is the issue? │
├───────────────────────────────────────────┤
│ 3. UNDERSTAND - Why does it happen? │
├───────────────────────────────────────────┤
│ 4. FIX - Make minimal change to resolve │
├───────────────────────────────────────────┤
│ 5. VERIFY - Confirm fix, add test │
└───────────────────────────────────────────┘
Before asking AI for help, gather information:
## Bug Report
**What I expected:**
[Expected behavior]
**What actually happened:**
[Actual behavior]
**Error message (if any):**
[Full error message and stack trace]
**Steps to reproduce:**
1. [Step 1]
2. [Step 2]
3. [Step 3]
**Environment:**
- Node/Browser version:
- OS:
- Relevant packages:
**Code involved:**
```[paste relevant code]```
**What I've already tried:**
- [Attempt 1]
- [Attempt 2]
If you don't know where the bug is:
I have a bug somewhere in this code flow:
1. Function A calls Function B
2. Function B processes data and calls Function C
3. Function C returns result
The bug manifests as [description].
Here's the code:
```[paste relevant functions]```
Help me identify which function is most likely causing the issue
and what I should check first.
Explain this error and likely causes:
TypeError: Cannot read properties of undefined (reading 'map') at processItems (processor.js:45:12) at async handleRequest (handler.js:23:5)
Code at processor.js:45:
```[paste surrounding code]```
What are the most likely causes and how do I fix them?
This code doesn't behave as expected:
```[paste code]```
**Expected:** When input is X, output should be Y
**Actual:** Output is Z
Walk me through the code execution step by step
and identify where the logic diverges from my expectation.
This bug only happens sometimes:
```[paste code]```
**Symptoms:** [description]
**Frequency:** About 1 in 10 times
**Conditions:** Seems more common when [observation]
What could cause intermittent failures? Consider:
- Race conditions
- Timing issues
- External dependencies
- State management
- Caching
I've identified the bug:
**Problem:** [description of root cause]
**Current code:**
```[paste buggy code]```
**Context/constraints:**
- [Any constraints on the fix]
- [Backward compatibility needs]
Provide a minimal fix that:
1. Solves the immediate problem
2. Handles edge cases
3. Doesn't introduce new issues
Generate a test that would have caught this bug:
**Bug:** [description]
**Root cause:** [what was wrong]
**Fix:** [how it was fixed]
**Fixed code:**
```[paste fixed code]```
Create a test that:
1. Fails with the old buggy code
2. Passes with the fix
3. Covers the edge case that caused this
Symptom: Cannot read property 'x' of undefined
AI Prompt:
This code throws "Cannot read property 'items' of undefined":
```javascript
function processOrder(order) {
return order.items.map(item => item.name);
}
Identify all paths where order or order.items could be
undefined and provide defensive code.
### Async/Await Issues
**Symptom:** Function returns Promise instead of value, or undefined
**AI Prompt:**
```markdown
This async code doesn't work as expected:
```javascript
async function getData() {
const items = fetchItems(); // forgot await
return items.filter(i => i.active);
}
Error: items.filter is not a function
Find async/await issues and fix them.
### Race Conditions
**Symptom:** Works sometimes, fails other times
**AI Prompt:**
```markdown
This code has a race condition:
```javascript
let cache = null;
async function getData() {
if (!cache) {
cache = await fetchData(); // Multiple calls can start fetch
}
return cache;
}
Identify the race condition and provide a thread-safe solution.
### State Management Bugs
**Symptom:** UI shows stale data, updates don't reflect
**AI Prompt:**
```markdown
React component doesn't update when it should:
```jsx
function Counter() {
const [counts, setCounts] = useState({a: 0, b: 0});
const increment = (key) => {
counts[key]++; // Mutating state directly!
setCounts(counts);
};
}
Identify the state management issue and fix it.
## Debugging Tools Integration
### Console Debugging
```javascript
// Strategic logging
console.log('Function entry:', { input, state });
console.log('After processing:', { result });
console.trace('Call stack'); // Show call stack
console.table(arrayOfObjects); // Tabular display
debugger; // Pause execution here
// Conditional breakpoint (in DevTools)
// Right-click line → Add conditional breakpoint
// Condition: user.id === 'problematic-id'
console.time('operation');
// ... code to measure
console.timeEnd('operation');
// Or use Performance API
const start = performance.now();
// ... code
console.log(`Took ${performance.now() - start}ms`);
Good candidates for AI debugging:
Better to debug manually:
development
Test skills for correct activation, content quality, and regression — both automated checks (frontmatter validity, lint) and manual verification (query-suite activation testing). Covers CI integration and how to catch skill regressions before users do. Use this skill when adding skills to a repo, setting up CI for a skill library, or debugging "the skill exists but doesn't work". Activate when: test skills, validate skills, skill CI, skill linting, skill activation test, skill regression.
documentation
Write the YAML frontmatter for a SKILL.md file so it activates reliably — name, description, and activation keywords that the model matches against. Covers length, tone, and the most common frontmatter mistakes. Use this skill when authoring a new skill, fixing a skill that isn't auto-activating, or reviewing skills for publication. Activate when: SKILL.md frontmatter, skill description, skill activation, skill YAML, write a skill, author a skill.
development
Design skills that fire at the right moment — neither over-eager (noise) nor under-eager (silent). Covers activation specificity, trigger phrases, disambiguation between overlapping skills, and debugging activation. Use this skill when multiple skills could fire on the same query, a skill never fires, or a skill fires too often. Activate when: skill won't activate, skill over-activates, overlapping skills, skill triggers, skill selection, skill disambiguation.
development
Structure SKILL.md content so the model reads just enough — concise summary up front, progressively deeper detail, examples on demand. Covers section ordering, length budgets, when to split into multiple skills. Use this skill when writing or refactoring a skill body, one skill has grown too long, or a skill is wordy but not useful. Activate when: SKILL.md structure, skill content, skill too long, split skill, progressive disclosure, skill body.