The context window is your budget: CLAUDE.md and project instructions

Day 3, 25 minutes · advanced

Goal of this lessonWrite a project instruction file for a client repository that the agent follows, and keep the context window free of noise.

Why it matters

Long agent sessions often go the same way. The first hour is sharp. Then the agent forgets a rule you gave it at the start, reads the same file twice and starts to guess. When an agent seems to get worse during a long session, check its context window first: everything the model can see at once. That window is a fixed budget, and every instruction, file and command output spends part of it.

On a client job you also hand the work over. Tomas, the client's engineer, will never see the rules you typed into a chat. The rules that matter have to live in the repository, in a short file that every new session loads by itself.

At the end of this lesson the orderdesk/ repository has a project instruction file of one page at most. And you have proven, in a fresh session, that the agent follows two of its rules without being told.

What fills the window

On day 1 you saw what is sent to the model on every turn: the tool's own instructions and tool list, your instruction file, the conversation, and the results of earlier tool calls. All of that sits in the context window at the same time, and the parts do not behave alike.

The tool's instructions and your instruction file are there before you type a word. The rest grows with every step: every file the agent reads, the output of every command it runs, every turn of the conversation. A test run that prints two hundred lines takes as much room as two hundred lines you wrote yourself.

Signs of a full window

  • The agent stops following a rule you gave it early in the session.
  • It reads a file again that it already read.
  • It asks for something you already told it.
  • Its answers get vaguer while its plans get longer.

Three ways out

  1. Start fresh. End the session and begin a new one. The instruction file loads again and the clutter is gone. Between two tasks this is usually the right move.
  2. Compact. Most tools can replace the earlier turns with a summary. You keep the thread, but details from early in the session can get lost in the summary. Several tools also do this by themselves when the window is nearly full.
  3. Hand over through a notes file. Ask the agent to write what is done, what is open and which files matter into a short notes file. Start fresh and point the new session at that file. You decide what survives, not the summary.

What goes in the instruction file

An instruction file is a plain Markdown file in the repository that the agent loads at the start of every session, before your first message. It rides along on every turn, so each line in it costs room for the whole session. Keep it to one page.

Put in what the agent cannot work out by reading the code:

  • the commands to build and test, exactly as you type them
  • conventions that are not visible in the code
  • the things it must never do
  • where things live, one line per folder

Leave out:

  • long documentation: name the file instead of pasting it
  • anything the agent finds by itself, such as a list of files or what each function does
  • secrets of any kind: no keys, passwords or connection strings, also not "for now". Day 5 covers where they belong.

The steps

Start from the orderdesk/ repository of day 2. Commit what is there first, so that git can show you later exactly what the agent changed.

  1. Write the instruction file with this text. Each tool wants its own file name and place, so pick your tool below and follow the steps.
Project: orderdesk drafts replies to order-status emails for the support team of Kettlebrook Wholesale.
It only writes drafts. A person at Kettlebrook reads and sends every reply.

Commands
- Run the tests: python -m unittest
- Print the draft for one sample email: python draft_reply.py E-001
- Python 3, standard library only. Use python3 if python is not found.

Where things live
- data/: made-up order data and sample emails
- prompts/: the reply prompt (added later)
- evals/: test cases for the reply prompt and their scores (added later)

Rules
1. Never edit files in data/. They are made-up fixtures.
2. Run python -m unittest before you say a change is done, and show the output.
  1. Read it once more and cut. If your tool generated a starting file, it probably lists files and describes code. Remove every line the agent could find by reading the repository.
  2. Check that your tool has loaded the file. Where your tool has a command for that, its guide names it.
  3. Start a fresh session. If anything from earlier is still in the window, you test your chat history, not your file.
  4. Give the proof task. Do not mention the rules.
Add a function expected_delivery_for(order_id) to orders.py that returns the expected delivery date from the order data, with a test. Do not change draft_reply.py.

Nothing from day 2 reads that date, so this is new work for the agent.

Check the result

Check the evidence, not what the agent says about itself:

  • Rule 2: the transcript shows that the agent ran python -m unittest before it called the change done, and that it showed you the output.
  • Rule 1: git status -- data/ shows no change.

When both hold, commit twice: first the instruction file, then the new function with its test. Day 4 reviews that second commit as change A.

In a chat tool

We found no vendor page that shows a chat product running the tests in your repository, so its two rules are about the reply instead:

  • Rule A: answer in the language of the customer's email.
  • Rule B: never state an order status that is not in the order data. If the order is missing, say you cannot find it.

Save the rules as instructions that load in every chat, give the assistant the six order rows, and test in a fresh chat with two sample emails. E-005: Emma writes in Dutch, so the draft must come back in Dutch. E-004: Marco asks about WH-19999, which is not in the data, so the draft must say it cannot find that order. The guides below show where each product keeps saved instructions and where the order rows fit.

When a rule is not followed

  • Make the rule concrete. "Run python -m unittest" works better than "test your work".
  • Look for a second instruction file that says something else. Several tools read more than one file name and combine them.
  • Remember what the file is: context the model reads, not a lock. A rule that must hold every single time becomes a hook on day 4: a script the tool runs by itself at a fixed moment.
  • Throw away the agent's change (git restore for changed files, delete the files it added), then test again in a fresh session, never in the one where you edited the file.

How the tools name the file

  • Claude Code: CLAUDE.md in the project root. It reads AGENTS.md when there is no CLAUDE.md.
  • OpenAI Codex: AGENTS.md. It reads the files when a session starts, so restart after a change.
  • Gemini CLI: GEMINI.md. Other file names can be added in its settings.
  • Cursor: AGENTS.md or CLAUDE.md in the project root, next to its own Rules.
  • GitHub Copilot CLI: .github/copilot-instructions.md, and it also reads AGENTS.md, CLAUDE.md and GEMINI.md.
  • The four chat products: saved instructions in a project or in the account settings, not a file in the repository.

If the client's team uses several of these tools, keep the rules in one file and check which names each tool reads. Two near-copies drift apart.

Keep it working

The file belongs to the repository, not to you. When a command changes, change the file in the same commit. On day 7 Tomas takes the repository over, and his agent loads this page in every session.

Deeper dive

Today's actions

Ticks are not saved without an account

Do it in your tool

Claude

  1. Open Claude, hover over the left side and click Projects.
  2. Click + New Project in the upper right corner and name it orderdesk. Claude does not see the name.
  3. Click the + button in the project knowledge area on the right and upload orders.csv from day 2. If you have no copy, save these six rows as orders.csv first.
    order_id,customer,status,expected_delivery
    WH-10432,Sanne,delayed,2026-12-03
    WH-10433,Daan,shipped,2026-11-30
    WH-10434,Priya,processing,2026-12-05
    WH-10435,Marco,delivered,2026-11-24
    WH-10436,Emma,shipped,2026-12-01
    WH-10437,Priya,processing,2026-12-08
  4. Click Set project instructions, paste this text and click Save instructions.
    You help the support team of Kettlebrook Wholesale draft replies to order-status emails. A person checks every draft before it is sent.
    Order numbers look like WH- plus five digits. The order data is in the project file orders.csv.
    Rule A: answer in the language of the customer's email.
    Rule B: never state an order status that is not in the order data. If the order is missing, say you cannot find it.
  5. Start a new chat inside the project and paste the email from Emma. Do not mention the rules.
    Draft a reply to this email from Emma:
    
    Hallo, waar blijft mijn bestelling WH-10436?
  6. Check that the draft is in Dutch. Then paste the email from Marco in the same chat.
    Draft a reply to this email from Marco:
    
    Where is WH-19999? It should be here by now.
  7. Check that the draft says it cannot find WH-19999 and states no status for it.

Note: Claude's help pages disagree: one says Projects are open to all users, free accounts included (up to five projects), another lists project instructions under paid plans only. Check your own plan before you count on it. If Set project instructions is missing, put the text under Settings, Your Claude, Instructions (older layout: Account, Instructions for Claude) and paste the order rows as your first message.

Checked on 27 November 2026 · Source: Claude Help Center: Create and manage projects (opens in a new tab)

Create a free account to save your progress. Sign in or sign up