Context Management & Compaction
How to manage conversation context in Claude Code and Cursor to save tokens and stay productive
Why context matters
Every message you send includes the full conversation history. A 50-turn conversation sends far more tokens than a 5-turn one. Managing context keeps costs down and responses focused.
Claude Code: compaction
Claude Code offers three levels of context management.
Auto-compact
Triggers automatically when you approach the context limit. Claude summarizes the conversation, preserving key decisions, code patterns, and recent changes while condensing older history.
You can see when it happens: Claude prints a compaction notice in the terminal.
Micro-compact
A lighter pass that removes old tool call results (file reads, command outputs) without summarizing the conversation itself. Frees space with minimal information loss.
Manual /compact
Run /compact to trigger compaction on demand. Add instructions to control what gets kept:
/compact /compact only keep the architecture decisions /compact preserve the API schema we designed /compact forget the debugging: keep the final solution
This is useful mid-session when you finish one phase (e.g., debugging) and want to reclaim context for the next phase (e.g., writing tests).
Other context commands
| Command | Effect |
|---|---|
/clear | Wipe the conversation entirely and start fresh |
/compact [instructions] | Summarize with custom focus |
--resume | Restore a previous session (its compacted state) |
Cursor: no compaction
Cursor does not offer compaction. When context fills up, you see a warning and must start a new chat. You cannot summarize mid-conversation or selectively trim context.
Workarounds
Notepads: Store key decisions, schemas, or context in Notepads. They persist across chats and load on demand with @notepad-name.
Rules files: Put project conventions in .cursor/rules/ as .mdc files. These load automatically based on glob patterns, so every new chat starts with the right context.
Manual summary: Before closing a long chat, ask the AI to summarize the conversation. Copy the summary and paste it into a new chat as the first message.
Shorter chats: Start a new chat for each distinct task. This is the most reliable way to keep context manageable.
Side-by-side comparison
| Feature | Claude Code | Cursor |
|---|---|---|
| Auto-compaction | Yes, triggers near context limit | No |
| Manual compaction | /compact [instructions] | No |
| Selective trimming | Micro-compact (tool results) | No |
| Clear conversation | /clear | Start new chat |
| Persist across chats | Memory files, CLAUDE.md | Notepads, rules files |
| Context limit signal | Auto-compact kicks in | Warning banner |
Best practices for both tools
- One task per chat: the single most effective cost-saving habit
- Front-load context: put important info in CLAUDE.md or rules files, not repeated messages
- Compact before pivoting, in Claude Code, run
/compactwhen switching from exploration to implementation - Don't fight context limits, if a conversation feels sluggish or unfocused, start fresh