Loading WURK...
RomanMotion
RomanMotion
Product ad & launch videos · 3D product visuals · app & AI builder. Concept to final cut in days. Open for projects.

Keep your coding agent on track: context windows and the fix

Give your agent the right project context, preserve decisions, and start each task without dragging along a messy chat.

Published on October 30, 20266 min read

Your coding agent fixed the bug earlier, but now it has brought the same bug back. If you keep working from a drifting session, you can spend your next review undoing changes you already settled. This guide shows you how to carry the right context into each task and check what survived the handoff.

Start a fresh session for a distinct task, give the agent a short project notes file, and supply the relevant code and errors. Before switching tasks, save decisions and unfinished work somewhere you can inspect, then verify that the next session reads them.

What a context window actually holds

A context window is the amount of information a language model can work with at once. It is measured in tokens: pieces of text that are not necessarily the same thing as words. Instructions, conversation history, code, and tool results can all take up space. This context-window explainer describes the window and how tokenization relates to it.

For a particular response, the model works from the information included in that request. An agent may also read files or use other tools and bring their results into a later request. A fact sitting in your repository is useful only if the agent finds and uses it.

As a session grows, the application may summarize or remove earlier material to stay within its limit. Even if a rule is present, the agent can still overlook or misapply it. A forgotten instruction does not automatically prove the context window was full.

Watch for practical symptoms: the agent changes a rule you already settled, reintroduces a fixed bug, or asks for a file you already discussed. Treat those as reasons to check what the current session knows, not as a diagnosis on their own.

Give each task a clean starting point

Start a fresh session when you move to a distinct piece of work. Instead of carrying a long conversation about a login bug into a styling task, give the new session a short description of the styling change and the relevant project rules.

A fresh session needs enough information to work. Include the goal, the expected behavior, the files or directories likely to matter, and anything that must stay unchanged. If you know the relevant test command, provide it. If you don’t, ask the agent to locate the project’s documented command and report what it finds.

Try an opening like this:

Read the project notes at PROJECT-NOTES.md first. Then inspect the settings page and its related tests. Add the requested display option without changing how settings are stored. Explain your plan before editing, and report which checks you run.

Replace the file and task with your own. If the agent cannot find the notes, have it stop and tell you instead of assuming it read them.

If you want a harness that keeps a plan across long tasks, you can try the ZCode agent harness free with our invite link. Whatever agent you use, check its response for the actual rules and files it found; a fresh session does not load your project’s decisions by magic.

Keep a short project notes file

Put durable instructions in a file the next session can read. A useful notes file tells the agent how to work in this repository without becoming a second, sprawling history of the project.

Include the project’s purpose, the build and test commands, important file locations, and rules that should survive a task switch. Record constraints such as “do not modify deployment settings” or “validate form submissions on the server” only when they genuinely apply to your project.

Separate settled decisions from open questions. If a storage choice is still under discussion, label it as open. Otherwise, the next session may treat a proposal as an instruction.

A compact starting point:

Project: [what this app does]

Start here:
- Main code: [path]
- Tests: [path]
- Build command: [verified command]
- Test command: [verified command]

Rules:
- [rule that applies across tasks]
- [files or settings that need approval to change]

Current decisions:
- [decision and where its implementation lives]

Open questions:
- [unresolved choice]

Keep secrets, private keys, and credentials out of the notes. After the agent reads the file, ask it to summarize the constraints relevant to the current task. Compare its answer with the file before letting it make changes.

Send the evidence, not the whole conversation

When something fails, give the agent the exact error, the action that produced it, and the relevant code or file paths. Include what you expected to happen and what actually happened. That is easier to work from than “it broke again.”

Paste enough surrounding code to make the error understandable. Include a related test or interface when it defines the expected behavior. If the agent has repository access, point it to the files and ask it to read them instead of pasting unrelated directories into the chat.

Remove credentials and personal data from logs before sharing them. Preserve the useful parts: the error text, relevant stack trace, and steps needed to reproduce the problem.

Ask the agent to identify what it has inspected and what remains unknown. If it proposes a fix based on a missing file or an assumed API response, have it check that evidence first. You can also ask it to explain why the proposed change would not bring back an earlier bug.

If you code with agents every day, you can get a referral discount on GLM coding plans with our referral link; Z.ai's campaign terms give invited users a referral discount on their first subscription. Both Z.ai links here are our invite links, and we may receive referral credits.

Make the handoff inspectable

Before leaving a session, ask for a short handoff rather than relying on the chat transcript. Request the goal, changed files, decisions made, checks run, results, remaining risks, and the next action. Ask the agent to distinguish a completed check from one it could not run.

Then compare the handoff with the actual changes and test output. An agent’s summary can omit a file or describe an intended fix as a completed one. Keep the evidence that matters: the relevant diff, test result, and any unresolved failure.

Move lasting decisions into the repository notes or another project document your team uses. Keep the task handoff separate from permanent rules: “the test command is…” belongs in project guidance; “this test failed during the current change” belongs in the handoff until resolved.

When you start the next session, point it to those records and ask it to inspect the current code. If the handoff conflicts with the repository, resolve the difference before continuing. A summary is a useful map, not a substitute for the files it describes.

Session hygiene checklist

Save this checklist for the next task:

  • □ Start a fresh session for a distinct task
  • □ Point the agent to the current project notes
  • □ State the goal, boundaries, and expected result
  • □ Share relevant files, errors, and reproduction steps
  • □ Keep credentials and private data out of pasted context
  • □ Ask what the agent read and what it still needs
  • □ Verify changes and test results before calling work done
  • □ Save decisions, unresolved issues, and a short handoff

If the agent drifts, stop adding instructions to the same thread. Check the notes and the current code, correct the handoff, and restart with the smallest useful task. Find more practical agent teardowns on our blog.

For another way to structure the task, read WURK’s guide to prompting patterns.

If this helped you keep a session on track, a small tip on this post helps keep these guides coming.

Conversation

Join the conversation

Share your thoughts with the author and other readers.

Comments0

Checking your account…

Latest comments

0
No comments yet. Be the first to share your thoughts.