Skip to content

The Main Thread

Every session is a conversation with a context window. The main thread concept — what goes in, what stays, and why it matters.

You open Claude Code. Type a message. Claude reads files, runs commands, writes code. Back and forth for a while. Then somewhere around the 30-minute mark, something shifts. Claude starts forgetting things you told it earlier. Makes mistakes it wouldn't have made at the start. Repeats itself.

The context window filled up.

Understanding why that matters is probably the single most important thing in this entire course. No exaggeration.

Context Window Is RAM

Everything Claude has seen during your current session lives in one big buffer. Every message you typed. Every response Claude gave. Every file it read. Every command it ran and every output that came back. All of it, simultaneously, for the entire session.

Fixed size. When it fills up, things get dropped. Details get summarized. Nuance evaporates. Performance tanks.

Most best practices in Claude Code boil down to one constraint: the context window fills up fast, and performance degrades as it fills. That's not a footnote. That's the whole game.

What Is Eating Your Context

More than you think.

Before you even type anything:

  • System prompt (Claude's behavioral instructions)
  • Your CLAUDE.md files
  • First 200 lines of MEMORY.md
  • Tool definitions (every tool Claude Code can use)

As you work:

  • Every message you send
  • Every response Claude generates
  • Every file read (full content)
  • Every command output (build logs, test results, git diffs)
  • Every tool result

You haven't started working yet and a chunk of your context is already gone. Now add a debugging session where Claude reads five files, runs three commands, and you go back and forth ten times. Tens of thousands of tokens consumed without you realizing it.

Tracking It

Claude Code gives you the tools. Use them.

/cost

Token usage for your current session. How many used, how many remain. Run this periodically during long sessions.

/context

Colored grid showing how full your context window is. Green means room. Red means trouble. Quick gut-check.

/statusline

Persistent indicator in your terminal. Set it up once, context usage visible at a glance forever.

When context gets full:

/clear

Nukes the conversation. Clean slate. Or:

/compact

Less aggressive. Claude summarizes the conversation and frees space. But summarization means detail loss. Important instructions from earlier might get compressed into vague summaries. That's the tradeoff.

Claude also auto-compacts when approaching the limit. You notice this when Claude suddenly "forgets" specific things from earlier. That's compaction doing its job, keeping the session alive at the cost of granularity.

Try It

Start a session. Run /cost immediately, before doing anything. Note the token count. That's your baseline: system prompt, CLAUDE.md, tool definitions, auto memory.

Read a file with 500+ lines, then run /cost again

The jump will surprise you. Have a few exchanges, check /cost again. Watch it climb.

This builds intuition fast. Once you see the numbers, you start thinking about what deserves to be in the context window and what doesn't.

Start Over More Often

A clean session with a better prompt almost always beats a long session with accumulated corrections.

Think about it. Twenty minutes of back-and-forth. Correcting course, adding clarifications, fixing mistakes. Your context window is packed with failed attempts, outdated instructions, contradictory guidance. Claude is trying to make sense of all of it simultaneously.

Now compare: you take what you learned from those twenty minutes, write one clean message that captures exactly what you want, and start fresh. Full context window. No noise. No contradictions. No ghosts of failed approaches haunting every response.

The fresh start wins. Almost every time.

This is why experienced users aren't precious about their sessions. They treat them as disposable. The code on disk persists. The conversation doesn't need to. Run /clear without hesitation.

Key Takeaways

  • Context window is RAM. Everything lives there simultaneously. When full, performance degrades through compaction and detail loss.
  • Your context is never empty. System prompts, CLAUDE.md, tool definitions, and auto memory all consume space before you start.
  • /cost and /context are your friends. Check them. Especially during long sessions.
  • Fresh sessions with refined prompts beat bloated sessions with corrections. Not obvious, but true.
  • Conversations are disposable. Code on disk is what matters.

Mastering Claude Code

Lesson 14 of 70