Skip to content
AI Architecture
Updated 10 min read

AI Coding Agents Losing Context? Run a Restart Check

When an AI coding agent forgets project context, check the record before you blame the model: triage missing, stale or contradictory state, then run a four-field restart check before it resumes.

AI coding work represented as a shared task board with prompt context, criteria, artifacts, and handoff state

Before a resumed agent touches code, it should be able to point at the record it is working from.

If your coding agent keeps forgetting project context, treat it as a record problem before you treat it as a memory problem. Before the agent resumes, check whether the task state it needs is missing, stale or contradictory. Then run a restart check: the agent must state the current owner, the last decision, the blocker and the next action, and trace each one to the source record. If any field conflicts or has no source, fix the record first. Code comes after.

That sounds like process for its own sake. It comes from a real failure. In March 2026 a Claude Code user reported that a session finished a refactoring plan covering 25 files, saved a one-line pointer to it in MEMORY.md, and said the plan was ready for the next session. The next session followed the pointer and found nothing on disk [6]. Re-explaining the project would not have brought that plan back, and neither would a bigger context window. A check that fails before work starts would at least have stopped the next session from guessing.

How to diagnose a coding agent that forgets project context

"It forgot" covers three different faults, and each one needs a different repair. More prompt history alone does not tell you which record is current or which one has authority.

StateWhat you seeHow to tellFix first
MissingThe agent asks "continue what?", rebuilds a plan from scratch, or follows a pointer that leads nowhereWhat it needs has no retrievable source: no file, comment, commit or task entryRecover the source or have the owner restate it, then save it where the next session will read it
StaleThe agent confidently does yesterday's plan: reverts a fix, reopens a closed option, edits a file that has movedA record exists, but a newer decision or the current code supersedes itMark the old record superseded and point to its replacement. Adding a newer note beside it leaves two candidates
ContradictoryThe agent follows one of two instructions, or switches between themTwo plausible current sources disagree and nothing says which one winsStop. Ask the person who owns the task to decide, record the decision, then resume
Stale and contradictory get confused, so use this test. If you can name the newer source that wins, the old one is stale. If you can't, you have a contradiction, and the agent should not be the one to settle it. A newer timestamp is a hint, not a ruling. A note left at 5 p.m. by someone without authority over the task does not overrule what the assignee decided that morning.

Mid-task drift can be the stale kind arriving through a side door. Claude Code's docs describe CLAUDE.md and auto memory as context the model reads, with nothing enforcing them [1], and say that when the context window fills, the conversation is compacted into a summary [2]. So when a Claude agent keeps forgetting what it was doing mid task, across sessions or after a long run, check whether it is working from a summary of an older decision while the correction lived in detail the summary dropped.

Contradictions that keep coming back are a different smell. If the same choice gets reopened on every retry, the fix belongs upstream: record a decision once so a retry replays it instead of asking again.

A real broken resume, diagnosed

The case is a comment by GitHub user Filament61 on anthropics/claude-code issue #39663, posted on 27 March 2026 under the heading "Internal plans are NOT persisted across sessions" [6]. Here is what they reported.

At the end of their Session 302, Claude produced a detailed plan for their issue #581: a refactor spanning 25 files, 115 occurrences and two implementation lots. It was made in Claude Code's plan mode and given the auto-generated name sleepy-inventing-floyd. Claude then wrote one line to MEMORY.md pointing at plans/sleepy-inventing-floyd.md and told the user the plan was ready for the next session. In the next session the plan did not exist anywhere on disk. The reporter adds that Session 302 had, earlier in the same session, written itself a rule to always save to memory before suggesting a restart, and that Session 303 responded to the loss by writing a near-duplicate rule.

Run the triage first. The pointer exists and its target doesn't, so this is missing state. Nothing newer superseded the plan, so it isn't stale. There's no competing plan, so it isn't contradictory. That matters, because each diagnosis points somewhere else: missing means recover or restate, and asking the agent to "be more careful" repairs nothing.

Now the four fields, using only what the next session could actually open:

FieldWhat the record showsResult
OwnerThe memory line names an issue, not who approved the refactor or who holds it nowNo source: fail
Last decision"Plan ready" for #581, but the plan itself is gonePointer without its target: fail
BlockerNothing recordedUnknown, which is not the same as none: fail
Next actionThe lots that defined the next step were inside the missing planNo source: fail
The check fails on its first field. The useful part is what it prevents: an agent rebuilding a 25-file refactor from a one-line summary and presenting the result as the plan everyone agreed on.

The repair that follows is a recommendation, not something the issue reports: don't ask the agent to regenerate the plan from the memory line. Have the owner reconfirm scope and the first lot, save the plan as a real file in the repo or as an artifact on the task, record the decision with a link to that file, and run the check again. It should now pass with four sources.

The second lesson is in Session 303's reaction. Another rule depends on the previous session behaving better next time. A check runs in the next session, and it works whether or not the last session remembered its rules. A saved pointer is only useful if its target still opens.

One caveat. The reporter's explanation, that plan-mode plans are session-scoped, is theirs. I haven't reproduced it, and Claude Code may have changed since March. The diagnosis doesn't depend on the cause, which is the point of checking the record at read time.

The restart check

Run it after a fresh session, a resumed one, or a compaction, before the agent's first edit. Each field has to pass on its own.

Owner. Who is assigned the task now. It passes when the agent cites the task's current assignee or an explicit handover note.

Last decision. The most recent approved decision that shapes the next step. It passes when the agent links where the decision was made (a comment, commit, ADR or attached file) and nothing newer supersedes it.

Blocker. What stops progress. "None" passes only if the record says none. Silence is unknown.

Next action. One step, naming files by paths the agent has opened and the commit or task revision they come from. It passes when those paths exist at that revision. Requiring verified paths makes the next action inspectable, but it can't prove the agent has found every dependency.

The check fails when any field has no source, when a cited source doesn't open, when two sources disagree, or when the record the agent read is not the current revision. On a fail, the agent stops and tells you which field broke. It does not fill the gap with its best guess.

Here is a prompt you can paste at the start of a resumed session:

text
Before you edit anything, run a restart check against <task link or file>.
Re-read the record now. Do not rely on memory or the earlier conversation.
Report four fields, each with the source you read it from:
1. Owner: who is assigned this task now
2. Last decision: the latest decision that shapes the next step
3. Blocker: what stops progress, or "none" only if the record says none
4. Next action: one step, with file paths you have opened and the commit or revision they are from
If any field has no source, or two sources disagree, stop and tell me which.
Do not reconstruct a missing plan from a summary.
Flow diagram of a restart check: the resumed agent re-reads the task record, classifies state as missing, stale or contradictory, then checks owner, last decision, blocker and next action against sources before it resumes or stops to fix the record
The restart check as a gate: re-read, classify, trace four fields, then resume or fix the record first.

The strongest objection is that the agent can just re-read the repo. It can, and it should, but re-reading only tells you that some text exists. Whether that text is current, and whether whoever wrote it had the authority to decide, are separate questions, and those are the ones the check asks. Session 303 did re-read: it found the memory line, searched for the plan and came up empty. The check turns that moment into a stop with a named reason instead of an improvised plan.

The other objection is overhead. For a ten-minute task on a fresh branch, skip it. The check pays where a session ends with work half done, which is exactly when nobody wants to write a handoff.

Know its limits. The check verifies evidence. It can't check judgment: if the record consistently says the wrong thing, the agent passes and does the wrong thing with confidence. Timestamps help you spot stale state but don't settle authority. And I don't know of a published measure of how often resumes fail this way, so treat the check as a cheap guard until someone measures it. The nearest research is adjacent: the MAST taxonomy of multi-agent failures includes inter-agent misalignment and task verification among its categories [5]. A resumed session is effectively a handoff from your earlier agent to a later one, which is my inference, not the paper's claim.

Where each field should live

Where information sits in a long input can matter. Liu and colleagues found that models used relevant information less reliably when it sat in the middle of a long input, in multi-document question answering and key-value retrieval tasks [3]. That isn't a coding-agent benchmark, and the case above didn't need one: the plan was never in context to begin with.

The CLAUDE.md versus auto memory question has a cleaner answer. Per Claude Code's docs, CLAUDE.md holds instructions you write, and auto memory holds notes Claude writes for itself as it learns your corrections and preferences [1]. Neither records who owns the task today, which is the first field the check asks for.

SurfaceWho writes itGood forCan't answer at restartPortability
CLAUDE.md or another repo instruction fileYouStable conventions, commands, architecture rulesWho owns this task, what was decided todayTravels with the repo
Claude Code auto memoryClaudeLearned preferences and correctionsWhether its notes are current or were ever approvedTied to Claude Code
Repo state file such as STATUS.mdYou or the agentSolo work across a few sessionsAnything that changed since the last updateTravels with the repo
Shared task recordPeople and agents with accessOwner, status, decisions, blockers and evidence across people and toolsAnything nobody wrote down; it goes stale without upkeepReadable by any assistant connected to it
If you want to stop re-explaining project context to AI coding agents without locking yourself into one vendor's memory, sort by who has to read the state. One developer in one repo: versioned files are hard to beat, and they move with git. Several people or several assistants: keep the four live fields in one place every tool can reach, and leave tool-specific memory for tool-specific learning. That is the setup in one task record across ChatGPT, Claude, Cursor and Codex. If you live in Claude Code, it's worth knowing when Claude Code's local memory stops scaling and what Claude Code Tasks stores and where it stops.

A shared record has its own costs. A recent r/ClaudeCode thread on keeping Claude Code from forgetting a working setup shows both sides [8]. The opening post describes re-briefing the agent on server, CMS and drafting rules, and a remembered config path that would go stale once it moved; it also says local auto memory was helping that solo setup. Treat it as one practitioner conversation, not a survey. A board adds upkeep, and a board nobody updates goes stale like any other record.

Research agents that lose context between steps

"My research agent keeps losing context between steps" is the same problem with different nouns. Anthropic's write-up of its multi-agent research system describes subagents storing their work in persistent artifacts and passing lightweight references back, and the system checkpointing regularly so a run can resume after errors instead of starting over [7]. Its context-engineering guidance makes the matching point for a single agent: keep structured notes outside the context window and pull them back in when needed [4].

So hand the next step a checkpoint. A useful one holds the research question and its scope, evidence links with the date each was checked, the last decision (which sources are in, which are out), the open question or blocker, and the next verification step.

Then apply the same rule as the coding check. Before building on the previous step, the next one reopens at least one cited source and separates what the source says from what the previous step inferred. If the source won't open, that is missing state, and the step stops there.

Where Agiflow fits

Agiflow is one example of a shared task record for AI coding agents. A task sits on the project board with a status and an assignee, and both people and agents comment on it. Files can be attached to the task as artifacts [10]. Connected external assistants get access scoped to a project, work unit or task over MCP, so more than one tool can read the same record [9].

That maps onto the check without extra ceremony. Owner is the assignee. The last decision is a comment or an attached file. Blocker and next action are what you write down before the session ends. The restart check itself stays a manual step that you or the agent run against the task. For what a coding team actually needs to share beyond that, see AI coding team shared state. And for one developer in one repo, a versioned file may be all you need.

Before the next session writes code, ask it four questions and make it show where each answer came from.

References

[1] Claude Code docs, How Claude remembers your project - https://code.claude.com/docs/en/memory - Describes CLAUDE.md (instructions you write) and auto memory (notes Claude writes), and says both are loaded as context rather than enforced configuration.

[2] Claude Code docs, Explore the context window - https://code.claude.com/docs/en/context-window - Describes what loads into context and how compaction summarizes the conversation as the window fills.

[3] Liu et al., Lost in the Middle: How Language Models Use Long Contexts - https://arxiv.org/abs/2307.03172 - Reports lower performance when relevant information sits in the middle of long inputs, in multi-document QA and key-value retrieval. Not a coding-agent benchmark.

[4] Anthropic Engineering, Effective context engineering for AI agents - https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents - Describes compaction, structured note-taking outside the context window, and sub-agent architectures for long-horizon work.

[5] Why Do Multi-Agent LLM Systems Fail? - https://arxiv.org/abs/2503.13657 - Proposes the MAST failure taxonomy, including system design issues, inter-agent misalignment and task verification. Adjacent evidence, not coding-specific.

[6] GitHub, anthropics/claude-code issue #39663, comment by Filament61, 27 March 2026 - https://github.com/anthropics/claude-code/issues/39663 - Third-party report of a plan referenced from MEMORY.md that the next session could not find on disk. The reporter's diagnosis is not independently reproduced here.

[7] Anthropic Engineering, How we built our multi-agent research system - https://www.anthropic.com/engineering/multi-agent-research-system - Describes checkpoints for resuming after errors and subagents writing persistent artifacts that are passed back as lightweight references.

[8] Reddit, r/ClaudeCode thread on keeping Claude Code from forgetting your setup - https://www.reddit.com/r/ClaudeCode/comments/1x8aikj/how_do_you_keep_claude_code_from_forgetting_your/ - Community discussion; URL resolved on 28 November 2026. Anecdotal; not prevalence data.

[9] Agiflow documentation, Connect Assistants - /docs/connecting-ai-tools - Documents scoped assistant connections at the organization, project, work-unit and task levels.

[10] Agiflow guide, Manage project files - /guides/project-artifacts/manage-files - Documents project files and viewing the files attached to a task.

Put this project board inside ChatGPT

Open Agiflow in ChatGPT to plan campaigns, create tasks, and check what needs attention. Create a free Agiflow account when you are ready to keep the board for your team.