The Deska blog
The Agent Broke My Code: A Calm Recovery Checklist
Step-by-step recovery guide for when an AI coding agent broke my code, covering Git triage, state management, and debugging tools.
· 11 min read
It happens to the best of us: you provide a prompt, the agent iterates through several files, and suddenly your build is failing. When an autonomous agent broke my code, the immediate reaction is often a mix of frustration and urgency. However, restoring stability requires a methodical approach rather than a series of panicked undos. This guide provides a technical checklist for developers to regain control of their codebase and understand why the agent deviated from the desired path.
Verify the Global State
Before touching any code, look at the high level state of your environment. AI agents often assume a clean slate, but side effects in the environment can cause persistent failures even after you revert the code.
- Check for zombie processes. Autonomous agents that run terminal commands might leave background workers or test runners active.
- Inspect temporary files. Agents creating documentation or JSON schemas may leave artifacts that interfere with your build tools.
- Validate environment variables. If the agent modified a
.envfile or exported a temporary variable to your shell session, your app might be behaving unexpectedly.
The Git Triage Strategy
Your version control system is your most important tool when an agent broke my code. If you are working with tools like Claude Code or Codex CLI, they perform many small edits across multiple directories.
The first step is a git status to see the blast radius. If the agent did not commit its work, you can see the uncommitted changes clearly. If the agent was instructed to commit as it went, you must look at the reflog. A common mistake is trying to manually fix the agent's errors by hand. Instead, use git checkout on specific files or git reset to return to the last known good state.
Isolating Agent Hallucinations in Logic
Sometimes the code looks syntactically correct, but the logic is subtly flawed. Agents might invent an API method that does not exist in your specific version of a library. They might also swap the order of operations in a way that creates race conditions.
To debug this, you need a high density of information. Using an infinite canvas allows you to place the original code side-by-side with the agent's modified version. When you can zoom out and see the entire flow of the logic across multiple files, the patterns of the "breakage" become more apparent.
Common Reasons Agents Fail
Understanding why the agent failed helps prevent it from happening again. Most failures fall into these categories.
- Context Windows: The agent lost track of a critical utility function defined at the top of a long file.
- Outdated Documentation: The agent is using its training data which might be two years old, while your library was updated last week.
- Dependency Conflicts: The agent added a package that conflicts with your existing peer dependencies.
When you use coding agents in a controlled environment, you can monitor these changes in real-time. Deska allows you to run agents like OpenCode or Claude Code in dedicated panels, where you can watch the terminal output as it happens.
Monitoring the Recovery
If you have to step away from your machine while a long build or a cleanup script is running, use a mobile app to monitor the progress. This ensures that you do not come back to a second round of errors. Monitoring the terminal output through a secure relay allows you to see if the recovery script failed early.
Local-First Security and Integrity
One reason recovery is often stressful is the fear of data loss or leaking sensitive keys during the "panic" phase. Working in a local-first environment means your files and sessions stay on your machine. You do not have to worry about the agent's broken code or your temporary debugging logs being cached on a remote server. This privacy allows you to experiment freely with fixes without exposing a broken or vulnerable state of your application.
Enhancing the Developer Workspace
A standard IDE is often too cramped for agent triaje. When you are managing multiple terminal sessions to fix what an agent broke, having a workspace where you can place terminals and code panels anywhere is essential. You might want one terminal running the broken test suite, one terminal for your Git commands, and a code editor panel showing the problematic diff.
Using Ask Deska can also speed up the recovery. You can ask the assistant to "open all files modified in the last 10 minutes" or "run the build and show me the errors in a new note." This allows you to orchestrate the recovery using voice or chat, reducing the cognitive load of manual navigation.
FAQ
How do I revert agent changes without losing my own recent work?
The best way is to use git add -p (patch mode). This lets you look at every hunk of code the agent changed and decide whether to keep it or discard it. If the agent committed its changes, use git revert followed by the commit hash to create a new commit that undoes those specific changes while preserving your own.
What should I do if the agent keeps making the same mistake?
This is usually a prompt engineering or context issue. Provide the agent with the specific documentation for the library version you are using. You can also use notes in your workspace to define "rules" for the agent, then point the agent to that file so it understands the constraints of your codebase.
Is it safe to let agents run commands in my terminal?
It is safe if you are using a tool that keeps everything local-first and allows you to see the output. You should always review the plan the agent proposes before it executes. If an agent broke my code, it was likely because a command had unintended side effects on the file system.
Get Back to Coding
If your current setup makes it hard to manage autonomous agents, try a workspace designed for them. Deska is a free desktop app for Mac, Windows, and Linux that provides the infinite canvas you need to visualize agent behavior and recover quickly from errors.
Download Deska to start building with a more resilient, agent-friendly workflow.