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 what to replenish it with. 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 then 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. This isn't “the model is tired.” This is context rot — and it's the first thing an operator learns.
Three skills I'll check
- Run
/compactbefore the agent starts hallucinating in a long session — based on observed signals, not a timer. - Delegate to
ExploreorPlansub-agent (built-in or your own via/agents) when the task requires file exploration, not editing. - Explain what survives
/compact, what doesn't, and why project-rootCLAUDE.mdis the only reliable rule-bearer for a long session.
Mental model — context window as working memory.Context window — bu working memory
In September 2025, Anthropic released a long post about context engineering — this is the central source for this module. Below are three verbatim quotes, each followed by my Russian version. If the language seems off, the original is next to it; trust the original.
1. Attention budget — attention as a budget, not a shelf
«Like humans, who have limited working memory capacity, LLMs have an "attention budget" that they draw on when parsing large volumes of context. Every new token introduced depletes this budget by some amount.»
Why this is so — Anthropic provides an architectural answer. A transformer allows each token to look at every other token. For n tokens, this is n² pairwise connections. Doubling the context quadruples the attention load.
«These factors create a performance gradient rather than a hard cliff: models remain highly capable at longer contexts but may show reduced precision for information retrieval and long-range reasoning compared to their performance on shorter contexts.»
context overflow. You'll see the agent confidently doing the wrong thing.Anthropic themselves haven't decided. Academy (“AI Capabilities and Limitations”, lesson 8) formulates this as a “cliff” — a sharp drop when the model stops coping. The Engineering blog (“Effective context engineering”, Sep 2025) — as a “gradient,” smooth degradation. We've adopted the gradient — it better describes what is empirically observed in benchmarks (long-context retrieval). But if you read the Academy and encounter “cliff” — don't be surprised, it's not a contradiction of sources, it's two different ways to describe the same phenomenon.
2. Context rot — not “forgotten,” but “blurred”
Anthropic introduces the term context rot: the more tokens in the window, the worse the model retrieves information from them. This isn't a bug of a specific model — it's a property of the transformer.
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
«Good context engineering means finding the smallest possible set of high-signal tokens that maximize the likelihood of some desired outcome.»
Anthropic calls this «Goldilocks zone» — between two errors: on one hand, brittle hardcoded if-else in the prompt, on the other — vague high-level guidance, relying on "the model will figure it out itself." Good context is specific enough to verify, flexible enough to think.
For the operator, this means: CLAUDE.md is not "everything I know about the project". It's a plant of specific rules that you can verify have been applied. If a rule cannot be verified by a diff — it's useless in the context.
Three techniques long-horizon from the Anthropic blog.Uzun masofa uchun uchta texnika
This is the heart of the module. Anthropic highlights three techniques for tasks that don't fit into a single window. Each has a corresponding feature in Claude Code. Learn them as "technique → command" pairs.
Compress the dialogue, keep the meaning
We take a long chat at the window's 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 out 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 to main compact summary (1-2K tokens).
Compaction — /compact in Claude Code
«In Claude Code… we implement this by passing the message history to the model to summarize and compress the most critical details. The model preserves architectural decisions, unresolved bugs, and implementation details while discarding redundant tool outputs or messages. The agent can then continue with this compressed context plus the five most recently accessed files.»
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 — the only confirmed survivor according to 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 # Anthropic shortcut was 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
«Structured note-taking, or agentic memory, is a technique where the agent regularly writes notes persisted to memory outside of the context window. These notes get pulled back into the context window at later times.»
NOTES.md. Long task — recorded progress. 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 setup needed):
NOTES.md in the repo root (you manage it manually or ask the agent)CLAUDE.md using the command /memory/memory — it's immediately in the window; with /compact it will survive compaction and load automatically in a new session.Write-back vs in-context — a key distinction. CLAUDE.md = in-context, always takes up space in the window. NOTES.md = write-back, sits on disk, loads on request. Use CLAUDE.md for rules, NOTES.md for progress.
Sub-agents — delegating to pure context
«Each subagent might explore extensively, using tens of thousands of tokens or more, but returns only a condensed, distilled summary of its work (often 1,000-2,000 tokens). This approach achieves a clear separation of concerns—the detailed search context remains isolated within sub-agents, while the lead agent focuses on synthesizing and analyzing the results.»
Built-in sub-agents in Claude Code — three of them, available immediately:
Explore · Haiku · read-onlyPlan · inherits model · read-onlygeneral-purpose · all toolsWhen to use which technique. Anthropic's blog provides guidance:
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, will the agent start making mistakes? And what will Zukhra do first, when will it notice? 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) › refactor src/notify/router.py into router.py + handlers.py. Do not break the public API. Plan first, code later. ⠋ Using Plan sub-agent… (doesn't flood main context) ✓ Plan ready: 1. Extract 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.
2:30 PM · Had lunch, added another task
After implementation, Zukhra didn't close the chat, but 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 discussion of the notify router is in the middle.
6:42 PM · Context rot caught
› run the tests we passed this morning ⠋ Reading tests/test_billing.py… ⠋ Reading tests/test_billing_v2.py… ⚠ agent went to 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 is 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.
6:45 PM · 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 only returned 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 mainWhat it looks like 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 refactoring via similar solutions that are already in its preparation repo.
Instead of letting the main agent read ~40 files from past tasks and cluttering the context, Timur delegates to a Exploresub-agent: "find ~/olymp-prep/prefix sum problems, return 2-3 reference solutions, and explain how they differ from the current one."
What the main agent gets:1.5K tokens summary — links to files and the key idea. What does NOT go into the main agent: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 uses compaction — his sessions are shorter. But sub-agents — every day.
Exercise — 3 probe Before-and-After.Uchta probe — Before va After
Adaptation of the exercise from Anthropic's "AI Capabilities and Limitations," lesson 9. Do all three probes manually. Without this, your next long session will be just like everyone else's — a shot in the dark.
Open claudein the same repo twice
We're taking your CLAUDE.md, which you created in Module 1.
- In the repo without CLAUDE.md run
claude. Prompt: "add function X, format it like in 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 to be more specific.
Bury an important constraint in the middle
This probe will uncover "lost in the middle" — that recall drop in the middle of the window that Anthropic writes about in "AI Capabilities and Limitations."
- Long chat. 30+ turns: ask the agent to read different files, discuss refactoring, switch between topics.
- On turn ~10–15, embed a critical constraint: "never use the
requestslibrary in this project, onlyhttpx." Don't repeat it later. - On turn 30+, ask for code that would naturally include an
requests(HTTP request). Record: did the agent userequests? orhttpx? - Record the same constraint in
CLAUDE.mdusing the command/memory. Open a cleanclaudesession in the same repo. Make the same request. Record the result.
CLAUDE.md clean session. Step 3 vs. Step 4 — two independent results, compare directly.See what's left in main
- A clean
claudestarts. Ask: "describe the structure ofsrc/api/(or any of your folders 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 points where the module breaks free from "read and forgotten."
Quiz — check 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 insurance before the next long session.
You've been refactoring ~/mars/src/ for 3 hours straight in one session. Initially, the agent accurately corrected files according to the convention in CLAUDE.md. 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 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, you'll build your own sub-agents (for example, homework-checkerto check a group's homework) and Agent Skills (pygame-startertailored to children's ages) that condense 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, Working Memory section (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 education — with attribution to Mars IT School and retaining the same license.