Get startedGet started for free

Video: Context management

1. Video: Context management

Context is Claude'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 adding 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 /clear 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 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 work similarly to MCP servers but doesn't put the entire thing into context, saving you space. Subagents 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 subagent do the work and return just a summary to your main agent. Managing context within Claude Code is crucial. Use /compact to summarize long sessions and /clear 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 subagents to delegate tasks you only need the answer for.

2. Let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.