Your error message shows up. You copy-paste it to ChatGPT. You get a generic answer. You waste 20 minutes. We can do better.
The problem? Most of us treat AI as a search engine substitute instead of a debugging partner. Here's how to actually integrate AI into your workflow so it catches stuff before production.
The Setup That Actually Works
Install these locally (no cloud required):
# Ollama for local LLM (runs on your machine)
brew install ollama
ollama pull neural-chat
# Or use your existing API if you prefer
export OPENAI_API_KEY=your_key_here
Create a .debug directory in your project:
.debug/
├── error-context.md
├── logs/
└── snapshots/
The Workflow
Step 1: Capture Context, Not Just Errors
When something breaks, don't just grab the error. Grab context:
# Create a debug snapshot
echo "## Error at $(date)" > .debug/error-context.md
echo "### Stack Trace" >> .debug/error-context.md
your-app-command 2>&1 | tee -a .debug/error-context.md
# Add recent changes
echo "### Recent Commits" >> .debug/error-context.md
git log --oneline -5 >> .debug/error-context.md
# Add environment
echo "### Environment" >> .debug/error-context.md
env | grep -E "NODE|PYTHON|DB_" >> .debug/error-context.md
This file becomes your AI's input. It's everything the AI needs to help you.
Step 2: Ask the Right Question
Wrong: "Why am I getting this error?"
Right: "Given this context, what changed recently that could cause this? What should I check first?"
# If using local AI
cat .debug/error-context.md | ollama run neural-chat "Analyze this error with context. What's the most likely cause? What do I test first?"
# If using API
curl https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-4",
"messages": [{
"role": "user",
"content": "'"`cat .debug/error-context.md`""'
Dont give me generic debugging steps. Tell me specifically what changed that caused this."
}]
}'
The difference: you're not asking "what's wrong" — you're asking "given what you see, what's the fastest fix?"
Step 3: Verify Before You Trust
AI can be confidently wrong. Add a verification step:
# Before you apply the fix, test it in isolation
# Example: if AI says "check your DB connection"
npm test -- --grep "database.*connection"
# Or reproduce with minimal code
cat > .debug/test-hypothesis.js << 'EOF'
// Test only the thing AI suggested
const db = require('./db');
db.connect().then(() => {
console.log('Connection works');
process.exit(0);
}).catch(err => {
console.error('Connection fails:', err.message);
process.exit(1);
});
EOF
node .debug/test-hypothesis.js
If the fix works in isolation, apply it. If it doesn't, you have evidence to push back on the suggestion.
Real Example: The Silent Cache Bug
Your API returns stale data. You check Redis, it's fine. You check the code, it's fine. Classic.
Your debug file captures:
- The exact response with timestamp
- Your recent refactor (moved cache invalidation logic)
- Environment config
- Server logs from the time it happened
You ask the AI: "I moved cache invalidation to a different function last Tuesday. The timestamps show the data got cached after my change. What did I miss?"
AI responds: "You're probably invalidating in the old location. Check if you have two cache implementations."
You grep for it. Found it. 30 seconds instead of 30 minutes.
Tools That Actually Help
Local options (privacy + speed):
- Ollama + neural-chat: Free, runs on your machine
- LM Studio: GUI wrapper, easier to use
API options (more power):
- Claude (Anthropic): Best for understanding weird edge cases
- GPT-4: Fast, good for quick questions
- Sonnet (Claude 3.5): Sweet spot for most bugs
Pick one and stick with it. You'll learn how to ask it better questions.
The Habit
- Error happens
- Grab context (30 seconds)
- Ask AI with the context (1 minute)
- Test the hypothesis (2-5 minutes)
- Apply the fix or dig deeper
Boring? Yes. Effective? Also yes.
The magic isn't the AI. It's the context. Most of us give AI 5% of the information it needs. That's why the answers are generic. Give it 95% and you'll be shocked how specific the advice becomes.
Want practical tips on building better dev workflows? Check out LearnAI Weekly — real strategies for actually shipping faster, not just hype.
Happy debugging.
Top comments (0)