A curated collection of patterns and tools for managing context rot in AI-assisted coding.

Context rot is the practical failure mode of long, mixed-purpose AI coding sessions: contradictions, forgotten constraints, vague plans, and repeated re-explanations as the working context becomes polluted.

Operating Model

Most effective approaches map to four levers:

Isolation Illustration

Isolation

Bound each session to a single task/phase/agent to prevent context pollution

Snapshot Illustration

Snapshot & Rehydrate

Record authoritative project state in files; resume from those instead of chat history

Packing Illustration

Packing

Provide only relevant repository slices, prepared for efficient AI consumption

Compaction Illustration

Compaction

Summarize or prune context intentionally before quality degrades

Quantitative Guidance

Research-backed thresholds for context management:

MetricRecommendationRationale
Effective context window<256k tokensModels degrade well before advertised limits (1M+)
Context utilizationStop at ~75%Sessions at 90% produce more code but lower quality
Compaction trigger~128k tokens or 50% utilizationCompact before degradation, not after
Memory/rules file size<300 linesContext tokens are precious; shorter is better

Patterns

STATE.md as source of truth

Maintain a STATE.md file in your repository with:

  • Objective — what "done" means
  • Constraints — non-negotiables
  • Decisions — selected approach and rationale
  • Current status — where things stand
  • Next steps — 3-7 concrete items

When outputs begin to drift, update STATE.md and start a fresh session using only that file plus relevant source code.

# STATE

## Objective
- ...

## Constraints
- ...

## Decisions
- ...

## Current Status
- ...

## Next Steps
1. ...
2. ...
3. ...

Task-scoped sessions

One task per session. When you finish a task or pivot to something different, end the session and start fresh. Mixing unrelated work in a single context accelerates rot.

Phase separation

Split work into distinct phases (research, planning, implementation, review) and run each in its own session. Don't let implementation details pollute research context, or planning debates pollute implementation.

Fresh-start rehydration

When context feels degraded, don't try to recover it. Instead:

  1. Update your state file with current knowledge
  2. Start a new session
  3. Load only: state file + relevant source files (or a packed digest)

This is cheaper and more reliable than trying to "fix" a polluted context.

Controlled repository slicing

Never dump an entire repository into context. Use packing tools to provide:

  • Only files relevant to the current task
  • Summaries instead of full content where appropriate
  • Token-aware truncation

Antipatterns

Dumping entire repositories

Loading a full repo into context wastes tokens on irrelevant code and drowns the signal in noise. The model will hallucinate connections between unrelated files and lose track of what matters.

Mixing planning and execution

Debating architecture while also writing code creates a context where half-formed plans mix with implementation details. Neither activity gets clean focus. Separate them into distinct sessions.

Chat history as project memory

Relying on earlier messages to remember decisions, constraints, or status. Chat history degrades, gets summarized lossy, and eventually falls out of context entirely. Externalize to files.

Pushing through drift

When outputs start missing constraints or repeating mistakes, continuing in the same session makes it worse. The context is polluted. Stop, snapshot, restart fresh.

Over-trusting summaries

Automatic summaries lose detail. When you resume from a summary, verify critical constraints and decisions are actually present. Don't assume the summary captured everything that matters.

Overloading a single agent

Asking one agent/session to handle research, planning, implementation, and review. Each activity pollutes context for the others. Use separate agents or sessions for separate concerns.

Tools

Each tool is included because it exposes a clear mechanism for one of the four levers.

Orchestration and Phase Separation

Tools that enforce phased execution and externalize state.

ToolMechanismBest for
Get Shit Done (GSD)Spec-driven phases with persistent state filesMulti-phase feature delivery
RalphAutonomous loop runner with explicit completion gatesLong-running iteration with guardrails
Continuous ClaudeHooks + ledger/handoff patternsStructured CLI workflows with state preservation
Claude Code WorkflowJSON-driven multi-step structure with explicit phase boundariesRepeatable, bounded agent execution

Parallel Work Without Context Bleeding

Tools for running multiple workstreams while keeping contexts isolated.

ToolMechanismBest for
workmuxGit worktrees + tmux to isolate at filesystem/session levelParallel development without context mixing
Claude SquadMultiple agents in separate terminal workspacesRunning parallel agent workstreams
Vibe KanbanMulti-agent orchestration with task trackingManaging multiple concurrent tasks/agents

Repository Packing

Tools that produce controlled, prompt-friendly repository context.

ToolMechanismBest for
RepomixRepo to AI-friendly artifact with configurable packingSharing controlled repo context
CTXStructured context docs based on explicit selection rulesDeterministic, high-signal context packets
GitingestPrompt-ready repository digestFast repo rehydration

Memory Persistence

Tools that persist decisions and state across sessions.

ToolMechanismBest for
memory-bank-mcpRemote memory bank service via MCPCross-session project memory
Context PortalStructured, DB-backed project context via MCPDurable source-of-truth memory
Cursor Memory BankStructured memory workflow with rules loadingReducing repeated explanations in Cursor
Cursor RulesPersistent, versioned instructions per repository/pathProject-level AI configuration

Compaction and Pruning

Tools and features for compacting long sessions before degradation.

ToolMechanismBest for
OpenCodeBuilt-in compaction/pruning workflowsLong terminal sessions
Claude Code/compact command and session managementCLI-based context hygiene