What you will be able to do
- Name every instruction file your harness loads at session start, and confirm what actually loaded.
- Write a short instruction file that holds only what the agent can't learn from the code.
- Keep memory and settled decisions from turning into a pile of stale, contradictory notes.
- Hand the agent the real reference (the file, the log, the page to copy) instead of describing it.
- Recognise stale context after a long session or a compaction, and check the live system before acting on it.
Module 1 was about the one message you write for a task. This module is about everything else the agent reads. Most of it you wrote weeks ago and forgot. Some of it is out of date. Some of it contradicts your brief. The model can't tell which part is current; you can.
2.1 What loads before you type
Every harness puts some text in front of the model before your first message. The biggest part you control is the instruction file: a Markdown file of standing rules for a project or for you. The two names you'll meet most:
CLAUDE.mdin Claude Code. Your personal one lives at~/.claude/CLAUDE.mdand applies to every project. A project one at./CLAUDE.mdor./.claude/CLAUDE.mdis shared with the team.CLAUDE.local.mdholds your private notes for one project and belongs in.gitignore. Files in the working directory and every directory above it load at launch; those in subdirectories load when the agent works in that subdirectory. They are concatenated, not overridden (How Claude remembers your project).AGENTS.mdin Codex, and a shared convention across several harnesses. Codex reads a global file from its home folder (~/.codexby default), then walks from the project root down to your working directory, taking at most one file per directory (AGENTS.override.mdfirst, thenAGENTS.md). Files are joined from the root down, so the one closest to you appears last and takes precedence. Codex stops adding files once the combined size reachesproject_doc_max_bytes, which its docs give as 32 KiB by default (Custom instructions with AGENTS.md).
Claude Code can also read AGENTS.md: by default it does so when there is no CLAUDE.md in your working directory or above it. If a project has both, Claude reads the CLAUDE.md files only, unless one of them imports AGENTS.md with an @AGENTS.md line (AGENTS.md in Claude Code). If your team uses two harnesses, keep one file and import it from the other, so the rules can't drift apart.
Confirm, don't assume
The file you think loaded and the file that loaded are often different: a file in the wrong folder, a size limit hit, a CLAUDE.local.md that quietly stopped AGENTS.md from loading. Check:
# Claude Code: inside a session
/context all
# Codex: from the repo root, per its AGENTS.md guide
codex --ask-for-approval never "Summarize the current instructions."
Our free /context-audit goes further for Claude Code: it reads the newest session transcript, which records what loaded and how big each part was, prints a table largest first, and flags files cut off at load, links to missing files and paths that no longer exist.
The common mistake
Treating instruction files as enforcement. They aren't. Anthropic is direct about it: CLAUDE.md and memory are context the model reads, not enforced configuration, and a rule that must never be broken belongs in a hook (memory docs). Write instruction files as advice to a capable colleague. Put the absolute rules in guardrails.
Open your harness in a project you use daily and list every instruction file it loaded, with its path and rough size. Use /context all in Claude Code or the Codex summary command above. Note one file you expected that didn't load, or one you'd forgotten existed.
2.2 What to write, and what to cut
Everything in an instruction file is read on every task, relevant or not. A long file costs tokens every session and, worse, dilutes the lines that matter. Claude Code's docs suggest keeping each CLAUDE.md under 200 lines, because longer files reduce how well the instructions are followed (memory docs). The test for each line: could the agent work this out by reading the repository? If yes, cut it.
What earns a place, following Anthropic's own list (keep CLAUDE.md short):
- How to check work here. The exact test, typecheck and lint commands, and how to run one test file.
- Places where the code misleads. An old pattern that's everywhere but mustn't be copied. A folder that looks dead but isn't.
- Decisions that aren't in the repo. How deploys work. Which error helper the team chose. What needs a migration review.
- Anything you've corrected twice.
Here is a real-looking file that passes the test:
# shop-api
## Check your work
- Tests: `bun test` (one file: `bun test test/orders.test.ts`)
- Types: `bunx tsc --noEmit`
- Integration tests need DATABASE_URL; see .env.example
## Misleading code
- src/legacy/ is live (old mobile app). Don't copy its callbacks
into new code; use src/lib/async.ts.
- `price` is in minor units (grosze/cents) everywhere. Never divide
in the API layer.
## Decisions
- Deploys go through CI on merge to main. Never deploy by hand.
- Errors: throw AppError from src/lib/errors.ts, never raw strings.
## Gotchas
- bun.lockb breaks the Node CI image; commit package-lock.json only.
Twenty lines. No project overview the agent could get from README.md, no description of the folder layout it can list, no "write clean code".
What to cut
| Cut this | Because |
|---|---|
| Architecture and file layout tours | The agent reads the repo. Anthropic lists this as old advice to drop. |
| IMPORTANT, ALWAYS, capitals | Current models follow a plainly worded line; emphasis mostly makes the rule over-applied. If a rule can't bend, make it a hook. |
| "Be thorough", "don't be lazy" | Ordinary text, not a control. It tends to cause over-work. Give a check to pass instead. |
| Status: "LIVE", "deployed", "v2 shipped" | True the day you wrote it. It goes stale silently and the agent will trust it. State belongs in memory with a date, or nowhere. |
| Long procedures used once a month | Move them into a skill or command that loads only when called. |
The first three rows come straight from Anthropic's list of advice that has aged out (Claude Code best practices).
Scope rules to where they apply
A rule that only matters for one part of the code shouldn't load for every task. Claude Code reads rule files from .claude/rules/; a rule with a paths: list in its frontmatter loads only when the agent works with matching files (path-specific rules). In Codex, a nested AGENTS.md in a subfolder does a similar job for that part of the tree.
---
paths:
- "migrations/**"
---
Every migration needs a down step and a note in docs/migrations.md.
The common mistake
Contradictions. A user file says "always use tabs", a project file says "two spaces", a rule file from last year says "follow Prettier". The model may pick one arbitrarily, which the memory docs say in as many words. Read all your instruction files together, the way the model does, at least once a month.
Take your longest instruction file. Mark every line the agent could learn from the repository, every capitalised rule, and every status claim. Delete them, or move status to dated memory. If the file was over 200 lines, get it under. Then run a normal task and see whether anything got worse.
2.3 Memory and decisions
Instruction files are what you write. Memory is what accumulates: notes the harness or the agent keeps between sessions. Claude Code's auto memory is written by Claude from your corrections and preferences; at session start it loads the first 200 lines or 25 KB of the project's MEMORY.md, which acts as an index of topic files (auto memory). Other harnesses have their own forms; the principles are the same.
Memory is useful exactly as long as it is true. Three habits keep it that way:
- Date every fact about state. "Billing service on v3 (checked 2026-11-20)" is a lead to verify. "Billing service is on v3" is a trap in six weeks.
- Keep the index short, the detail elsewhere. The index line says what and where; the topic file holds the why. An index that loads only its first lines must put the most important ones first.
- Prune on a schedule. Merge duplicates, delete what's no longer true, fix links to files that moved. A memory that only grows becomes noise.
Decisions and lessons
Two kinds of note deserve their own handling because they're the ones that come back as fresh questions. A decision is a settled choice with its reason ("we stay on SQLite until 50 writes per second; Postgres was rejected for ops cost"). A lesson is a correction turned into a rule ("reload the page before calling a UI change done"). Write each once, with the reason and the date, in a place every session sees.
> /decision keep the API dependency-free; zod was proposed and rejected
Logged: 2026-11-28 · dependency-free API · reason: zero-install
deploys on shared hosting. New sessions will be told it is in force.
> /lesson mine
3 corrections you gave more than once and never filed:
1. "check the live page, not localhost" (4 times, 3 projects)
...
/decision and /lesson are part of our free skills for Claude Code. The idea needs no tooling: a DECISIONS.md with one dated line per choice and its reason, linked from the instruction file, does the same job in any harness. Module 7 builds the full habit.
The common mistake
Storing a rule twice. The same rule in CLAUDE.md, memory and a skill will drift: someone updates one copy and the agent now holds two versions. One home per rule; other places link to it.
Open your harness's memory or notes for one project. Find one fact without a date, one duplicate, and one claim you can check right now. Check it. If it's wrong, fix it and note how long it had been wrong.
2.4 References and examples
An agent can follow a description, but it copies an example far better. When you have the thing, hand it over instead of describing it.
- A file. In Claude Code,
@src/utils/auth.jsin a message includes the file's content (reference files and directories). In any harness, the exact path is better than "the auth file". - Output. Pipe the log in rather than paraphrasing it:
cat error.log | claude -p "what's going on here"is Anthropic's own example. - A screen. A screenshot of the bug, or of the design to match, says more than a paragraph about it.
- A reference to copy. "Make the pricing page like stripe.com/pricing" is vague. "Copy the structure of pricing/team.html (three columns, toggle above, FAQ below) with the new content" is a spec.
The strongest reference is one from the same codebase. "Add an endpoint for refunds; follow the shape of src/routes/orders.ts exactly, including the error handling and the test file next to it" gets you code that looks like the rest, because it was copied from the rest.
Add GET /api/refunds/:id.
Reference: src/routes/orders.ts and test/orders.test.ts.
Copy their structure: validation first, AppError for failures,
one happy-path test and one 404 test. Same naming style.
Don't introduce a new pattern; if orders.ts does something you'd
do differently, do it the orders.ts way and tell me in the reply.
When you name a reference, it's binding
If you point at a reference, the agent should take its structure and use your content. The failure is the agent "taking inspiration", which in practice means writing its own default and keeping one detail from yours. Say plainly that the reference is the shape to follow, and check the result against it.
The common mistake
Pasting too much. Ten files "for context" where two matter, a whole log where the last forty lines hold the error. Every irrelevant token competes for attention with the relevant ones. Give the smallest reference that shows the pattern, and the path to the rest if it's needed.
Pick a small feature that has a sibling in your codebase. Brief it twice in two fresh sessions: once described in words, once with "follow this file" and its path. Compare the two diffs for how closely each matches the codebase's style.
2.5 The context window, compaction and stale context
Everything in a session (instructions, your messages, every file read, every command output) sits in the model's context window. When a long session nears the limit, harnesses compact: they replace the conversation with a summary and continue. Claude Code does this automatically before the window fills, and you can run it yourself with a focus, for example /compact keep the API changes and the test commands (keep cost and context down).
A summary is shorter than what it replaces, so it loses things. What it tends to lose is the detail that matters most to resuming: the exact stopping point, the branch that isn't pushed, the approach that already failed. After a compaction the agent continues confidently from the summary, and it can't know what the summary left out.
Protect state before it compacts
- Write state to disk at milestones. A short file with done, in progress, not started, decisions and where to resume. Our free
/checkpointwrites one after checking git, and our compact hook turns every compaction into such a file and keeps the raw transcript beside it. - Ask before you compact. Is anything still running? Is there uncommitted work with no checkpoint? Our
/compact-checkanswers in three lines. - Start fresh between unrelated tasks.
/clearin Claude Code costs nothing and stops the next task paying for the last one's history.
Stale context is not state
The deeper problem isn't compaction. It's that anything in context describes the world at the moment it was read. The test run from an hour ago, the file read before another agent edited it, the "deployed" note from yesterday: all of it may be false now. The rule we use: check the live system before you act on what the session remembers.
Agent: The fix is deployed (from earlier in the session), so I'll
close the ticket.
You: Check first.
Agent: $ git log origin/main --oneline -3
a41c9e2 Revert "fix: retry webhook on 502"
...
The fix was reverted 40 minutes ago by another session.
Not closing the ticket.
Make it a habit in your briefs and your instruction file: before any action that depends on state (deploying, closing, merging, reporting), re-read the state from its source. Git, the live URL, the database, the CI page. Not the conversation.
The common mistake
Correcting a session that has gone wrong three times in a row. Each failed attempt stays in context and the agent keeps re-reading it. Anthropic's advice is to /clear after two failed corrections and write one better prompt that folds in what you learned (steer the session). Sometimes the best context is less context.
In a long session you have open, ask the agent to list every fact it is relying on about external state (branches, deploys, test results, other people's work), each with when it last checked. Then have it re-check three of them from the source. Count how many had changed.
Practice task
Rebuild the context for one project you use every week, then prove the rebuild helped.
- Inventory: list every instruction file and memory file the harness loads for this project, with sizes. Confirm with
/context allor the Codex summary command. - Read them all together, in load order. Mark contradictions, duplicates, status claims and lines the agent could learn from the repo.
- Rewrite the project instruction file to pass the "can't learn it from the code" test. Move path-specific rules into scoped files. Move procedures into a skill or a linked document.
- Date or delete every status claim in memory. Record two settled decisions with their reasons.
- Run the same small, realistic task in a fresh session before and after the rewrite (use a branch or worktree each time) and compare the transcripts.
Success criteria.
- You have a written list of what loads, confirmed by the harness, not from memory.
- No contradictions remain between the files that load together.
- The project instruction file is under 200 lines and contains the exact commands to check work.
- Every remaining status claim has a date, and you checked at least one against the live system.
- The after-run needed fewer corrections or fewer exploratory reads, and you can point to where in the transcript.
Check yourself
In Claude Code, which CLAUDE.md files load at launch, and which load later?
Files in the working directory and every directory above it, plus your user file at ~/.claude/CLAUDE.md, load at launch. Files in subdirectories load when the agent works with files in that subdirectory. All of them are concatenated rather than overriding each other.
How does Codex decide which AGENTS.md wins?
It reads the global file, then walks from the project root to the working directory, taking at most one file per directory, and concatenates them from the root down. The file nearest your working directory appears last, so its guidance takes precedence. It stops once the combined size reaches project_doc_max_bytes.
What is the test for whether a line belongs in an instruction file?
Whether the agent could work it out by reading the repository. If it could, cut it. Keep the commands to check work, places where the code misleads, decisions that aren't in the repo, and anything you've corrected twice.
Why are status claims like "deployed" dangerous in memory?
They go stale silently and the agent trusts them. Date every fact about state so it reads as a lead to verify, and check the live system before acting on it.
A session has failed the same correction twice. What do you do?
Start a fresh session (/clear in Claude Code) with one better prompt that includes what you learned. A third correction adds to a context already full of failed attempts.
Key takeaways
- Know exactly which instruction files load, and confirm it with the harness.
- Instruction files are advice, not enforcement. Absolute rules go in hooks.
- Write only what the agent can't learn from the code. Keep each file short; scope rules to where they apply.
- Date state in memory, keep one home per rule, prune on a schedule.
- Hand over the real file, log, screen or reference instead of describing it.
- Checkpoint before compaction. Check the live system before acting on what the session remembers.
Go further
- Module 1: The brief: the task-level context that sits on top of everything here.
- Module 3: Decomposition: how to give each session and subagent only the context it needs.
- Module 7: Compounding: turning corrections into rules, skills and hooks.
- Free skills:
/context-audit,/checkpoint,/compact-check,/decisionand/lesson. - Guided training and certification.