Session context
why the AI starts getting confused towards the end
What it is
Context is everything the AI "sees" in the current conversation: your messages, its own replies, the files it read, the output of commands. It has a limit, and as a conversation approaches it, the quality of the answers drops.
It drops gradually rather than sharply — which is why the signs are worth recognising early.
What it looks like in code
Signs that the context is full
| Sign | What is happening |
|---|---|
| The AI forgot a requirement from the start | the old was pushed out |
| It returns to a rejected solution | both versions are in the context |
| It contradicts itself in neighbouring replies | it leans on different parts of the history |
| The answers got shorter and vaguer | less room for reasoning |
| It "re-read" a file and produced the old version | it remembers the first read, not the last |
The last sign is the most treacherous with an agent: the file changed long ago and the AI is reasoning about what it saw at the start of the session.
What takes up the room
The biggest consumers are not your messages but:
- files that were read — an agent reads the whole file even when one function is needed;
- command output — long logs, file listings, test output;
- the AI's own replies — especially long code listings;
- rejected versions — everything you tried stays in the history.
What to tell the AI
The main technique is not to accumulate anything unnecessary.
Read only the fetch_weather function from handlers/weather.py,
not the whole file.Show only the last 20 lines of the log, not the whole file.When the session is already long, compression helps — ask the AI for a summary you can carry into a new session:
Summarise: what we did, which decisions we made and what is
left. Briefly, so I can start a new conversation from that text.To check whether the context has drifted:
Which requirements for this task do you currently remember?
List them.If something you agreed at the start is missing from the list, it is time to start over (article 5.4).
What to look for
Files read in full for no reason. One thousand-line file pushes out the whole previous conversation.
Long logs pasted in their entirety. What is needed is the chunk around the error, not all of it.
A session that has run all day. By evening it holds three abandoned approaches and two versions of the code. Starting over is easier than explaining which of it is out of date.
"But you remember" as an argument. If the AI forgot, repeating is cheaper than finding out why it forgot.
Cheat sheet
Context is finite; the longer the session, the less room for the task.
Signs: forgot a requirement, returned to a rejected idea, contradicts itself.
The biggest consumers are files that were read and command output.
Ask for part of a file and part of a log, not all of it.
The check: "which requirements do you currently remember?"
A long context does not make an AI smarter.