Try free

Last updated 13 October 2026

Separating Claude Code tasks into sessions

Context window limits cause confusion

When you start a session with Claude Code, the agent begins filling its context window with your project files and the conversation history. If you try to fix a database bug and refactor a React component in the same session, the agent eventually loses track of the earlier details. The conversation grows long and the token count rises quickly. This lead to the agent suggesting changes based on outdated context or getting confused about which file it is currently editing.

Context contamination occurs when the history of one task influences the solution for another unrelated task. If the agent reads a specific utility file to fix a bug, it might try to use that same utility for a new feature where it does not belong. Separating your work into distinct sessions prevents this overlap. Each session starts with a clean slate or a focused history that keeps the agent's attention on the specific problem at hand.

Managing sessions with built-in flags

You can handle multiple streams of work by using the built-in session management flags. When you run the claude command, it starts a fresh session in your current directory. If you need to stop and come back later, you can use claude --continue to pick up exactly where the last session left off. This is useful for long-running feature development where you need to maintain a deep history of changes and decisions.

If you are working on several different tasks at once, use claude --resume to see a list of previous sessions. This command offers a menu where you can pick a specific conversation to restore. This allows you to jump back into a specific context with all the previous file reads and edits intact. It is a much better approach than trying to explain a complex problem to the agent multiple times in new sessions.

Folder-based isolation for complex projects

Claude Code looks at the current directory to determine its scope. If you have a large monorepo, you can run the claude command from different subdirectories to keep the agent focused. Running the command in a specific folder restricts the agent's view. This keeps the file history relevant to that specific module. It prevents the agent from reading unrelated files in the root directory unless you explicitly tell it to do so.

If you use adhdTerminal, these sessions persist even after you restart the application. The app reopens your tiles in the same position and resumes the specific session for each project. This is a native app for macOS and Windows that helps you keep track of your task wall without manually managing terminal history. It uses an encrypted link to mirror your wall to an iPhone app so you can check the status of a long task while you are away from your desk.

Control through project instruction files

You can use CLAUDE.md files to guide the agent across these different sessions. A CLAUDE.md file in the root of your repository provides global instructions that apply to every session you start in that project. If you have specific rules for a sub-module, you can place another CLAUDE.md in that subdirectory. The agent reads these files to understand the coding standards and build commands relevant to that specific part of the tree.

These files are the best place to store information that should persist across sessions. You can include common terminal commands for testing or specific linting rules. This ensures that even if you start a completely new session using the /clear command, the agent immediately knows how to interact with your codebase correctly. It reduces the amount of manual setup you need to do every time you switch tasks.

Context window management and cleanup

Long sessions eventually hit the context limit of the underlying model. When this happens, the agent may struggle to process new information or maintain accuracy. You can use the /compact command to summarize the conversation so far. This frees up space in the context window while keeping a high-level overview of what has been accomplished. It is a vital tool for maintaining performance during extended development sessions.

If a session becomes too cluttered with failed attempts or irrelevant logs, the /clear command lets you start over in the same folder. This removes the conversation history but keeps the agent in the current directory. If you just want to see how much you have spent on a specific task, use the /cost and /usage commands. These provide transparency on your resource consumption for the current session and your overall account.

Visual session management for multiple tasks

Switching between many terminal tabs and remembering which one holds which bug fix is difficult for many developers. adhdTerminal solves this by running many Claude Code sessions side by side as tiles on a single screen. Each tile shows the last few lines of the conversation and the current status of the agent. You can name a tile after the specific feature you are building and give it a unique color.

This visual wall allows you to see at a glance if a long-running task is waiting for your input or if it has finished the work. You can see which sessions are idle and which ones are actively working on a task. This setup is particularly helpful when you are managing subagents or running complex bash scripts that take time to complete. It turns a messy collection of terminal windows into an organized dashboard of active development.

Safety through explicit permission modes

When you run multiple sessions, you might forget which session has permission to edit your files. You can cycle through permission modes using Shift+Tab inside any session. The default mode asks for permission before the agent uses a tool like Write or Edit. This is the safest way to work when you are switching between different parts of a sensitive codebase.

If you are confident in a specific session, you can switch to acceptEdits to let the agent work faster without constant interruptions. Using the plan mode allows the agent to think through a complex problem across multiple files without making any actual changes. You can review the proposed plan before allowing any tools to modify your source code. This granular control is essential for managing risk across several simultaneous tasks.

Configuration of session boundaries

You can further isolate session behavior by modifying the configuration files. The .claude/settings.json file in your project directory stores settings that apply to everyone working on that repo. For your own personal session preferences, you can use .claude/settings.local.json. These files allow you to define which tools the agent can use and which files it should ignore beyond the standard .gitignore rules.

If you want specific tools to be restricted in all your sessions, you can edit the permissions section in these files. For example, you might want to allow the Read tool globally but require manual approval for the Bash tool. This level of control ensures that each session follows the specific security and operational boundaries you define for your environment. You can also manage MCP servers using the claude mcp command to extend the agent's capabilities in specific sessions.

Efficiency with custom commands and agents

To make switching between sessions even faster, you can define custom slash commands. These are markdown files stored in the .claude/commands directory. A custom command can trigger a specific sequence of tool uses or provide the agent with a templated set of instructions for a recurring task. This reduces the amount of typing required to get a new session up to speed on a familiar problem.

You can also use subagents by creating markdown files in the .claude/agents directory. Subagents can handle specialized tasks within a larger session, allowing you to delegate specific parts of a feature to a more focused context. When you finish a session, you can use /export to save the conversation history for your records. This is helpful for documentation or for sharing the logic behind a complex change with your team.

Questions people ask

How do I stop an agent that is currently writing too much code?

Press the Escape key to interrupt the agent while it is working. If you need to go back to a previous point in the conversation, press Escape twice to see a list of earlier messages. This allows you to reset the state to a point before the unwanted changes occurred.

Can I apply the same rules to every project I work on?

Yes, you can create a file at ~/.claude/CLAUDE.md to hold global instructions. This file applies to every session you run on your machine regardless of the project folder. Use this for your general coding preferences or common library documentation that you use across different repositories.

What should I do if a session becomes too slow or unresponsive?

Use the /doctor command to check the health of your installation and connection. If the issue is related to the length of the conversation, use /compact to reduce the context size. This keeps the session running efficiently by summarizing the history and freeing up memory for new tasks.

Read next

More on claude code basics·All posts