All courses

The context window: the agent's working memory

Explain that everything in a session (instructions, messages, files read, command output) shares a fixed token budget. Predict what fills it fastest: large files, long logs and long sessions.

Builds on: Tokens: how models measure text, What the agent can and cannot see

Read it card by card Start the whole course

Where did your first instruction go?

You ask the agent why the nightly data import fails. It reads `app.log` (8,000 lines) and several source files, and you go back and forth with it for an hour. Then it edits a file that your very first message told it to leave alone. You never changed that rule, and the agent did read it. So why did it stop following it?

One desk, and everything goes on it

Each session has one working memory, the **context window**: a fixed number of tokens. Everything goes into it: the tool's built-in instructions, any instruction file, your messages, the agent's own replies, every file it read and every line of command output. There is no separate notebook. At each step the model rereads all of it, so anything that gets pushed out stops shaping what it does.

The rules of the budget

- The budget is fixed for each model, often around 100,000–200,000 tokens. Some models have more. - Whatever enters the context stays and counts for the rest of the session. Nothing leaves on its own until the budget runs low. - **Fastest fillers:** large files read in full, long command output and logs, and long sessions, where everything piles up. - Near the limit, tools usually summarize or drop older material to make room. Details get lost, including your early instructions.

Reading a log: whole vs. targeted

Ask for only the part that matters. `tail -n 200` prints just the last 200 lines of a file, and only those lines enter the context. The token counts are rough. They assume log lines of about 60 characters, and plain text runs about four characters per token, so each line is about 15 tokens.
# Costly: the whole file
▸ You: why does the import fail? see app.log
⚙ Read: app.log
# 8,000 lines ≈ 120,000 tokens
# over half of a 200,000-token budget

# Targeted: only what matters
▸ You: check only the last 200 lines of
  app.log and find the error that ended the run
⚙ Run: tail -n 200 app.log
# 200 lines ≈ 3,000 tokens

Remember

Everything in a session (instructions, messages, files read, command output) shares one fixed token budget. Big files, long logs and long sessions fill it fastest. When it gets full, the earliest details are the first to blur or disappear.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.