Skip to content
All posts

Why AI Coding Agents Keep Forgetting What They Were Doing

Why AI Coding Agents Keep Forgetting What They Were Doing

Aankit RoyCEOOctober 31, 20269 min read

AI coding agents can inspect a repository, understand a task, edit several files, and run tests. Yet halfway through a complicated task, they sometimes repeat steps, forget earlier decisions, or modify something they were specifically told to leave untouched.

It can look like the agent has suddenly become less intelligent. Often, the real problem is that it has lost track of the information that made its earlier decisions meaningful.

This is one of the most frustrating problems in agentic software development: maintaining continuity across long-running tasks.

To understand why it happens, we need to look at context windows, memory, conversation history, and how coding agents manage information over time.

1. why do AI coding agents forget things?

An AI coding agent does not automatically remember everything it has ever done.

When you give an agent a task, the system provides information such as your instructions, conversation history, relevant code, documentation, and tool outputs. The model uses this information to decide what to do next.

This collection of information is commonly called context.

The problem is that context has limits. Every model has a maximum amount of information it can process in a single request, known as its context window.

Imagine asking an agent to build an entire authentication system. It investigates the repository, reads several files, implements login, fixes errors, writes tests, and reviews the changes.

As the task continues, the conversation fills with code snippets, terminal output, tool calls, and previous decisions. Eventually, the agent may need to make room for new information.

When important details are no longer available in its active context, the agent can lose track of earlier decisions.

It is not necessarily forgetting like a human. It is operating without all the information that previously guided its work.

AI coding agents forget things
AI coding agents forget things

2. the context window problem

A context window is one of the most important limitations developers need to understand when building AI agents.

Every interaction consumes tokens. Instructions, user messages, code, documentation, tool definitions, and terminal outputs all contribute to the total.

Consider a coding agent working on a large application. It might read 30 files, inspect database schemas, execute several commands, and receive lengthy test reports.

All that information competes for space.

When the available context approaches its limit, agent frameworks often use a technique called context compaction. They summarize earlier interactions and replace a large conversation history with a smaller representation of the information considered important.

This allows the agent to continue working without carrying every previous message forward.

However, summarization introduces a trade-off.

A summary might preserve the overall objective but lose a small implementation detail. It might remember that authentication was updated but omit why a particular middleware was intentionally left unchanged.

OpenAI's Codex and Microsoft VS Code's agent documentation both describe context compaction as a way to support longer-running agent sessions. Anthropic has also explored the challenges of maintaining coherent progress across multiple context windows.

The lesson is important: a larger context window helps, but it does not automatically solve the problem of maintaining useful information over time.

3. why context compaction is not the same as memory

Developers sometimes assume that once an agent supports context compaction, it can work indefinitely without losing important information.

That is not entirely true.

Compaction reduces the size of the current working history. Memory preserves useful information that can be retrieved later, including across separate sessions.

They solve different problems.

Context compactionPersistent memory
Helps continue a long-running taskHelps retain information across sessions
Summarizes active conversation historyStores useful facts, decisions, and lessons
Reduces context-window pressureReduces repeated explanations
Usually focuses on current workCan preserve reusable project knowledge

Imagine an agent working on a database migration.

During the current session, compaction can preserve the migration plan, completed steps, and outstanding work. Persistent project memory might preserve the fact that the application uses PostgreSQL and requires migrations to follow a particular naming convention.

Both are useful, but neither should be treated as a substitute for the actual source code, tests, or project documentation.

OpenAI's Agents SDK cookbook explains this distinction through two reliability mechanisms: compaction for continuing the current workflow and memory for reusing lessons across future runs.

4. the real problem: agents do not always preserve their progress

There is another problem that is easy to overlook.

Even if an agent remembers the original request, it might not know exactly how much work has been completed.

Consider this task:

"Build a complete subscription management system with authentication, payment integration, subscription cancellation, and billing history."

The agent starts implementing the application. It creates the database schema, adds authentication, and begins integrating payments.

Then the context window fills up.

A new context begins with a summary, but the summary does not clearly explain which features are complete, which files are partially implemented, and which tests are still failing.

The next agent instance may start investigating everything again. It might rewrite existing code, duplicate functionality, or assume that unfinished work is already complete.

Anthropic describes this as the long-running agent problem. Its research shows why simply giving an agent a large objective and allowing it to work across multiple context windows is not enough.

A reliable system needs structured progress tracking.

For example, the agent should maintain:

  • A clear description of the overall objective.
  • A list of completed features.
  • A list of unfinished tasks.
  • Important technical decisions and their reasoning.
  • Known bugs and failing tests.
  • The exact next step.

This gives the next working session something concrete to continue from instead of forcing it to reconstruct the entire project history.

agents do not always preserve their progress
agents do not always preserve their progress

5. how developers can stop AI agents from losing context

You do not need a complicated multi-agent architecture to solve every continuity problem. A few practical engineering decisions can make a significant difference.

Use structured project instructions.

Files such as AGENTS.md can explain repository conventions, architectural boundaries, important commands, and testing requirements. This gives an agent a reliable starting point when a new session begins.

Maintain a progress file.

For long-running projects, create a simple file such as PROGRESS.md.

# project progress

## objective
Build a subscription management system.

## completed
- Authentication implemented.
- Database schema created.
- Subscription model added.

## in progress
- Payment integration.

## pending
- Cancellation workflow.
- Billing history.
- Integration tests.

## important decisions
- Use the existing PostgreSQL database.
- Keep payment logic inside the billing service.

## next step
Complete payment integration and test webhook handling.

The agent should update this file after meaningful milestones.

Keep a record of architectural decisions.

If the agent chooses a particular database structure or decides against introducing a new dependency, preserve that decision and its reasoning. Otherwise, a future session may make the same decision differently.

Break large tasks into smaller milestones.

Instead of asking an agent to build an entire application in one attempt, divide the work into authentication, database design, payment integration, and testing.

Smaller milestones make progress easier to verify and recover.

Use Git as a source of truth.

Commits, branches, and diffs provide a concrete record of what changed. Conversation summaries can be incomplete, but the repository shows the actual state of the implementation.

Verify before continuing.

When an agent resumes work, ask it to inspect the current repository, review the progress file, check Git changes, and run relevant tests before making further modifications.

The objective is to make every new session understand the actual state of the project rather than blindly trusting an old summary.

6. are AI coding agents getting better at remembering?

Yes. Agent frameworks are increasingly introducing dedicated systems for managing context, memory, and long-running workflows.

For example, OpenAI's Agents API provides managed sessions, orchestration, context compaction, and recovery capabilities. Its Codex infrastructure also uses compaction to preserve useful information when conversations approach context limits.

Microsoft VS Code supports agent context management, workspace instructions, session memory, and compaction. These features help agents retain useful project information and continue working across longer tasks.

Anthropic has explored another important approach: designing an agent workflow specifically for long-running software development.

Its research describes using an initializer agent to prepare the project environment and a coding agent to make incremental progress. The system also maintains a progress file and Git history so future sessions can understand what previous sessions accomplished.

These developments point toward a broader engineering principle: reliable agents need more than a capable model. They need infrastructure that manages information and preserves the state of their work.

Larger context windows, better memory, and more efficient compaction can help. But they work best when combined with clear task boundaries, persistent project artifacts, and automated verification.

AI coding agents getting better at remembering
AI coding agents getting better at remembering

7. what this means for the future of AI-native engineering

The ability to generate code is becoming increasingly accessible. The harder challenge is getting AI systems to work reliably on complex projects over extended periods.

A developer might spend hours understanding an application before making a small change. An AI agent needs a way to preserve that understanding, retrieve relevant information, and avoid repeating previous mistakes.

This changes how developers should think about building agentic systems.

Instead of focusing only on which model generates the best code, engineering teams must also consider how the agent receives context, stores progress, retrieves information, and recovers from interrupted tasks.

The next generation of coding agents will need to behave less like temporary conversations and more like reliable engineering systems.

They will need project-level knowledge, structured progress records, persistent memory, access to the right tools, and clear definitions of what counts as completed work.

The real breakthrough will not simply be an agent that can write 10,000 lines of code in one session. It will be an agent that can work on a project for days, understand what previous sessions accomplished, and continue without creating unnecessary problems.

conclusion: writing code is easy compared to remembering why it was written

AI coding agents are becoming more capable, but long-running development still exposes an important weakness: maintaining continuity.

Context windows have limits. Summaries can lose details. Memory can become outdated. And a new session can misunderstand the state of work completed by an earlier one.

The solution is not to rely on the model remembering everything. It is to build systems that preserve important information outside the conversation.

Project instructions, progress files, architectural decisions, Git history, and automated tests provide a foundation that agents can repeatedly return to.

As AI-native engineering evolves, the quality of an agent will depend not only on how intelligently it writes code, but also on how reliably it carries knowledge from one step to the next.

"An agent that can write code is useful. An agent that understands what it has already done is worth trusting."


references

  1. Anthropic, Effective Harnesses for Long-Running Agents: https://www.anthropic.com/research/effective-harnesses-for-long-running-agents
  2. Anthropic, Effective Context Engineering for AI Agents: https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
  3. OpenAI, Building Reliable Agents with Memory and Compaction: https://developers.openai.com/cookbook/examples/agents_sdk/building_reliable_agents_memory_compaction
  4. OpenAI, Unrolling the Codex Agent Loop: https://openai.com/index/unrolling-the-codex-agent-loop/
  5. OpenAI, Compaction Guide: https://developers.openai.com/api/docs/guides/compaction
  6. Microsoft, Understand Context in AI Agents: https://code.visualstudio.com/docs/agents/concepts/context
  7. Microsoft, Agent Conversation Compaction: https://learn.microsoft.com/agent-framework/concepts/agents/conversations/compaction

Build the thing you just read about

Start with a sentence. Leave with a working agentic app.

Why AI Coding Agents Keep Forgetting What They Were Doing · Something