Last updated 13 October 2026
How to resume a previous Claude Code session
Managing context during long refactoring tasks
You are halfway through a complex refactor when your terminal closes or you need to switch branches for an urgent bug fix. Losing the mental model and the progress of a coding agent is a major setback in your workflow. You do not want to explain the entire architectural pattern or the specific variable constraints to the agent a second time. When you work with a terminal agent, the history of what has been discussed and which files have been modified is your most valuable asset.
A coding session is more than just a list of commands. It is a stateful environment where the agent has already used the Read and Glob tools to understand your project structure. If you start a fresh session, the agent loses the knowledge of why a certain change was made or what errors it encountered during the last test run. You need a way to pick up exactly where the last message ended without repeating your instructions or re-uploading context. This is especially true for tasks that span several hours or even days across different work sessions.
The ability to resume a session allows you to maintain a continuous loop of development. You can leave a task on Friday and return to it on Monday with all the previous Bash outputs and Edit operations preserved in the history. This persistence ensures that the agent does not repeat mistakes it already learned to avoid earlier in the conversation. By correctly using the built-in session management features, you turn a ephemeral command line tool into a persistent development partner that remembers the nuances of your codebase.
Reopening the most recent session quickly
The fastest way to get back into your work is by using the continue flag. When you run the command claude with the continue flag, the agent looks for the very last session that occurred in your current folder. This is the most common way to resume work after a short break or a terminal restart. You can use the short version of the flag, which is -c, to save time. This command skips the initial setup and immediately loads the context of your most recent conversation.
Using the continue flag is ideal when you are working in a single repository and only have one active task. It reloads the conversation history and the agent becomes aware of the files it was previously working on. If you were in the middle of a multi-step plan using the Task tool, the agent will remember which steps are finished and which ones are still pending. This allows for a seamless transition back into the coding logic without any manual catch-up required from your side.
It is important to remember that this command is directory-specific. If you move to a different project folder and run the command with the continue flag, it will look for the last session associated with that new directory. If no previous session exists in that folder, it will not be able to resume. Always ensure you are in the root of your project where the .claude directory or your repository metadata is located before attempting to continue a session.
Selecting a specific session from history
Sometimes the most recent session is not the one you need. You might have started a quick experiment in the same folder that took over the primary slot in the history. In these cases, the resume flag is the correct tool to use. Running the command claude with the resume flag, or the -r shortcut, will present you with a list of earlier sessions. This list usually includes a timestamp and a brief summary of what happened in each session, making it easier to identify the correct point in time.
Picking a session from the history list restores the full state of that specific interaction. This is useful when you are managing multiple feature branches or if you need to go back to a conversation from several days ago. Once you select a session from the list, the agent loads the conversation history and you can continue as if you never left. This prevents the frustration of searching through terminal scrollback to find out what you were doing last week.
The session history is stored locally on your machine. This means you can return to a task even if you have rebooted your computer or updated your terminal software. The agent uses the information stored in your user directory to rebuild the context window. This local storage ensures that your session data remains private and is always available when you are working on your primary development machine.
Switching sessions within an active interface
You do not have to quit your current session to jump to a different one. If you are already inside an interactive session, you can use the resume slash command. This command opens the same selection menu as the resume flag but keeps you within the existing interface. It is a powerful way to pivot between different parts of a project without restarting the agent process. This saves time on loading the model and initializing the environment.
Using the resume command internally is helpful when you realize the current path of the conversation is not leading to the right solution. Instead of trying to fix a messy context, you can simply resume a version of the session from an hour ago. This acts like a checkpoint system for your coding tasks. You can branch off into different experiments and always have a way to return to a known good state in the conversation history.
When you use this command, the agent clears the current context and replaces it with the history of the selected session. Any unsaved changes in the agent's internal memory that were not written to files will be lost, so make sure you have committed your progress or used the Write tool if necessary. This internal switching makes the agent feel more like an integrated part of your development environment rather than a one-off command line utility.
Maintaining context window space with summaries
As a session grows longer, the context window fills up with file contents and conversation history. A very long session can eventually reach the limits of the model, which might lead to performance issues or higher costs. To handle this, you can use the compact slash command. This command summarizes the conversation so far and removes the redundant details while keeping the essential technical decisions and progress markers.
Compacting a session is a great way to keep a resumed task focused. If you have been working on a refactor for a long time, the history might be full of minor Bash errors or old file reads that are no longer relevant. By running the compact command, you clean up the history so the agent has more space to process new information. This is particularly useful after you have successfully completed a large chunk of work and are ready to move on to the next phase of the project.
The agent also has internal hooks like PreCompact that can trigger before this process happens. This ensures that the state of the conversation is preserved in a way that remains useful for the agent. Regularly compacting your long-running sessions prevents the context from becoming a wall of noise. It allows you to maintain a single session for an entire feature development cycle without losing the core intent of the original instructions.
Using persistent tiles for project organization
Keeping track of multiple sessions in different terminal tabs can lead to confusion. This is where adhdTerminal provides a more structured approach for developers who handle several tasks at once. The app organizes your work as a wall of tiles, where each tile represents a specific session. Each tile has its own color, number, and name, allowing you to visually identify different parts of your project without reading terminal titles.
A major benefit of this setup is that tiles stay in the same place even after a system restart. You do not need to remember which directory you were in or which flag to use to resume your work. The app automatically handles the resumption of the session in the background. When you open your computer, your workspace is exactly how you left it, with the status of each task clearly visible on the tile, such as whether it is idle or waiting for your input.
This visual organization reduces the mental load of context switching. If you are waiting for a long build process in one session, you can glance at your wall of tiles to see which other task needs your attention. By using adhdTerminal, you turn the command line experience into a persistent dashboard. This makes it much easier to manage long-running refactors across different repositories without losing your place in the workflow.
Defining project instructions for consistent behavior
Every time you resume a session, the agent needs to know the rules of your project. This is handled by the CLAUDE.md file. When placed in the root of your repository, this file provides the primary instructions for the agent. It should contain information about your build commands, testing patterns, and coding style. Because this file is read at the start of every session, it ensures that even a resumed conversation follows your established standards.
You can also use a CLAUDE.md file in a subdirectory to provide more specific instructions for that part of the tree. For example, if your frontend and backend have different linting rules, the agent will pick up the correct instructions based on which directory it is working in. There is also a global version of this file located in your user home directory at ~/.claude/CLAUDE.md which applies to every session you run on your machine.
By keeping your instructions in these markdown files, you make your sessions more resilient. You do not have to repeat your preferences every time you use the resume flag. The agent will always know to use the Grep tool to find symbols or to run specific Bash scripts for your tests. This creates a stable environment that persists across different sessions and makes the resumption process much smoother.
Handling interruptions and correcting session flow
Sometimes a session needs to be resumed because something went wrong during a tool execution. If the agent is stuck in a loop or starts writing the wrong code, you can use the Escape key to interrupt it immediately. This stops the current tool and returns control to you. If you need to go back further, pressing the Escape key twice allows you to select a previous message in the history and restart from that point.
This ability to step back within a session is a form of micro-resumption. It prevents a single mistake from ruining a long and productive conversation. Instead of starting a whole new session with the clear command, you just roll back to the last good state. This keeps your context clean and ensures that the agent only remembers the correct steps toward the solution. It is a vital tool for maintaining the quality of a long-running refactoring job.
If the agent is completely unresponsive, you can use Ctrl+C to quit the terminal process entirely. Because the session history is saved, you can then use the continue flag to jump back in. The agent will be aware that the previous session ended abruptly and you can provide a new prompt to get it back on track. This combination of local interruptions and session persistence gives you total control over the development process.
Configuring permissions for automated task execution
Your settings also influence how a resumed session behaves. The settings.json file in the .claude directory of your project allows you to define permission modes. If you are resuming a long task where you trust the agent, you can switch to the bypassPermissions mode. This allows the agent to use tools like Edit and Write without asking for your approval every time. This significantly speeds up the work when you are not actively watching the terminal.
You can also control permissions on a per-tool basis in your settings. For example, you might allow the Read and Glob tools to run automatically but require a prompt for the Bash tool. These configurations are preserved when you resume a session. This means your security and workflow preferences remain consistent throughout the entire lifecycle of a project task. You can find these settings in the project folder or in your global user settings.
If you need to change these settings while a session is active, you can use the config slash command. This allows you to toggle modes or update your preferences without having to restart. By properly managing your settings.json and your session history, you create a highly efficient coding environment. The agent becomes a tool that you can pick up and put down as needed, always maintaining the context and permissions required for your specific development goals.
Questions people ask
Can I see the cost of a session after I have resumed it?
Yes, you can use the cost or usage slash commands at any time. These will show you the total spend for the current session, including the parts from before you resumed. This helps you track the budget for long refactoring jobs that span multiple days.
What happens if I try to continue a session in a folder with no history?
The agent will notify you that no previous session was found in that directory. In this case, it will start a fresh session as if you had run the command without any flags. Always make sure you are in the correct root directory of your project before using the continue or resume flags.
Does the agent remember files it read in a previous session?
When you resume a session, the agent remembers which files were in its context window. However, it may need to use the Read tool again to ensure it has the most recent version of the code if the files have changed on disk since the last interaction. The conversation history will still show the previous file contents it worked with.
Read next
- Add build instructions to your CLAUDE.md fileImprove project context by adding specific build commands and environment requirements to your CLAUDE.md file for the AI to follow.
- Add common error fixes to CLAUDE.mdImprove project memory by adding a section for common errors and their fixes to your CLAUDE.md configuration file.
- Add custom shell aliases for Claude CodeSpeed up your workflow by creating shell aliases for common Claude Code invocations and project-specific startup commands.
- Add test commands to a CLAUDE.md fileUnderstand how to define specific test runners and environment flags in your CLAUDE.md file so the tool runs the correct test suite.