What drift looks like
You start a session aligned, but a couple hours in the agent reintroduces a pattern you rejected, mixes styles, or ignores a constraint you set early on. That gradual divergence is drift.
It's subtle — each step looks reasonable — which is why it's easy to miss until the code is inconsistent.
Why it happens
As the conversation grows, earlier messages get summarized or pushed out of the context window. The constraint you set 200 messages ago simply isn't in front of the model anymore.
The agent isn't being careless; the information that would keep it consistent has fallen out of view.
Anchor with persistent memory
Put your durable conventions and constraints in a project memory file the agent reads every session. That way the anchor doesn't depend on staying in the live conversation.
It's the single most effective defense against drift — the rules are always re-supplied.
Re-anchor long sessions
When a session runs long, summarize the state and restate the key constraints to bring them back into the window. A quick 're-anchor' resets the agent's focus.
Starting a fresh session for a new sub-task is often cleaner than letting one balloon.
Scope context and verify
Give the agent only the relevant files for the task, and work in small, verifiable steps so drift is caught immediately rather than after a big change.
Frequent review keeps a small divergence from compounding into a rewrite.