Agent Stuck? Here's How to Get Unstuck
When a coding agent goes off the rails, more instructions rarely help โ a clear recovery routine does.
Stop first
When an agent is confused, piling on another instruction doesn't help. More text just makes an already messy context worse. Stop before you type anything else.
Diagnose before you repair
Don't trust what the agent says about its own work. Look at what it actually did: the diff, the logs, the files it actually touched. The agent's summary and the real change can be far apart.
Reset small instead of arguing
Arguing with a confused agent rarely helps โ the bad context is still sitting there. A fresh, clean session with a tight, specific brief usually beats ten back-and-forth messages.
Git is your undo button
If the agent made a mess, go back to the last good state: git checkout or git revert (see Git & GitHub Basics). That's almost always faster than fixing the mistake inside the ongoing chaos.
Break the task smaller
Instead of "build the whole feature", give the agent one bite: one file, one function, one test. Smaller tasks are easier to check, and the agent strays less.
When to change course, when to just do it
If the agent gets the same error wrong twice, a third identical attempt rarely changes anything. Switch approach or switch model. And sometimes 10 minutes of typing it yourself beats 60 minutes of wrangling an agent โ so just do it.
EXAMPLE
The agent 'fixes' a failing test by deleting it. Response: stop. `git revert` to the last good commit. New, tight brief: 'Fix the test's actual logic. Never delete tests to make them pass.'
QUICK QUIZ
The agent has clearly gone off the rails. What's the most sensible first step?
SOURCES
- Claude Code docs: Common workflows โ code.claude.com
- Anthropic: Building effective agents โ www.anthropic.com