Try free

Last updated 13 October 2026

How to undo changes made by Claude Code

The reality of automated code edits

You are watching the terminal window as the agent moves through your project files. It uses the Edit tool on a controller, then the Write tool to create a new service, and finally the Bash tool to run your test suite. Suddenly, the screen fills with red text. A logic error in the new service has broken three unrelated modules. This is the moment where every developer feels a surge of anxiety. You need to stop the process and return your codebase to a functional state before you lose track of what happened.

Claude Code works directly on your local file system. It does not operate in a temporary branch or a virtual sandbox unless you specifically set your environment up that way. When the agent modifies a file, that change is written to your disk immediately. Because the agent can work much faster than a human, it can perform dozens of edits in a few seconds. Reverting these changes manually by clicking undo in your editor is slow and prone to error. You need a systematic way to handle these interruptions without losing your momentum.

Git as your primary safety net

Your most effective tool for undoing changes is git. Before you even start a session with the claude command, ensure your working directory is clean. Commit your current work or use git stash to clear the deck. Because Claude Code respects the .gitignore file, it will not interfere with your internal git tracking. If the agent makes a series of changes that you do not like, you can use the Bash tool inside the session to run git checkout or git reset commands. This is often the fastest way to wipe the slate clean while keeping the session open.

You can also use git from a separate terminal tab. If the agent is currently busy with a Task, you do not have to wait for it to finish. You can run git checkout followed by the specific filenames the agent just modified. This will restore the files to their last committed state. When the agent next tries to use the Read tool on those files, it will see the original content. This keeps your physical files safe even if the agent logic has gone off the rails.

Navigating session history with the Escape key

The interface provides a built-in mechanism to go back in time. If you realize the conversation has taken a wrong turn, press the Escape key twice in rapid succession. This action opens a history navigator that shows your earlier messages. You can scroll back through the exchange and select a specific point to resume from. This is useful when the agent misunderstands a requirement and spends several turns building the wrong feature. By jumping back, you remove those turns from the active context window.

It is vital to understand that pressing Escape twice only reverts the conversation state. It does not undo the physical file changes on your hard drive. If the agent used the Write tool to create ten files before you jumped back in history, those ten files still exist. You must combine the history jump with a git command to ensure your files match the state of the conversation. Use the Bash tool to delete any new files or revert any edits that happened after your selected jump-back point.

Interrupting and quitting sessions

Sometimes the agent enters a loop where it tries to fix a bug, fails, and then tries the exact same fix again. To stop the agent immediately, press the Escape key once. This interrupts the current tool use and returns control to the prompt. From here, you can give new instructions to steer the agent back on track. If the situation is beyond a simple correction, you can use Ctrl+C to quit the session entirely. This kills the process but leaves your files in whatever state they were in at the moment of the exit.

After quitting a messy session, you have choices on how to return. Running the claude command without flags starts a fresh session. If you want to try again with the same context but after you have manually cleaned up your files, use the claude --continue flag. This carries on the most recent session in that folder. If you want to see a list of all your previous interactions to find a specific starting point, use the claude --resume flag. This offers a list of earlier sessions to pick from, allowing you to bypass the mistakes made in the most recent one.

Using permission modes for safer editing

You can prevent the need for an undo by changing how the agent is allowed to interact with your code. Press Shift+Tab to cycle through the different permission modes. The default mode asks for permission for some actions but not all. The plan mode is the safest for experimental work. In plan mode, the agent will think through the problem and describe the changes it wants to make without actually using the Edit or Write tools. This gives you a chance to spot errors before a single line of code is changed.

If you are in the middle of a session and feel things are getting risky, switch to the acceptEdits mode. This forces the agent to ask for your explicit approval before it modifies any files. While this adds extra keystrokes to your workflow, it acts as a manual check. You can read the proposed diff and hit 'n' to deny the change if it looks wrong. This is much easier than trying to revert a complex set of changes after they have already been committed to the disk.

Configuring tool permissions in settings

You can make safety a permanent part of your project by editing the configuration files. The .claude/settings.json file in your project root allows you to define permissions for specific tools. You can find the permissions key and set tools like Bash or Write to always require manual approval. This ensures that even if you forget to switch modes with Shift+Tab, the agent cannot make major changes to your system without you seeing a prompt first.

If you share a repository with a team, you might want different safety settings than your colleagues. In this case, use the .claude/settings.local.json file. This file is for your own untracked overrides. You can set your personal permission levels here to be more restrictive. This is a good practice when you are first learning how the agent behaves. As you grow more comfortable with how it handles your specific tech stack, you can relax these permissions to allow for faster, more autonomous work.

Managing context to prevent recurring errors

The agent can sometimes get stuck because its context window is full of its own previous mistakes. Every session has a context window that fills with the conversation and the files the agent has read. If the agent keeps trying to use a tool that has failed five times already, that failure is part of its current memory. Use the /compact command to handle this. This command summarizes the session so far and frees up space. It distills the important progress while discarding the repetitive logs of failed attempts.

If the session is completely unrecoverable but you want to stay in the same terminal directory, use the /clear command. This starts the session over from scratch. It wipes the conversation history but leaves your files as they are. After a /clear, you can use the Bash tool to revert your files with git, and then start fresh with a new prompt. This is often better than trying to argue with an agent that is stuck in a logic loop caused by a messy context.

Monitoring multiple sessions with adhdTerminal

When you are working on a large project, you might have several Claude Code sessions running in different directories. Keeping track of which session is making which change can become overwhelming. This is where adhdTerminal provides a clear advantage. It is a native app for macOS and Windows that runs many sessions side by side as tiles on a wall. Each tile has a color, a number, and a name, showing you at a glance whether a session is working, waiting for you, or idle.

If a session in one tile starts producing errors, you can see the last exchanges of its conversation directly on the wall without switching terminal tabs. This high level view helps you catch bad edits early. Because tiles reopen in the same place after a restart and resume the same session, you can safely experiment in one tile, knowing that if you need to undo everything, the context and history are preserved and visible. This visibility reduces the cognitive load of managing multiple AI driven refactors at once.

Setting project boundaries in CLAUDE.md

The CLAUDE.md file is a powerful way to prevent the agent from making changes that require an undo. This file sits in your repo root and holds project instructions. You can use it to explicitly forbid the agent from touching certain sensitive files or directories. For example, you can tell the agent to always use the Read tool on a specific documentation file before it attempts an Edit on the core logic. This ensures the agent has the necessary context to do the job right the first time.

You can also use CLAUDE.md to define the specific Bash commands the agent should run to verify its work. If you instruct the agent to run your full test suite after every use of the Write tool, it will catch its own mistakes immediately. The agent will see the test failure in the terminal output and can attempt to fix the error before you even realize something went wrong. This proactive approach to safety turns the agent into a self-correcting system, significantly reducing the amount of time you spend manually reverting code.

Questions people ask

Does the /clear command undo the changes made to my source code files?

No, the /clear command only resets the conversation history and clears the context window. Any changes the agent made using tools like Edit or Write remain on your disk. You must use git checkout or a similar version control command to revert the actual file changes.

What happens to my files if I use the history navigator to go back?

Pressing Escape twice to go back in history only changes the agent's internal state and memory. It does not perform a file system rollback. You will have a mismatch between what the agent remembers and what is actually in your files, so you should manually revert your files using git to match that point in time.

Can I prevent Claude Code from ever deleting files without my permission?

Yes, you can manage this by editing the permissions section in your .claude/settings.json file. You can configure the agent to require manual approval for specific tools like Bash or Edit. Additionally, using the plan mode by pressing Shift+Tab ensures the agent only describes its intended actions without executing them.

Read next

More on claude code basics·All posts