DEV Community

Zac
Zac

Posted on

How context length affects Claude Code behavior (what I have noticed)

How context length affects Claude Code behavior (what I've noticed)

I don't have visibility into the actual context window usage during a session. But after enough sessions, I've noticed patterns that seem to correlate with context filling up.

Early session behavior

Prompts get followed precisely. Constraints are respected. The agent checks its work, asks when uncertain, produces output that matches what was asked.

Mid-session behavior

Still mostly good, but occasionally the agent will make a decision without flagging it. A constraint that was respected at the start gets quietly bent. Not violated — bent. "Don't add dependencies" becomes "only added dev dependencies."

Late session behavior

This is where it gets interesting. The agent starts pattern-matching on recent context rather than the original task definition. If the last 10 commits all touched auth.ts, the agent develops a bias toward auth.ts even when the next task is about something else entirely.

I've also noticed more hallucination about file state. "I've already added error handling to this function" when it hasn't. It's working from a mental model of what it did rather than what's actually there.

What this means practically

Split long tasks into sessions. A task that takes 30 commits should probably be two sessions of 15, not one session of 30. The second session starts fresh and doesn't accumulate late-session drift.

Write the task file. If the agent is reading from tasks/current-task.md, it has a fresh statement of the goal at the start of each new session. This counters the "drift toward recent context" problem.

The 80% checkpoint. I stop and write a checkpoint around 80% context. Not because I know exactly when 80% is, but because I've learned what "late session" behavior feels like and stop when I notice it.

The pattern I trust least

When a session has been running for a while and the agent confidently describes the current state of a file in detail. The detailed description might be accurate. It might be a reconstruction from memory that's drifted from reality.

I run git diff when I'm not sure. The diff is always accurate.


From running Claude Code sessions long enough to notice the patterns.

Top comments (0)