Context Management
Every Claude Code session operates within a context window, which is the total amount of text Claude can consider at once. Managing this context well is one of the most important skills for productive sessions. When context runs low, Claude may lose track of earlier details or struggle to produce accurate responses.
Understanding the Context Window
The context window includes everything in the current conversation: your prompts, Claude's responses, file contents that have been read, tool outputs, and CLAUDE.md instructions. As the session progresses, this accumulated context grows.
When the context window fills up, you have two options:
- Compact the conversation to summarize what has happened so far.
- Clear the conversation and start a new one.
Using /compact
The /compact command tells Claude to summarize the conversation history into a condensed form. This frees up space in the context window while preserving the key details of what you have discussed and accomplished.
> /compact
After compacting, Claude retains a summary of:
- What files were discussed and modified
- Key decisions that were made
- The current state of the task
Use /compact proactively during long sessions. Do not wait until you hit the limit.
Providing Good Context
The quality of Claude's responses depends heavily on the context you provide. Here are practices that help:
Be Specific About Files
Instead of saying "fix the bug in the component," point Claude to the exact location:
There is a null reference error in /src/hooks/useAuth.ts
on line 42 where the user object might be undefined.
State the Goal Clearly
Tell Claude what you want to achieve, not just what to do:
I need the sidebar to collapse on mobile screens.
The breakpoint should be 768px. Update the Sidebar
component and any related CSS.
Provide Relevant Background
If there is important context that Claude would not know from reading the code alone, mention it:
We are migrating from REST to GraphQL. The old API client
in /src/lib/api.ts should be replaced with the new
GraphQL client in /src/lib/graphql.ts.
CLAUDE.md as Persistent Context
Your CLAUDE.md file is loaded at the start of every session automatically. This makes it the ideal place for context that applies across all conversations:
- Tech stack and framework versions
- Coding conventions and style preferences
- Common commands for development, testing, and deployment
- Project structure and architecture notes
Anything you find yourself repeating at the start of sessions should go into CLAUDE.md instead.
Conversation History
Claude Code maintains conversation history within a single session. Once you close the terminal or run /clear, that history is gone. If there are important decisions or context from a session that you want to preserve, add them to your CLAUDE.md or document them elsewhere in your project.
Session Lifecycle
- Start — Claude loads CLAUDE.md and begins with a fresh context.
- Work — Context grows as you chat, read files, and make edits.
- Compact — Summarize when context gets large.
- End — Closing the session discards conversation history.
Plan your work sessions with this lifecycle in mind. Tackle related tasks together, compact when needed, and start new sessions for unrelated work.