A long AI coding session can run out of context or keep reprocessing stale history. Compaction reduces retained context by summarizing the conversation, but the summary is lossy: an instruction given once at the start may disappear even when it prevents bugs. section 3.5.2 section 9.5.2
In Claude Code, context management clears older tool outputs first and summarizes the conversation if needed. The summary favors recency, relevance, and frequency; requests and key code snippets may survive while detailed early instructions are compressed away. A typical compaction frees 60–70% of context, but that space comes at the cost of detail. section 3.5.2
Protect important context before the summary becomes the only record:
- Put persistent project rules in a project memory file such as CLAUDE.md or AGENTS.md rather than relying on an early conversation message. CLAUDE.md is re-read at session start. section 3.5.2
- Append decisions, findings, and reasoning to a durable artifact at workflow boundaries, including when leaving plan mode or completing a todo. Write before compaction and at session end as a backstop, not a substitute for timely notes. section 5.6.5
- Treat late summaries cautiously. A note reconstructed at session end can omit abandoned approaches, and an agent rereading its own notes in the same session can reinforce an earlier mistake. section 5.6.5
Managing a growing session
A session that moves from a bug fix through feature discussion, refactoring, and several attempts can accumulate 150,000 tokens, much of it irrelevant. In Claude Code, use /compact to summarize the history; the cited recommendation is to compact at 70–80% context usage rather than wait for auto-compaction at 85% or more. Starting a new session for a distinct task is another option. section 9.5.2









