Think about the context window like the session’s fuel tank. Every message you send, every agent response, every file read, and every tool loaded takes up tokens — pieces of text the model has to “keep in mind” at the same time. The tank has a fixed capacity. As it fills, quality doesn’t drop all at once: it gradually degrades. Around ~60% of use, errors start to appear. The good news: you have two pedals— /compact e /clear — to catch your breath before the tank overflows.
Illustrative diagram — the tank fills with the conversation history; start “checking the meter” and use /compact around 70% and /clear above 85% so quality doesn't plummet.
🍂 Context rot — degradation after ~60%
What it is
Context rot ("context rot") is the gradual decline in response quality as a conversation gets longer single session. It’s not a bug or a “tired” model: it’s a consequence of how the attention of the model works. The more text is in the window, the more the AI has to weigh at once—and past a certain point (in practice, around ~60% of use), errors start to appear.
What is it?Context window — everything the model “sees” right now: your messages, the replies, files it has read, and instructions. Token — the small piece of text the model counts (a word is usually worth 1 to 3 tokens). The context window has a token limit.
The mechanism is easy to picture: as the conversation grows, the window fills up with noisy history — failed attempts, files you no longer use, back-and-forth. Recent messages (which often no are the most important) start to "drown out" the core rules at the beginning. The agent starts forgetting instructions, repeating what it has already done, or mixing things up—classic symptoms of bloated context.
Why learn
Anyone who doesn’t know about context rot blames the model (“the AI got dumb”), when the problem is that the session got too long. Recognizing the pattern changes everything: instead of fighting with the agent, you clears the tank and the quality comes back.
- •Correct diagnosis: "it's bad" becomes "the context is full," which has a solution.
- •Stable quality: you intervene before ~60%, not after the damage is done.
- •Less rework: short, clean sessions make fewer mistakes and use fewer tokens.
Key concepts
Doesn't fail suddenly.
Errors start there.
History hides what's essential.
Root cause of the phenomenon.
🚥 The thresholds (0-50 / 50-70 / 70-85 / 85%+)
What it is
Instead of treating window usage as "all or nothing," divide it into four tiers with different actions. Think of a traffic light: 0-50% is the safe zone—work freely; 50-70% is yellow — start thinking about compacting; 70-85% is orange — run /compact proactively; 85%+ it’s the critical zone—give it /clear and start over from scratch.
Illustrative diagram — the numbers are practical guides, not exact rules. The habit that matters is: check the meter and act before before reaching the critical range.
Why learn
Thresholds turn a vague feeling (“I think this is getting confusing”) into an objective routine. You stop reacting to disaster and start acting proactively: once you hit 70%, compacting is a reflex; once you pass 85%, starting fresh is automatic. It’s the difference between driving while watching the dashboard and driving until the car dies on the road.
🎯 Practical tip
Treat the threshold of 70% as a "checkpoint": it’s the natural moment to pause, run /compact and reassess whether it still makes sense to continue with the same task. Don’t wait until the agent starts making mistakes to check the meter — by then, it’ll already be too late.
Key concepts
Work without worry.
Consider compacting.
Compact proactively.
Clear it and start over.
🧹 /clear vs /compact
What it is
Are the two commands for managing the tank. /clear é o full reset: deletes the entire conversation and starts from scratch with empty context—use when you're switch tasks or when quality has already degraded completely. /compact é o smart summary: the agent condenses the conversation, saves what matters (decisions, current state, rules), and compresses the rest—use in the middle of a long task, when the context is high but you still need the history.
What is it?/clear = empty the box (lose the history, get clean context). /compact = shrink the box into a summary (keeps the essence, frees up space). Rule of thumb: change of topic → /clear; same task, full tank → /compact.
Illustrative diagram — /clear zero; /compact shrinks while preserving decisions and state. Choose based on your intent: switch tasks, or continue the same one with less overhead.
Why learn
Using the wrong command is costly: give /clear in the middle of a long task erases state you still needed (and you have to reconstruct everything by hand); give /compact thinking that it will "summarize" a change of subject leaves junk from the old task contaminating the new one. Knowing which one to use, and when, is what separates those who maintain quality from those who struggle with the agent.
✓ /clear when…
- ✓You’re about to start a new, unrelated task.
- ✓Quality has permanently degraded (repeated corrections, things being forgotten).
- ✓The tank exceeded 85% and the old history no longer matters.
✗ /compact when you SHOULDN’T
- ✗Switching topics, thinking the summary "clears" the previous task.
- ✗Compact every message out of anxiety (you only lose useful detail).
- ✗Use
/compactto “fix” an already-broken session—that’s/clear.
🎯 Goal: restore quality when the context goes beyond ~70%
/compact
✅ How to verify: the agent returns a summary of what matters; if quality still drops or you’re switching tasks, use /clear.
Key concepts
Full conversation reset.
Summary that preserves the essentials.
/clear, always.
/compact in the middle of it.
1️⃣ One task per session
What it is
The simplest and most powerful hygiene rule: one task per session. You focus on one goal, finish, give /clear and only then starts the next one. Don’t reuse a bloated conversation from an old task for something unrelated — that’s the fastest path to context rot.
What is it?Session — an ongoing conversation with the agent, from the beginning until you reset it. Bloated conversation — a session that has accumulated too many tasks, attempts, and files, leaving the window full of noise.
Illustrative diagram — a task starts fresh, gets compacted midway when it grows heavy, and ends in a /clear before starting the next one. Short session = high quality.
Why learn
Clean context means accuracy. When a session contains only what matters for the current task, the agent gets more right, hallucinates less, and spends fewer tokens because it isn’t reprocessing irrelevant history with every response. Mixing tasks in the same conversation does the opposite: it dilutes focus and wastes tokens.
🎯 Practical tip
Before /clear, ask the agent for a summary of what was decided and paste the essentials into CLAUDE.md or in a note. That way, the next session starts fresh e with the right context already loaded — without dragging along the clutter from the old conversation.
Key concepts
Finish, then reset.
Bloated conversation = noise.
Fewer errors, fewer tokens.
Save the essentials and /clear.
🏁 Define “done” (prevents loops)
What it is
Define "done" it’s giving the agent an explicit criterion for when to stop—a definition of done. Without this, a diligent agent keeps working "just to be safe": it searches more, redoes work, expands, and burns tokens (and context) in an endless loop. With a clear target like "exactly 75 profiles", it knows the finish line and stops there.
What is it?Definition of done — the objective condition that says “it’s done” (a quantity, a format, a generated file). Loop — when the agent keeps repeating steps without converging, usually because it doesn't know when it's done.
Why learn
A loop isn’t just slow — it fills the tank. Every extra search, every “let me check again,” piles tokens into the window and speeds up context rot. Defining “done” stops the problem at its root: the agent stops at the target, the session stays short, and you don’t waste tokens or quality. It’s the cheapest way to protect context: prevent unnecessary work before it happens.
🎯 Goal: give an explicit stopping criterion to prevent loops and token waste
pesquise exatamente 75 perfis de <cargo> em <setor>; pare ao atingir 75 e me devolva a lista.
✅ How to verify: the agent delivers 75 items and stops—without "looking for more just to be safe." If it continues, reinforce the limit in the prompt.
🎯 Practical tip
Whenever you ask for something "open-ended" (research, collect, generate variations), include a a number, a format, or a stopping condition. “How many?”, “by when?”, “in what format?”—answer these three in the prompt itself, and the agent won’t get stuck in a loop.
Key concepts
"Exactly 75 profiles."
Say when it’s “done.”
No “search just to be safe.”
Unnecessary work = zero.
💰 Save money: skills, disable MCP, keep CLAUDE.md lean
What it is
Even before the first message, part of the tank is already taken up by things that load at the start: o CLAUDE.md, the definitions for each server MCP, system instructions. Saving context means pulling three levers: using skills (which load on demand, only when triggered, instead of living in CLAUDE.md), turn off MCP that you don't use (each server injects tool definitions into the context), and keep the Lean CLAUDE.md (fewer than ~500 lines, only what matters for every session).
What is it?Skill — a capability the agent loads only when needed (on demand), so it doesn’t weigh down the context all the time. MCP — a connector that gives the agent tools; each one adds definitions to the window even when it isn’t used. CLAUDE.md — the permanent instructions file, loaded in every session.
Illustrative diagram — each lever gives window space back. Combine all three (plus "one task per session") and you have a routine for context hygiene.
Why learn
The context you spend at the start is context that no left for the task. A 1,500-line CLAUDE.md and five connected MCPs can use up a large part of the tank before you type the first word—and push you to the ~60% threshold much faster. Context hygiene isn’t an advanced detail: it’s what keeps your sessions long, inexpensive, and precise.
✓ Context hygiene
- ✓Skills loaded on demand instead of putting everything in CLAUDE.md.
- ✓MCPs you don't use today stay off.
- ✓CLAUDE.md < ~500 lines, only what applies to every session.
- ✓One task per session;
/compacta ~70%,/clearwhen switching.
✗ Bloated conversation for everything
- ✗Dump all your knowledge into CLAUDE.md "just in case."
- ✗Leave ten MCPs on without using any during the session.
- ✗A single giant conversation for all of the day's tasks.
- ✗Never just look at the meter and
/clearwhen it gets stuck.
Key concepts
Load only when used.
Each one adds weight to the context.
< ~500 lines, essentials only.
Bring all the levers together.
Wrapping up the module: your context meter has passed 85% and you’re going to start a new task. Which command should you use?
📌 Module Summary
Next Module:
2.5 — RAG & Data