Undo changes made by an AI coding agent
A step-by-step procedure to reverse an AI agent’s work without losing the parts that worked. Includes branch strategy and what version control cannot undo.
the short answer
Commit at each working step and keep irreversible actions outside version control so you can undo precisely what went wrong.

You give an agent a broad task and it executes quickly, but not always correctly. The fastest way back is to plan undoability before the agent starts, not after it finishes.
Start on a branch or separate checkout
Create a branch or a fresh checkout so the agent’s work stays isolated from main. A branch keeps the history clean and makes reverting a single change straightforward. If the agent will touch multiple repositories or services, give each its own branch or checkout so you can roll back per component without touching unrelated work.
Commit after every working step
After the agent completes a discrete piece of work and you verify it passes the tests, commit it. Include a clear message describing the change and why it works. These commits become the undo points. If the next step breaks something, you can reset to the last commit and try a different approach without losing the parts that already worked.
Example workflow
You ask the agent to add a new endpoint for user uploads. It writes the route handler, adds the schema, and updates the OpenAPI spec. You run the tests and they pass, so you commit with the message feat: add user upload endpoint. The agent then tries to add a database migration for a new table. The tests fail because the migration conflicts with an existing index. You reset to the previous commit, adjust the migration, and commit again before trying the agent’s next step.
Treat non-repository changes as irreversible
Code in a repository is easy to undo with git, but changes outside the repo are not. A database migration that runs in production alters data that git cannot revert. A deployed service that receives traffic from a new endpoint you did not intend to ship will keep serving requests until you deploy a fix. Messages sent by an agent to Slack or email cannot be recalled. Treat these actions as one-way doors and gate them with human permission before they happen.
If an agent must run a migration, review the SQL diff first and run it manually. If it must send a message, review the content and the recipient list before execution. Keep the agent’s ability to perform these actions disabled by default and enable it only when someone explicitly authorizes the step.
Use a shared workspace to coordinate undo points
When multiple agents work on the same codebase, coordinate their undo points in a shared workspace. Overlap warnings arrive when an agent claims work, which the shared workspace records for every agent. You can see which files each agent has touched and decide when to reset to a common commit. Without this coordination, one agent’s undo can undo another agent’s unrelated work, creating merge conflicts and lost progress.
You start an agent to refactor the user service and another to add a new feature that depends on the refactor. The refactor agent finishes its first safe commit and the feature agent starts. If the refactor agent later resets to an earlier commit to try a different approach, the feature agent’s work remains on top of the latest refactor commit, not the one you reverted. The shared workspace prevents the feature agent from building on code that no longer exists.
What to do when an undo is necessary
If you discover a mistake after the agent has committed, use git revert to create a new commit that undoes the changes. This keeps the history linear and avoids rewriting shared history. If the mistake is not yet committed, reset to the previous commit and discard the agent’s work. For changes already pushed, force-push only if the branch is not shared with others, otherwise revert and push the revert commit.
If the agent’s change introduced a data migration, roll back the migration with the database’s own tooling and restore from a backup if necessary. If the agent sent messages or triggered deployments, revoke any unintended permissions and notify the recipients. In each case, the undo path is specific to the system that was changed, not to git.
Gate irreversible actions to a person
Only humans should decide when to run migrations, send messages, or deploy services. Configure the agent’s permissions so it cannot perform these actions without explicit approval. A prompt like Apply the migration only if the diff matches the approved plan keeps the agent from running unchecked changes. When the agent requests permission, a human reviews the plan and either approves or rejects it, preventing accidental one-way changes.
You can also use a code review step to approve migrations before they run. The agent prepares the migration file, opens a pull request with the diff, and waits for a human to approve. Once approved, the migration runs. This adds a small delay but prevents the agent from altering production data without oversight.
When agents step on each other’s undo paths
Agents working on the same files can conflict when one undoes another’s changes. To avoid this, split the work so each agent owns a distinct set of files or uses its own branch. If overlap is unavoidable, use a shared workspace to declare intentions before editing. The workspace records which agent is working on which file, so you can see who will be affected if you revert a commit.
Overlap warnings arrive when an agent claims work, which the shared workspace records for every agent. You can then decide whether to pause one agent, proceed with caution, or revert to a point before the overlap began.
Plan the undo path before the agent starts
Before you run an agent on a broad task, decide how you will undo each step. Identify the irreversible actions and require human approval for them. Set up branches or checkouts so the agent’s work is isolated. Write down the commit points you expect to use as undo targets. If the agent’s scope is too large to undo safely, break it into smaller tasks and commit after each one. A well-planned undo path is the difference between a quick recovery and a day spent untangling mistakes.
If you routinely work with agents on large changes, consider a tool like Concord AI to keep a shared record of each agent’s intentions and decisions. The shared workspace logs which agent made which change and why, so you can reconstruct the undo path even if the git history is messy. This is especially useful when multiple agents contribute to the same feature and one needs to roll back part of the work without losing the rest.
The safest undo is the one you never have to use. Make each agent’s task small enough to verify at each step, commit after every working change, and keep irreversible actions under human control. That way, when the agent inevitably makes a mistake, you can undo precisely what went wrong without losing the parts that worked.