Aulafy
Courses/Claude Code, from zero to pro/Control Context and Costs

Control Context and Costs

The two most common complaints from beginners: "every session starts from scratch and I have to re-explain everything" and "I burn through my plan limits right away." Both have the same root—context—and both have a fix. This lesson is your savings manual.

  • Understand what the context window is and what fills it (and costs you money).
  • Make Claude Code "remember" your project between sessions with CLAUDE.md.
  • Use /clear, /compact, and subagents to stretch your limits.
  • Decide which tasks to send to a cheap model or your local AI.

What Context Is (and Why It Gets Spent)

What fills context the most, in order:

  • Large files read in full (or pasted by you into the chat).
  • Long command output (logs, tests, listings).
  • Endless conversations that mix different tasks.

Your Three Savings Buttons

TerminalCode
/clear    # borra la conversación y empieza limpio (fin de tarea)
/compact  # resume la conversación y libera espacio (mitad de tarea)
/cost     # consulta cuánto llevas consumido en la sesión

/compact is the middle ground: it compresses what you've discussed into a summary and lets you continue where you left off. Use it when the task is long but you don't want to lose the thread. And don't fear /clear: it doesn't delete your code or files, only the conversation.

The Cure for "Starting from Scratch": CLAUDE.md

The frustration of re-explaining your project every session has an official fix: a CLAUDE.md file in the project root. Claude Code reads it automatically on startup. Ask for it like this:

TerminalCode
Crea un CLAUDE.md para este proyecto: qué es, cómo se arranca,
qué estructura tiene, mis convenciones y qué NO debes tocar.
Breve y útil, que sirva de memoria entre sesiones.

Subagents: Explore Without Cluttering

When Claude needs to dig through a large repository, every file it reads stays in your context… unless it delegates. Subagents explore in their own memory and return only the conclusion. Ask for it explicitly:

TerminalCode
Usa un subagente para investigar dónde se gestiona el login
en este proyecto, y tráeme solo el resumen con los archivos clave.

Each Task Deserves the Model It Needs

Not every task needs the most powerful model:

  • Mechanical tasks (renaming, formatting, summarizing): a fast/cheap model is enough—switch with /model.
  • Designing, hard debugging, refactoring: the powerful model—that's what it's for.
  • Volume and private data (processing a hundred PDFs, chatting with documents): no cloud, no limits—your local AI. How to connect it is covered in the lesson "Connect Claude Code with Your Local AI" in the Local AI course.
  • CLAUDE.md when starting each project (and updated when you make an important decision).
  • /clear when switching tasks; /compact on long tasks.
  • Subagents for exploring; limit which files it should read.
  • Fast model for mechanical work; local AI for volume and private data.

Challenge to Practice

Take your most active project and write its CLAUDE.md today (with help from Claude Code). Tomorrow, time how long it takes to pick the work back up. That minute that used to be ten is the best metric for this lesson.