Module Structure
AI doesn't get dumber. It runs out of attention.
«AI nimani ko'rmoqda — va nimani unutib qo'ydi»This technique is the most useful in the course. But it's up to you to decide. One skill: seeing what's in the agent's context, what it has already lost, and how to replenish it. Without this, Claude Code turns into a fortune teller by the third hour of work.
Hook — why powerful AI gets dumber by evening.Nega kuchli AI kechqurun ahmoqlashadi
In the morning, you opened claude in ~/mars/src/. The idea was to rewrite the notification router. The morning went smoothly: the agent read 12 files, found the right module, proposed a plan. You agreed. It did it. Tests are green.
Then you stayed in the same chat. Added a second task. A third. By lunch — refactoring migrations. By five — discussing another piece of the sales funnel.
At seven in the evening, you asked it to “run the tests we passed this morning.” And that's when it started rewriting a completely different file. It doesn't remember what you decided in the morning. Confidently heading for a wall.
This isn't a bug. It's not “the model is tired.” This is context rot — and it's the first thing an operator learns.
Three skills I'll check
- To launch
/compactbefore the agent started hallucinating in a long session — based on observed signals, not a timer. - Delegate
ExploreorPlansub-agent (built-in or your own via/agents), when the task requires file exploration, not editing. - Explain what survives
/compact, that there is no, and why project-rootCLAUDE.md— the only reliable rule carrier for a long session.
Mental model — The context window as working memory.Context window — bu working memory
The main idea of the module: an agent has a finite attention budgetLet's break down how it's spent, why the agent "gets dumber" by evening, and three tricks that fix it.
1. Attention is a budget, not a shelf
The model has attention budget — final, like a human's. Each new token (word, symbol, piece of code) is a deduction from this budget. If you give 200,000 tokens, attention is spread thin. If you give 10,000 necessary ones, attention is concentrated. More context ≠ better.
The more text in the window, the harder it is for each word to maintain connection with all others — attention blurs. Important: this not a break at some number, and a smooth blurring.
2. Context rot — not "forgotten," but "blurred.
This has a name— context rot ("context rot"): the more tokens in the window, the worse the agent is at extracting what's needed from them. This isn't a bug of a specific model, but a general property – it's not cured by a "harsher prompt," but by techniques from the next section.
Operator's rule: if you notice a convention violation, unnecessary Reads, or "confident nonsense" — this is not a reason to write a harsher prompt. It's a signal to apply a technique from the next section.
3. Anatomy of effective context — what to keep in the window at all
Definition in one phrase: good context is the minimal set of necessary tokens, which gives the maximum chance of getting the desired result. Not "more context," but less noise and more density.
The sweet spot is between two extremes: overly strict rules "for every case" (fragile, breaks on new) and overly general "figure it out yourself" (the agent guesses). You need to be in the middle: specific enough to be verifiable, and flexible enough for the agent to think.
For the operator, this means: CLAUDE.md is not "everything I know about the project". It's a set of specific rules, each of which you can verify via a diff to see if it was applied. If a rule cannot be verified, it's taking up space in the context unnecessarily.
Three techniques long-horizon from the Anthropic blog.Uzun masofa uchun uchta texnika
This is the heart of the module. Three techniques for tasks that don't fit into a single window — each has its own command in Claude Code. Learn them in pairs: "technique → command."
Compress the dialogue, keep the meaning
We take a long chat at the window boundary, summarize it, and start a new window with this summary. In Claude Code — the command /compact.
Write notes to disk
The agent or you keeps notes NOTES.md / todo-list outside of context. Loaded back when needed. This is agentic memory.
Delegate to a clean window
A sub-agent works in its own context window, reads 15 files in its window, and returns only a compressed summary (1-2K tokens) to the main window.
Compaction — /compact in Claude Code
/compact compacts the session history: the model itself retells the dialogue, keeping what's important and discarding the noise. What's preserved: architectural decisions, unresolved bugs, important details + the last 5 files read. What's discarded: redundant command outputs, repetitive messages.
Another important fact from Claude Code docs (docs/04-claude-code-memory.md): project-root CLAUDE.md survives compaction. After /compact Claude re-reads it from disk and re-injects it into the session. This means:
/compactCLAUDE.md (re-injected from disk is the only confirmed survivor according to the docs)~/.claude/CLAUDE.md and nested CLAUDE.md from subdirectories are automatically loaded by Claude Code at startup, but this is a different mechanism, not a /compact survivorPractical implication. If, during a long session, you told the agent "never touch this function" — after /compact it will disappear. If you want it to survive — add it to CLAUDE.md using the command /memory (the old #-shortcut Anthropic declared deprecated in Academy lesson 9).
$ /compact ⠋ Summarizing conversation… ⠙ Preserving: 3 architectural decisions, 2 open bugs, recent file edits ⠹ Discarding: 28 stale tool outputs, 41 redundant turns ✓ compacted 142k → 18k tokens (-87%) ✓ CLAUDE.md re-injected from disk /Users/rus/mars/src/CLAUDE.md ✓ 5 recent files kept in context src/notify/router.py src/notify/handlers.py src/notify/__init__.py tests/test_notify.py CLAUDE.md › we can continue. what's next?
Structured note-taking — NOTES.md and agentic memory
This is memory on disk, not in the window. A simple pattern: the agent maintains NOTES.md outside of context. A long task — recorded progress; a new session — read NOTES.md, continued. Context between sessions isn't wasted on retelling.
Three practical places where this already works in Claude Code (no configuration needed):
NOTES.md in the repo root (you maintain it manually or ask the agent)CLAUDE.md using the command /memory/memory — it's immediately in the window, will survive compression with /compact, and will load automatically in a new session.Write-back vs in-context — the key difference. CLAUDE.md = in-context, always takes up space in the window. NOTES.md = write-back, stored on disk, loads on request. Use CLAUDE.md for rules, NOTES.md for progress.
Sub-agents — delegating to pure context
The main technique is noise isolation. A sub-agent spends its tens of thousands of tokens searching within its own window, and returns only a compressed summary (1-2K tokens) to the main session. The main window remains clean. This isn't "faster" — it's cheaper in terms of attention.
Built-in sub-agents in Claude Code — three of them, available immediately:
Explore · Haiku · read-onlyPlan · inherits model · read-onlygeneral-purpose · all toolsWhich technique when:
Demo — mentor refactors ~/mars/src/ all day.Mentor butun kun ~/mars/src/ refactor qiladi
A real-life scenario. Zukhra, a Python mentor from Yunusabad (evening, after her shift — helping Mars IT with an internal script): split a notification router into two modules. A large repo, a long day, everything we just discussed — here step-by-step.
At 2:30 PM, Zukhra has 118k tokens in context (out of 200k). By 6:42 PM — even worse. At what step, do you think the agent will start making mistakes? And what will Zukhra do first, when she notices? Write down your two answers, then check below.
10:14 AM · Morning, clean context
$ claude ✓ CLAUDE.md loaded ~/mars/src/CLAUDE.md (2,140 tokens) ✓ user CLAUDE.md loaded ~/.claude/CLAUDE.md (1,820 tokens) › split src/notify/router.py into router.py + handlers.py. don't break the public API. plan first, code later. ⠋ Using Plan sub-agent… (doesn't flood main context) ✓ Plan ready: 1. Move 4 handlers to handlers.py 2. Keep router.py as a dispatcher 3. __init__.py — preserve old names for backward compatibility 4. tests/test_notify.py — fix imports, not logic
Note: Zukhra is in plan mode. Plan sub-agent doesn't flood main — main context only sees the final plan.
14:30 · Had lunch, added another task
After implementation, Zukhra didn't close the chat; instead, she added: “now fix the migrations.” Then, “check the warning in the sales funnel.” The chat grew to 118k tokens. CLAUDE.md is somewhere at the beginning, the notify-router discussion in the middle.
18:42 · Context rot caught
› run the tests we passed this morning ⠋ Reading tests/test_billing.py… ⠋ Reading tests/test_billing_v2.py… ⚠ agent went into billing this morning it was notify. it doesn't remember. › Escape (stop) › you're going the wrong way. this morning it was notify, not billing. yes, sorry — I'll check tests/test_notify.py… ⚠ after 2 turns, it again suggested an f-string in child-friendly code which is explicitly forbidden in CLAUDE.md
What happened: CLAUDE.md at the beginning of the window, its rules “faded” under the weight of 156k tokens in the middle. The morning context about notify also faded. The agent is confidently heading for a wall.
18:45 · Treatment — /compact + Explore
› /compact ⠋ Summarizing… preserving: notify split (DONE), migrations (DONE), sales warning (OPEN — root cause unclear) ✓ compacted 156k → 14k tokens (-91%) ✓ CLAUDE.md re-injected › sales warning remained open. find out what's in the funnel via Explore, don't flood the main context. ⠋ Delegating to Explore subagent… ⠋ Explore reading: src/sales/*.py (~22 files)… ⠋ Explore: targeted grep for warning source… ✓ Explore returned summary (28k tokens explored → 1.4k returned) warning source: src/sales/funnel.py:241 unused import after refactor 12 days ago fix: delete line 11.
What Zukhra gained: main context — 14k instead of 156k. Explore scanned 22 files, but returned only the problem address and solution to main. The morning rules from CLAUDE.md are “fresh” again. We can continue.
/compact + isolated search via Explore. The main thing is — you see what returned to mainHow it looks for Timur (Python olymp 12–14, Chilonzor)
Timur has a different scenario: a student solved an olymp.uz problem poorly — a long 200-line solution that works, but the judge gives TLE. Timur wants to show refactor using similar solutions already in his preparation repo.
Instead of letting the main agent read ~40 files past tasks and filling up the context — Timur delegates to a Explore sub-agent: "find prefix sum problems in ~/olymp-prep/ and return 2-3 reference solutions, explaining how they differ from the current one."
What main receives: 1.5K tokens of summary — file links and the core idea. What does NOT go into main: 35k tokens of raw solutions. Then, he discusses the summary with the student — the agent's attention isn't spread thin.
Same technique, different task. Timur hardly ever uses compaction — his sessions are shorter. But sub-agents? Every day.
Exercise — 3 probe Before-and-After.Uchta probe — Before va After
Three exercises for your long sessions. Do all three manually — otherwise, your next long session will be like everyone else's, a matter of luck.
Open claude in the same repo twice
Let's take your CLAUDE.md, which you created in Module 1.
- In the repo without CLAUDE.md, run
claude. The prompt: "add function X, styled like this project". Record: how many clarifying questions the agent asked and if it matched the style. - In the same repo with CLAUDE.md, run
claude. The same prompt. Record the same two numbers. - Compare. If there's no difference, your CLAUDE.md is weak; rewrite it more specifically.
Bury an important constraint in the middle
This probe will uncover "lost in the middle" — that drop in accuracy regarding what was discussed in the middle of a long context window.
- Long chat. 30+ turns: ask the agent to read different files, discuss refactoring, switch between topics.
- Around turn ~10–15, embed a critical constraint: "never use the library
requestsin this project, onlyhttpx." Do not repeat it later. - On turn 30+, ask for code that would naturally include
requests(HTTP request). Record: did the agent userequests? orhttpx? - Record the same constraint in
CLAUDE.mdusing the command/memory. Open a clean sessionclaudein the same repo. Make the same request. Record the result.
CLAUDE.md clean session. Step 3 vs step 4 — two independent results, compare them directly.See what's left in main
- A clean
claudestarts. Ask: “describe the structure ofsrc/api/(or any folder of yours with 10+ files)”. Let the agent read everything in main context. Do a/costor/transcript— record how many tokens are in the window. - A clean
claudestarts. Ask: “use the Explore sub-agent to describe the structure ofsrc/api/». Let it run. Do a/cost. Record again. - Compare the numbers. There should be a 3-10x difference.
Before you check yourself — pause for 60 seconds
These answers stay with you — we don't send them. This is just a way to anchor two moments where the module breaks out of “read and forget.”
Quiz — Test yourself in 3 minutes.O'zingni sina — 3 daqiqada
Three questions. If you get even one wrong, go back to the relevant section. This isn't a grade; it's your safety net before the next long session.
You've been refactoring ~/mars/src/ for 3 hours straight in one session. At first, the agent accurately fixed files according to the CLAUDE.md convention. Now it's started violating it. What happened?
What does /compact do in Claude Code?
/clear, not /compact.When is a sub-agent appropriate (according to the Anthropic blog)?
/compact, /memory, /agents, /cost, sub-agents, hooks
What's next — Module 5.Keyingisi — Modul 5
Your own sub-agents and Agent Skills
You can now see what's in the agent's window. In the next module — assemble your own sub-agents (for example, homework-checker for checking a group's homework) and Agent Skills (pygame-starter tailored to children's ages) that compress repetitive work into a single command. What now takes you an evening will take 5 minutes.
Attribution and License
This module is adapted by Mars IT School (2026) based on:
— Anthropic Engineering Blog «Effective context engineering for AI agents» (Sep 2025) — central source, verbatim quotes.
— «AI Capabilities and Limitations» — Anthropic Academy, 2026, section Working Memory (lessons 8, 9).
— «AI Fluency: Framework & Foundations» — Dakan, Feller, Anthropic, 2025 (CC BY-NC-SA 4.0).
— Claude Code documentation (claude.com/docs) — definitions of /compact, sub-agents, what survives compaction.
— «Claude Code in Action» and «Introduction to Subagents» — Anthropic Academy, 2026.
Our adaptation is CC BY-NC-SA 4.0. You can copy, remix, and use it in teaching — with attribution to Mars IT School and retaining the same license.