PTENES
MODULE 2.4

🧠 Context & Tokens

An agent's quality is not fixed: it rots the longer the session gets. The more the conversation fills up, the more the window becomes noise and the more the agent "drifts." This module teaches you the discipline of managing context and tokens—knowing how to read the thresholds, when to /compact, when to use /clear, and how to keep each session lean so quality stays high from start to finish.

6
Topics
~40
Minutes
Inter.
Level
Discipline
Type
Module progress 0% · 0 of 6

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.

Context tank — fills as the session grows → ~80% ~60% · quality starts to decline high quality declining quality ~70% → /compact 85%+ → /clear

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.

1

🍂 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

Degrades gradually

Doesn't fail suddenly.

~60% is the threshold

Errors start there.

Noise drowns out the rule

History hides what's essential.

Limited attention

Root cause of the phenomenon.

2

🚥 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.

% of context window used → 0–50% · safe work freely 50–70% think about /compact 70–85% /compact now 85%+ /clear · start over 0% 50% 70% 85% 100%

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

0–50% safe

Work without worry.

50–70% attention

Consider compacting.

70–85% /compact

Compact proactively.

85%+ /clear

Clear it and start over.

3

🧹 /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.

/clear — full reset full context /clear empty starts from scratch /compact — smart summary full context /compact summary of the essentials /clear forgets everything · /compact remembers what matters in less space

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 /compact to “fix” an already-broken session—that’s /clear.

🎯 Goal: restore quality when the context goes beyond ~70%

command (copy and run)
/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

/clear = reset

Full conversation reset.

/compact = shrink

Summary that preserves the essentials.

Switched tasks?

/clear, always.

Same task?

/compact in the middle of it.

4

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.

1 start (clean) 2 work on the task 3 ~70% → /compact 4 completed task 5 switch tasks → /clear Lifecycle of a healthy session

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

1 task = 1 session

Finish, then reset.

Don't reuse

Bloated conversation = noise.

Clean = precise

Fewer errors, fewer tokens.

Summarize first

Save the essentials and /clear.

5

🏁 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

prompt (copy and adapt)
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

Explicit target

"Exactly 75 profiles."

Stop condition

Say when it’s “done.”

Prevents loops

No “search just to be safe.”

Saves tokens

Unnecessary work = zero.

6

💰 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.

Efficiency levers → less context used at the start before heavyweight on-demand skills instead of CLAUDE.md turn off MCP not used Lean CLAUDE.md < ~500 lines then ↑ a lighter tank = more room for the real work

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; /compact a ~70%, /clear when 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 /clear when it gets stuck.

Key concepts

On-demand skills

Load only when used.

Turn off MCP

Each one adds weight to the context.

Lean CLAUDE.md

< ~500 lines, essentials only.

Hygiene = routine

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

✓
Context rot — quality degrades the longer the session runs; errors start around ~60% usage.
✓
Thresholds — 0-50% safe · 50-70% caution · 70-85% /compact · 85%+ /clear.
✓
/clear vs. /compact — reset to switch tasks; summarize in the middle of a long task.
✓
One task per session — finish, run /clear, start the next one; clean = precise and cheap.
✓
Define "done" — an explicit target (“exactly 75 profiles”) prevents looping and token waste.
✓
Context efficiency — on-demand skills, MCP turned off, a lean CLAUDE.md: context hygiene.

Next Module:

2.5 — RAG & Data