Journal
Tutorials

/clear vs /compact vs Kill: Managing Claude Code's Context Window

C

Clearly Team

Engineering

6 min read
Jul 7, 2026

/clear vs /compact vs Kill: Managing Claude Code's Context Window

Claude Code's context window is a finite, precious, easily-wasted resource — and most people manage it by accident. They let it fill until the agent gets slow and a little stupid, then wonder why it "got worse" over the afternoon. It didn't get worse. Its context got full.

You have three deliberate levers: /compact, /clear, and a fresh start. They are not interchangeable — reach for the wrong one and you either throw away context you needed or drag along context you should have burned. Here's the precise version.

First, the mental model

Everything in the current session — your messages, every file read, every command output, every edit — lives in one context window, and the whole thing is re-sent to the model on every turn. Two implications most people miss:

  • A bloated context taxes you every turn. More tokens re-sent means slower, pricier, more diluted answers — not once, but on each interaction until you reset.
  • Context is attention. The model can only weight what's in the window. A window that's 80% dead ends is a prompt that's 80% distraction.

Managing the window isn't housekeeping. It's the difference between a sharp agent and a foggy one.

/compact — the soft reset

/compact replaces the conversation history with a summary and keeps going, reclaiming space while preserving the thread of what you were doing. You can even aim it — /compact focus on the auth refactor — to steer what gets kept. Claude Code also compacts automatically as you approach the limit: it drops older tool outputs first, then summarizes, holding on to your requests and key code while some early detail falls away.

Reach for /compact when the work is going well but getting long. You're deep in a feature, the agent is on track, you just need room to keep going. Compaction keeps the momentum and the gist. The catch: a summary is lossy, so if an exact error or a precise decision still matters, don't assume it survived the squeeze.

/clear — the hard reset

/clear empties the context window entirely — same directory, same session — and re-reads your CLAUDE.md, so your project rules come back while the conversation does not.

Reach for /clear when the thread is poisoned or you're switching tasks. Two cases:

  1. The session went bad — loops, drift, an anchored wrong assumption. /compact would only carry the poison forward in condensed form; /clear actually removes it.
  2. You're moving from task A to an unrelated task B. Don't let A's context bleed into B — clear between them. A shocking amount of "why is it bringing up that other file?" is just leftover context from the last thing you did.

Start clean — the fresh session

Here's the myth worth killing: quitting Claude Code does not wipe anything. Sessions save continuously to disk (under ~/.claude/projects), so closing the terminal and reopening lets you pick up exactly where you left off. The route to a genuinely empty context isn't quitting — it's /clear, or simply starting a new session and choosing not to resume the old one. And when you do want to continue, claude --continue brings the last session back (or /resume to choose one). Nothing is ever destroyed; a "reset" is a choice not to carry the old context forward — never a forced loss.

What survives what

The thing to internalize: your reasoning lives in the context; everything durable lives outside it.

What survives/compact/clearNew session
Live conversationSummarizedEmptiedEmpty
Saved to disk / resumableYesYes (--resume)Old one still on disk
Files on disk, git stateKeptKeptKept
CLAUDE.md rulesKept (re-read)Re-readLoaded fresh

Notice what's always safe: files, git, and CLAUDE.md. That's the whole lesson. Anything you can't afford to lose should never live only in the conversation.

The real move: keep the important context out of the window

If resetting a session ever feels scary, it's because you're storing something in the window you can't afford to lose. Fix that, and every reset becomes free.

  • Project conventions → CLAUDE.md. Anything you'd re-explain to a fresh agent — architecture, naming, "run the typecheck before claiming it works" — goes in the file that's re-read every session. Write it once; it survives every /clear.
  • Decisions and team knowledge → a durable store. The reasoning behind a choice, the brand, the context that spans sessions and people shouldn't be re-derived each time. Put it where an agent can recall it on demand. That's the idea behind a Company Brain: durable memory an agent pulls by meaning, so a freshly-cleared session is one recall away from everything it needs — and through Beehaven it pulls that from the CLI without you re-typing a word.

Do that, and /compact, /clear, and restart stop being a tax on your work. They go back to being what they should be: the throttle on a resource you finally control.


Keep reading: Shoot your Claude Code in the head: when to kill a session instead of saving it · Claude Code stuck in a loop? Restart it, don't debug it

#claude code#context management#claude.md#ai agents#developer workflow