Managing Context: When to Compact and When to Start Fresh
Learn how to manage Claude Code’s context window with `/context`, `/compact`, and `/clear`. This guide explains when to inspect usage, summarize related work, start a fresh conversation, and preserve important project knowledge outside temporary chat history.
How to Manage Context in Claude Code With /context, /compact, and /clear
Claude Code can inspect files, discuss architecture, generate code, run commands, and maintain a long conversation about your project. All of that information must fit inside its context window.
The context window is Claude’s working memory for the current conversation. As a session becomes longer, more of that working memory is occupied by messages, files, tool results, project instructions, and generated output.
Managing that context is an important part of using Claude Code effectively. A focused session gives Claude a clearer view of the current task, while an overloaded session can bury important requirements beneath irrelevant history.
In this tutorial, you’ll learn:
- What occupies Claude Code’s context window
- How to inspect context usage with
/context - When to summarize a session with
/compact - When to start fresh with
/clear - How
CLAUDE.mdbehaves after clearing a conversation - Why fixed token and percentage rules can be misleading
- How to build a repeatable context-management workflow
What Is a Context Window?
A context window is the total amount of information a model can consider during a request. You can think of it as Claude’s working memory.
In a Claude Code session, that context may include:
- System instructions
- Built-in tool definitions
- Installed skills, plugins, or integrations
- Your conversation history
- Claude’s previous responses
- Files Claude has read
- Tool calls and their output
- Shell commands and terminal output
- Project instructions such as
CLAUDE.md - Summaries created during compaction
The available window depends on the model, plan, environment, and current Claude Code configuration. In the session recorded for this lesson, /context displayed a 200,000-token window. Do not assume every model or future version will use that exact capacity.
Rather than memorizing a fixed number, inspect the active session with /context.
What Is a Token?
Models process text as tokens rather than whole words. A token may be a word, part of a word, punctuation, or another unit of text.
A common rough estimate for English prose is that one token represents about three-quarters of a word, but code behaves differently. Symbols, identifiers, paths, repeated structures, minified files, logs, and generated output can consume tokens much faster than plain paragraphs suggest.
The precise conversion is less important than the practical lesson: a large context window is still finite, and software-development sessions can fill it surprisingly quickly.
Why Context Management Matters
More context is not automatically better. Relevant context helps Claude understand the task, but unrelated or repetitive context makes the important information harder to prioritize.
As a session grows, you may notice symptoms such as:
- Earlier constraints receiving less attention
- Claude repeating an investigation it already completed
- New code failing to reuse existing components
- Answers becoming inconsistent with earlier decisions
- The model focusing on stale requirements
- Large logs or file contents crowding out useful discussion
- Claude spending more time reconstructing the current state
These problems are sometimes described casually as “hallucination” or “forgetting,” but the underlying situation is more nuanced. Instructions still present in the window may be overwhelmed by later content, summarized during compaction, contradicted elsewhere, or simply missed during reasoning.
Good context management reduces those risks by keeping the current task visible and removing history that no longer provides value.
Inspect Usage With /context
Claude Code provides a built-in visualization of the current context window.
Run:
/context
According to the official Claude Code command reference, /context visualizes current context usage and can provide suggestions or warnings when particular sources consume significant space.
The display may include categories such as:
System instructions
These define Claude Code’s foundational behavior and operating rules. You generally do not control this portion directly.
System tools
Tool definitions tell Claude how to read files, edit code, run shell commands, use integrations, and perform other actions.
Skills and integrations
Installed capabilities may add instructions or tool descriptions to the context. A large number of always-loaded integrations can create overhead even before a task begins.
Messages
This includes the conversation between you and Claude. It grows as you discuss requirements, review plans, generate code, and provide corrections.
Memory or instruction files
Project instructions such as CLAUDE.md occupy part of the window because Claude reads them as persistent context.
Remaining capacity
The visualization shows how much room remains for additional messages, files, tool results, and reasoning.
In the recorded example, the session had used about 24% of its available context after several rounds of code generation. The exact percentage is not a universal threshold; it simply shows how quickly a development conversation can accumulate information.
For a more detailed breakdown, current versions may support:
/context all
Option 1: Use /compact for Related Work
If you are continuing the same task but the conversation has become long, run:
/compact
This replaces much of the detailed conversation history with a shorter summary so the session can continue with more free context.
Use /compact when:
- You are still working on the same feature
- Earlier decisions remain relevant
- Claude needs to retain the current implementation state
- The session contains a large amount of completed exploration
- You want to free space without starting over
For example, imagine that you have used Plan Mode to design a workout-history feature, implemented the data model, and finished the main components. You still need to fix validation and add tests. The earlier decisions matter, but the full transcript of every edit does not. Compaction lets Claude continue from a summary of the work.
You can also provide focus instructions:
/compact Preserve the approved architecture, changed files, unresolved
validation bug, and verification steps. Drop superseded approaches and
verbose tool output.
Focused compaction can help protect the information you expect to need next.
What Compaction Preserves—and What It Can Lose
Compaction does not preserve the earlier conversation word for word. It creates a condensed representation of the session.
A useful summary should retain:
- The current objective
- Important architectural decisions
- Files created or modified
- Constraints that still apply
- Commands already run
- Known failures
- Remaining work
Minor details, abandoned ideas, lengthy command output, and repeated discussion may disappear. That is usually the point, but it also means you should not depend on compaction to preserve every subtle requirement.
Important durable rules belong in one of the following places:
CLAUDE.mdfor project-wide instructions- A specification or plan file for the feature
- The source code and tests themselves
- A focused reminder in your next prompt
Context is temporary. Written project artifacts are more reliable.
Option 2: Use /clear for a New Task
If you have finished one task and are moving to something unrelated, run:
/clear
/clear starts a new conversation with empty conversational context. The previous session can still be resumed, but the new conversation does not carry its full history forward.
Use /clear when:
- A feature is complete
- You are switching to an unrelated part of the application
- The current session contains outdated or conflicting requirements
- You want Claude to reconsider the next task without being anchored to earlier discussion
- The old conversation no longer improves the next answer
For example, after completing a workout-logging redesign, you might switch to configuring deployment or writing an authentication flow. Those tasks do not need the entire history of the workout interface. Starting fresh gives the new task more room and reduces irrelevant influence.
You can optionally name the previous conversation in supported versions:
/clear workout-redesign
That can make it easier to find later with /resume.
What Happens to CLAUDE.md After /clear?
Clearing the conversation does not mean Claude loses all project knowledge.
When a new project conversation begins, Claude Code reloads the applicable project instructions, including CLAUDE.md, CLAUDE.local.md, and relevant rule files. Files you explicitly reference can also be read again as needed.
This is why a concise CLAUDE.md is so valuable. It lets you clear stale conversation history without repeatedly explaining the technology stack, architecture, commands, and coding conventions.
The new session has a clean conversation while retaining essential project guidance.
/compact vs. /clear
Use this rule of thumb:
| Situation | Command | Result |
|---|---|---|
| Continue the same feature | /compact |
Summarizes the conversation and preserves the main thread |
| Begin an unrelated task | /clear |
Starts a new conversation with fresh context |
| Unsure what is consuming space | /context |
Visualizes current usage and context sources |
The distinction is based on relevance—not merely a percentage.
If the history still helps solve the next problem, compact it. If the history belongs to a completed or unrelated problem, clear it.
Verify the Effect
After running either command, inspect the context again:
/context
In the recorded lesson, using /clear reduced usage from approximately 24% to 8%. The remaining portion included Claude Code’s baseline instructions, tools, skills, and project memory.
Your result will differ depending on:
- The selected model
- Loaded instructions
- Installed tools and integrations
- Project memory files
- Claude Code version
- Environment and plan
The important point is that /clear removes the previous conversation, not that every session must reach the same percentage afterward.
Do Not Rely on a Fixed Auto-Compact Threshold
The transcript for this lesson referenced automatic compaction around 70% usage. Treat that as an observation from a particular Claude Code version—not a permanent rule.
Current Claude Code versions can tune auto-compaction based on the model and configuration. The command reference also includes:
/autocompact
This shows or configures when automatic compaction occurs in supported versions. You may also be able to return it to a model-tuned setting:
/autocompact auto
Because this behavior evolves, use the current command interface as the source of truth. Do not build your workflow around a hard-coded percentage from an older tutorial.
Automatic compaction is a safety mechanism, not a substitute for intentional context management. Claude Code cannot know as reliably as you do whether the next task is closely related or completely different.
Practical Ways to Reduce Context Waste
Commands are only part of good context management. The way you work also affects how quickly a session fills.
Keep each session focused
Avoid mixing unrelated features, debugging threads, research questions, and architecture discussions into one conversation.
Reference only relevant files
Use @ file mentions when you know which files matter. Do not ask Claude to read an entire directory when two components contain the necessary context.
Avoid dumping large logs prematurely
Start with the error, stack trace, and relevant surrounding lines. Add more output only if needed.
Keep CLAUDE.md concise
Because project instructions load repeatedly, remove generic explanations and rules that apply only to rare tasks. Use path-specific rules when appropriate.
Save decisions outside the chat
Store approved architecture and acceptance criteria in a Markdown specification. A written spec survives clearing, compaction, and handoffs better than conversation history.
Start new tasks cleanly
Commit completed work, run verification, and use /clear before beginning an unrelated change.
Use version control
Git preserves the real implementation state even when conversational context is compacted or cleared. Claude can inspect the current diff instead of relying on a memory of earlier edits.
A Repeatable Context-Management Workflow
Use the following loop during AI-assisted development:
- Start a focused task with clear requirements.
- Reference the minimum relevant files.
- Keep durable project rules in
CLAUDE.md. - Store large feature decisions in a specification.
- Run
/contextafter substantial planning or code generation. - Use
/compactif you are continuing the same task. - Test and review the completed implementation.
- Commit the finished work with Git.
- Use
/clearbefore switching to an unrelated task. - Run
/contextagain to confirm the new session is focused.
This workflow keeps Claude’s temporary working memory aligned with the work that matters now.
Common Mistakes
Waiting until the context is almost full
You do not need to chase a perfect percentage, but waiting until a warning appears can make the session harder to manage. Inspect context after large generations or long debugging sessions.
Clearing during an unfinished feature
If important reasoning exists only in the conversation, /clear can force you to reconstruct it. Save the plan or use /compact first.
Assuming compaction preserves everything
A summary is necessarily selective. Restate critical constraints after compacting and keep permanent rules in project files.
Using CLAUDE.md as a transcript archive
Project memory should contain stable, widely applicable instructions—not the history of every feature conversation.
Treating more context as automatically better
The ideal context is not the largest possible context. It is the smallest collection of information sufficient to solve the current task correctly.
Final Takeaway
Context management is part of the engineering workflow when using Claude Code. The context window contains the conversation, files, instructions, tools, and other information Claude can consider at that moment. As irrelevant history accumulates, it becomes harder to keep the current task prominent.
Use /context to understand what is occupying the window. Use /compact when you want to continue related work with a concise summary. Use /clear when you are ready to begin an unrelated task with a clean conversation.
Most importantly, do not ask temporary chat history to serve as permanent project documentation. Keep stable instructions in CLAUDE.md, store feature decisions in specifications, verify changes with tests and Git, and give each task the focused context it needs.