Agent Context Management: Match Failure Mode to Fix
Key takeaways
- Context rot is the only failure mode a bigger or compacted context window fixes; handoff loss, stale state, write collisions and spec drift are workflow problems.
- The minimal handoff payload between agent sessions is four items: the task card, a short note, the git diff, and test status.
- Anything the next agent needs to decide goes in the handoff note; anything it needs to read goes in the code.
- Claim-and-note mechanics, one card with one owner, plus per-session git worktrees prevent write collisions between parallel agents.
- Audit context quality with three cheap rituals: read the diff, check the handoff note, and count rework per handoff.
Agent context management is the practice of diagnosing why a coding agent loses the plot mid-task and applying the specific fix: compaction for context rot, structured handoff notes for lost state, claim-and-lock for write collisions. This article maps each symptom you'll see across parallel sessions to the technique that fixes it.
What is agent context management and why does context degrade over long tasks?
Agent context management is the practice of deciding what a coding agent carries between steps, sessions and teammates: the task spec, the current diff, test status and the handoff note. You already do a version of it with a CLAUDE.md and git worktrees.
What counts as context
Context is everything the model sees this turn: system prompt, project files, the conversation so far, tool output. Chat history is disposable working memory; the task board is the system of record.
Why long sessions rot even when nothing overflows
Long sessions degrade before they hit the window. Models weigh recent tokens more heavily, so early instructions and file reads fade in influence as tool output piles up. Anthropic's docs on context windows and compaction describe this summarise-and-continue behaviour. The fix is passing a compact handoff note, not replaying the session: KanbanMCP's connect docs show the minimal payload an agent needs to claim a card and continue.
When does a single agent need context compaction versus a multi-agent setup?
Compaction fixes one long session that is rotting. Multi-agent context management fixes three or more parallel sessions that need shared state. If your problem lives inside a single conversation, compact; if it lives between conversations, you need coordination.
The compaction threshold
Compact when one session shows the classic decay: the agent rereads files it already read, forgets decisions from earlier in the session, or drifts from the plan in your CLAUDE.md. Compaction summarizes what the session has done so it can keep going. It does nothing for a second agent that starts with no idea what the first one finished.
Three signs you have outgrown one session
First, you are running three or more agent sessions in parallel and they touch the same codebase. Second, handoffs fail: you paste a handover prompt between chats and the next agent still misses context. Third, sessions collide, two agents editing the same file or duplicating work. At that point the fix is a shared system of record, not a bigger window. A board where each agent claims a card and leaves a handoff note, like KanbanMCP, keeps chat sessions disposable and state in one place.
Which failure mode is actually biting you? A symptom-to-fix matrix
Diagnose the symptom first, then pick the technique. The four failures look similar from the outside but have different fixes:
| Symptom | What you see | Fix |
|---|---|---|
| Context rot | Agent forgets earlier constraints mid-task | Auto-compaction; Claude Code summarizes long sessions (docs) |
| Handoff loss | Next session starts cold, redoes work | Written handoff note on the card, not in chat |
| Stale state | Board says done, branch says otherwise | Single source of truth, status updated by the agent itself |
| Write collisions | Two agents edit the same file | One card claimed at a time, worktrees per session |
| Spec drift | Later agents build against an old plan | Spec lives in CLAUDE.md or backlog.md, referenced per task |
Notice that only context rot is a window problem. The other four are workflow problems, which is why a board like KanbanMCP treats them with claim-and-note mechanics rather than bigger prompts. If compaction alone isn't fixing your mornings, your failure mode is probably in the bottom four rows.
How do you decide what context to pass between agents in a multi-agent system?
The minimal handoff payload
A handoff needs four things: the task card, a short handoff note, the git diff, and test status. Everything else belongs in the repo, not the message. The diff is the highest-value item because the next agent can read it and infer intent without you writing a summary. The note covers what the diff can't show: dead ends, why you picked one approach over another, what you'd do differently. Test status tells the next session whether it's resuming from green or inheriting a mess.
Keep the system of record out of the chat
Chat sessions stay disposable; tasks and decisions live in the repo or on a board. If a project's context exists only across agent chats, you can't recover it a week later, which is exactly the failure solo devs running three or more parallel sessions keep hitting. Write the handoff note to the card, not to the chat transcript, so the next agent claims the card and starts from the same state regardless of which tool it runs in. If you're unsure what belongs in a payload versus the repo, the rule of thumb is: anything the next agent needs to decide goes in the note; anything it needs to read goes in the code.
A card, a note, a diff, and a test result is the whole payload, and it's deliberately boring. If your handoff needs more than that, the task was probably scoped too wide and should be split before the next agent picks it up. When in doubt about what fits, the team behind KanbanMCP publishes examples of payloads that work in practice at https://kanbanmcp.com/support.
What are the most common context handoff failures between agents and how do you prevent them?
Lost decisions
The agent that chose Postgres over SQLite, or rejected a refactor, closes its session and the reasoning evaporates. The next agent re-litigates the same choice from scratch. Prevention: the handoff note must record decisions, not just completed work. Two lines of "we tried X, it failed because Y" saves a whole session.
Stale state on the card
An agent finishes half a card, crashes, or gets killed mid-edit, and the board still says "in progress" with no owner. The next session picks it up blind and duplicates work. Prevention: agents claim a card explicitly and leave a partial-work note before going quiet, so a human reviewing the git diff in the morning knows what actually landed.
Assumed prior work
The worst one: an agent assumes the previous session's changes are merged and builds on code that does not exist. Prevention: every handoff note points at a concrete artifact, a branch or worktree path, never a summary. A board like KanbanMCP makes the note the card's source of truth, so the next agent reads state from the board instead of guessing from chat history.
How should shared state be structured so multiple agents don't overwrite each other's context?
The fix for write collisions is boring: one card, one owner. An agent claims a card, works on it, and writes a handoff note back to the card before dropping the claim. Nobody else touches that card while it's claimed, so the card itself becomes the source of truth instead of any chat session. This matches the research on context rot: performance degrades well before a context window is full, so long chats are the wrong place to store state (Anthropic on effective context engineering).
Claim, work, note
The claim-then-work pattern has three steps. Claim sets ownership atomically. Work happens against the card's scope only. The note records what changed, what's untested, and what the next agent should check, so a fresh session starts from two paragraphs instead of a scrollback.
Worktrees as write isolation
Give each session its own git worktree. Two agents editing the same checkout is a write collision regardless of how good your board is; separate worktrees make the collision a merge instead. KanbanMCP runs this same pattern: claim a card, work in isolation, leave a note, and you review the diff from the board. Its gap is honest: it doesn't manage the merge itself, so you still own conflict resolution.
What signals tell you your agent's context window is the bottleneck versus your workflow design?
Before adding tooling, check which bottleneck you actually have. The two fail differently and need different fixes.
Window bottleneck signals
The agent asks questions you already answered, re-reads files it changed an hour ago, or forgets a constraint you set at the start of the session. Output quality degrades partway through a long task even though nothing about the task changed. If compaction or a fresh session with a good handoff note fixes it, the window was the problem.
Workflow bottleneck signals
Two sessions edit the same file and you get merge conflicts, or two agents independently solve the same task because neither knew the other claimed it. Context quality is fine inside each session; the state between sessions is missing. That points at your board and handoff design, not the window.
How do you audit and measure context quality in a running agent system?
Auditing context quality comes down to three cheap rituals: read the diff, check the note, count the rework. You don't need dashboards; you need a repeatable morning pass over what your agents actually did and wrote.
The morning diff audit
Run git diff across your worktrees before anything else. For each session, ask: does the diff match the card it claims, and does the handoff note explain any deviation? A diff with no matching note is the earliest signal of handoff loss. Task-style files like those used by Taskmaster make this check mechanical, because the task state is a file you can read alongside the diff.
Tracking rework per handoff
Keep a one-line log per handoff: card, agent, and whether the next session had to redo work. If a lane needs rework more than once a week, the notes are too thin, not the model. Fix the note template before touching anything else.
What does this look like with a real board?
Running the matrix on KanbanMCP
KanbanMCP implements the matrix directly: each card is a unit of context, an agent claims it, does the work in its own worktree, and leaves a handoff note for the next session. Stale state and write collisions get fixed by the claim itself, since one card has one owner at a time. Handoff loss becomes a written note on the card instead of a pasted prompt you have to dig out of a dead chat. You watch several lanes from one board and steer with a comment before the next agent picks the card up.
Where a board does not help
Honest limits: KanbanMCP does no automatic context summarisation. You write the handoff notes, and a vague note passes the same rot to the next agent as a vague prompt would. It also does not compact a single long session; that is still your job. If your bottleneck is one agent drowning mid-task rather than coordination between three or more parallel sessions, a board will not fix it.
FAQ
Do I need a framework for multi agent context management or is a markdown backlog enough?
A markdown backlog works until sessions collide. If you run three or more parallel agents on one codebase, you need atomic claiming so two agents never pick up the same card, plus notes written back to the card. A static file can hold the spec but cannot enforce one owner at a time. Start with markdown; move to a board when collisions or stale state appear.
How much context should I put in a handoff note between agent sessions?
Four items: the task card, a short note, the git diff, and test status. The note covers what the diff cannot show: decisions made, dead ends, and untested areas. Anything the next agent needs to decide goes in the note; anything it needs to read goes in the code. If the payload grows beyond that, split the task.
Can agents in different tools like Claude Code and Cursor share the same context?
Yes, if the context lives outside the chat. Chat history is tool-specific, so a Claude Code session cannot read a Cursor transcript. Store state in the repo or on a board instead: a card with a handoff note, a branch, and test status. Any agent that claims the card then starts from the same state regardless of which tool it runs in.
Why does my agent forget decisions from earlier in the same session?
Context rot. Models weight recent tokens more heavily, so early instructions and file reads lose influence as tool output accumulates. The window is not full; the relevant tokens are just buried. Compaction summarizes the session so it can continue, and a written record of decisions in CLAUDE.md or the task note survives even a fresh session.