Cactus can help your business benefit from AI through "StartAI", the AI program of Agoria and Vlaio

How Engineers Keep AI Models From Getting Dumber

AI Context plan-md by phases

 

AI coding agents do not usually fail because the model suddenly became useless. They often fail because the context got dirty. As the context window fills up, the model becomes less precise, less consistent, and more likely to follow stale assumptions from earlier in the conversation. It may edit the wrong file, reintroduce a bug, forget constraints, or solve an old version of the problem. That is context pollution.

A context window is not real memory. It is the model’s current working set: instructions, files, terminal logs, stack traces, previous attempts, tool outputs, decisions, and your latest request. When that working set is clean, the model reasons better. When it is overloaded, every irrelevant token competes with the information that actually matters now.

 

Context usage

 

This is why engineers working with tools like Codex, Claude Code, OpenCode, and Cursor do not treat long tasks as one endless conversation. They break work into phases: research, scope, design, setup, implementation, integration, testing, refactor, and documentation. Each phase has a clear objective, a limited set of relevant files, a definition of done, and a short handoff before moving to the next one.

A good workflow is simple: save the plan in plan.md, break it into phases, complete one phase, update the plan, summarize what changed, then decide whether to use /compact or start a new session. The goal is not to preserve the whole conversation. The goal is to preserve the state required for the next correct action.

Use /compact when the current session is still directionally correct but too full. It compresses the conversation into a smaller summary, keeping the important decisions, files, constraints, and current state while dropping a lot of operational noise. It is useful between phases when the plan is still valid, the architecture is still clear, and you want continuity without carrying every command, log, and failed attempt forward.

Start a new session when the context is not just full, but polluted. If the agent is following old assumptions, mixing abandoned approaches with current ones, repeatedly editing the wrong area, or the task has changed direction, compaction may preserve some of that confusion. A fresh session with a clean plan.md handoff is often better: current goal, completed work, files changed, known issues, test status, and the next task.

This is also why OpenAI and Anthropic talk so much about context management, compaction, memory, agent harnesses, subagents, and long-running workflows. OpenAI describes context management as a major challenge for large agentic tasks and recommends giving Codex a map instead of a huge instruction manual. Anthropic describes compaction as a way to summarize a near-full context window and continue with a cleaner working set.

Prompt engineering was the first layer. Context engineering is the next one. The best AI engineers are not only good at asking the model what to do. They are good at managing the environment in which the model works.

A clean context creates sharper reasoning. A polluted context makes even strong models look dumb.

 

So the next time your AI coding agent starts making strange decisions, do not just blame the model. Ask this instead: is the context still clean enough for the task? Sometimes the smartest move is to save the plan, finish the current phase, compact if the session is still healthy, or start a new session if the context is already polluted.

References worth reading:

  • OpenAI — Harness engineering: leveraging Codex in an agent-first environment
  • OpenAI Codex docs — Context management, compaction, and subagents
  • Anthropic — Claude Code best practices
  • Anthropic — Effective context engineering for AI agents
  • Anthropic — Context compaction for long-running conversations and agentic tasks

Share this page

Dianas picture 2x

If there is a project needing help or even a skill set you are missing, contact us.

Similar Articles

Contact us today to explore how Cactus
can support your digital journey