- Claude's working memory, known as the
context window, has a finite capacity, making efficient management crucial for optimal performance and preventing loss of detail. - Users can manually manage context using commands like
/compactto summarize past interactions or/clearto completely reset the session, depending on whether they need to retain memory or start fresh. - Optimizing context involves writing specific prompts, leveraging tools like
CLAUDE.mdfor persistent memory, and using specialized features such asskillsorsub agentsto control what Claude processes.
Context Management in Claude Code
- The
context windowis a finite memory space where Claude processes all input (files, commands, messages), and it's important to optimize its usage. Compactionautomatically or manually (/compact) summarizes important details and removes unnecessary information from the context window, freeing up space but potentially losing minor details.- Use
/clearto completely remove all previous context and start a new session from scratch without any memory of prior interactions. - Monitor your current context size, categories taking up the most space, and a visual representation using the
/contextcommand. - When continuing a specific feature, use
/compactto maintain relevant context; when starting a new feature, use/clearto prevent bias from previous conversations. - Store information Claude should remember across multiple sessions in the
CLAUDE.mdfile to avoid rediscovery. - Write specific and explicit prompts to reduce Claude's need to explore the codebase and consume more context window space.
- Disable unnecessary
MCP serversas they load all available tools into context by default, or useskillswhich offer similar functionality without consuming as much context. - Utilize
sub agentsfor tasks that only require an answer without the "journey," as they run with a separate context and return only a summary to the main agent.
context window — The finite memory space in an AI agent like Claude that holds all the information it's currently processing, including prompts, file contents, and tool results.
compaction — A process, either automatic or manually triggered by /compact, that summarizes past interactions and removes less important details from the context window to free up space.
prompt — The input text or query provided by a user to an AI agent to initiate a task or conversation.
tool call — An action initiated by the AI agent to execute an external function or interact with a specific tool.
CLAUDE.md — A specific markdown file where users can store information they want Claude to remember and access across different sessions.
MCP servers — A mechanism that loads all available tools into the AI's context by default, which can consume significant context window space.
skills — An alternative to MCP servers that provides tool-like functionality but is more efficient with context, as it doesn't load the entire tool into memory.
sub agents — Secondary AI agents that operate in parallel with the main agent, each having its own separate context window, often used to delegate specific tasks and return summarized results.
Context is Claw's working memory. Every file it reads, every command it runs, every message you send, it all takes up space in the context window. Think of the context window as the amount of space that Claude could hold in his memory. Whenever you enter a prompt, Claude reads a file, runs a tool call, gets a tool call result. This is added on to the context window. And since there's only a finite amount you can put in the context window, it becomes extremely important to optimize this as much as possible. Now, when you approach this limit, the context window is automatically compacted. Compaction will summarize important details and remove the unnecessary tool call results and free up a lot of space in your context window. Do note though that this could potentially lose details in your previous conversation. You can run the compaction manually as well with the /compact command. This will compact everything that you've done up to that point, which could be handy if you want to clear up context space, but also have a memory of what you previously worked on. If you want to completely start from scratch without memory of what was previously worked on, you can also run /cle and that will remove everything starting from scratch. To check the state of your context, run the /context command. Here you'll get a big picture of how large your context size is, the different categories that are taking up the most context, and a graphic showing you all of this. A general rule of thumb is when you're working on a specific feature and are going over the context window, but need to continue, then compact. Keeping the context relevant for this feature is important when continuing development. If you have finished the plan and want to start on a new feature, then clear. You don't want the previous conversation to present bias in anything new that you want to create. For things that you do want Claude to remember in other sessions, put it in the CLAUDE.md file. That way, it doesn't have to rediscover things from scratch all over again. Be specific. The irony behind writing a smaller prompt is that it in the long run, it will take up more context. Without being explicit, Claude is forced to look around your codebase more and do its own thinking, which takes up a lot more context. window space than if you were just a little bit more clear with a sentence or two. MCP servers load all of the tools available into context by default. So, if you have a lot of MCP servers for things that are unrelated to the project, it might be worth turning them off. You can also try out skills, which works similarly to MCP servers, but doesn't put the entire thing into context, saving you space. Sub agents run in parallel with your main agent but has a complete separate context window. So for tasks that require an answer without the journey like where is the authentication endpoints located, you can have the sub agent do the work and return just a summary to your main agent. Managing context within Claude Code is crucial. Use slash compact to summarize long sessions and slashclear to start fresh. To use your context window effectively, be specific with what you want. Check what's using your current context window and use sub agents to delegate tasks you only need the answer for.
TL;DR
- Claude's working memory, known as the
context window, has a finite capacity, making efficient management crucial for optimal performance and preventing loss of detail. - Users can manually manage context using commands like
/compactto summarize past interactions or/clearto completely reset the session, depending on whether they need to retain memory or start fresh. - Optimizing context involves writing specific prompts, leveraging tools like
CLAUDE.mdfor persistent memory, and using specialized features such asskillsorsub agentsto control what Claude processes.
Takeaways
- The
context windowis a finite memory space where Claude processes all input (files, commands, messages), and it's important to optimize its usage. Compactionautomatically or manually (/compact) summarizes important details and removes unnecessary information from the context window, freeing up space but potentially losing minor details.- Use
/clearto completely remove all previous context and start a new session from scratch without any memory of prior interactions. - Monitor your current context size, categories taking up the most space, and a visual representation using the
/contextcommand. - When continuing a specific feature, use
/compactto maintain relevant context; when starting a new feature, use/clearto prevent bias from previous conversations. - Store information Claude should remember across multiple sessions in the
CLAUDE.mdfile to avoid rediscovery. - Write specific and explicit prompts to reduce Claude's need to explore the codebase and consume more context window space.
- Disable unnecessary
MCP serversas they load all available tools into context by default, or useskillswhich offer similar functionality without consuming as much context. - Utilize
sub agentsfor tasks that only require an answer without the "journey," as they run with a separate context and return only a summary to the main agent.
Vocabulary
context window — The finite memory space in an AI agent like Claude that holds all the information it's currently processing, including prompts, file contents, and tool results.
compaction — A process, either automatic or manually triggered by /compact, that summarizes past interactions and removes less important details from the context window to free up space.
prompt — The input text or query provided by a user to an AI agent to initiate a task or conversation.
tool call — An action initiated by the AI agent to execute an external function or interact with a specific tool.
CLAUDE.md — A specific markdown file where users can store information they want Claude to remember and access across different sessions.
MCP servers — A mechanism that loads all available tools into the AI's context by default, which can consume significant context window space.
skills — An alternative to MCP servers that provides tool-like functionality but is more efficient with context, as it doesn't load the entire tool into memory.
sub agents — Secondary AI agents that operate in parallel with the main agent, each having its own separate context window, often used to delegate specific tasks and return summarized results.
Transcript
Context is Claw's working memory. Every file it reads, every command it runs, every message you send, it all takes up space in the context window. Think of the context window as the amount of space that Claude could hold in his memory. Whenever you enter a prompt, Claude reads a file, runs a tool call, gets a tool call result. This is added on to the context window. And since there's only a finite amount you can put in the context window, it becomes extremely important to optimize this as much as possible. Now, when you approach this limit, the context window is automatically compacted. Compaction will summarize important details and remove the unnecessary tool call results and free up a lot of space in your context window. Do note though that this could potentially lose details in your previous conversation. You can run the compaction manually as well with the /compact command. This will compact everything that you've done up to that point, which could be handy if you want to clear up context space, but also have a memory of what you previously worked on. If you want to completely start from scratch without memory of what was previously worked on, you can also run /cle and that will remove everything starting from scratch. To check the state of your context, run the /context command. Here you'll get a big picture of how large your context size is, the different categories that are taking up the most context, and a graphic showing you all of this. A general rule of thumb is when you're working on a specific feature and are going over the context window, but need to continue, then compact. Keeping the context relevant for this feature is important when continuing development. If you have finished the plan and want to start on a new feature, then clear. You don't want the previous conversation to present bias in anything new that you want to create. For things that you do want Claude to remember in other sessions, put it in the CLAUDE.md file. That way, it doesn't have to rediscover things from scratch all over again. Be specific. The irony behind writing a smaller prompt is that it in the long run, it will take up more context. Without being explicit, Claude is forced to look around your codebase more and do its own thinking, which takes up a lot more context. window space than if you were just a little bit more clear with a sentence or two. MCP servers load all of the tools available into context by default. So, if you have a lot of MCP servers for things that are unrelated to the project, it might be worth turning them off. You can also try out skills, which works similarly to MCP servers, but doesn't put the entire thing into context, saving you space. Sub agents run in parallel with your main agent but has a complete separate context window. So for tasks that require an answer without the journey like where is the authentication endpoints located, you can have the sub agent do the work and return just a summary to your main agent. Managing context within Claude Code is crucial. Use slash compact to summarize long sessions and slashclear to start fresh. To use your context window effectively, be specific with what you want. Check what's using your current context window and use sub agents to delegate tasks you only need the answer for.