🚀Publish FREEJoin WriterDock's early community of writers.Start Writing — It's Free

Managing Context in Claude Code: /clear, /compact, /rewind and /resume

Suraj Kumar

Suraj Kumar

November 3, 2026

A long session with Claude Code can drift. Early instructions fade, old output crowds the window, and a wrong turn is hard to undo. This lesson gives you the tools to prevent that. After it, you will know when to start fresh and when to shorten the conversation, how to go back when Claude heads the wrong way, and how to return to old work later.

You already know the idea from lesson 6: Claude can only keep so much text in mind at once, and that space is called the context window. Here you learn to manage it on purpose.

Five tools, five situations

Five cards: /clear for switching to an unrelated task, /compact when the same task is filling up the context, /rewind when Claude went the wrong way, /resume to return to an older conversation, and /branch to try a different approach

Most of the skill is choosing the right tool. The rest of this lesson covers each one in turn.

See what is using space: /context

Before you shrink anything, look. Type:

text
1/context

It shows a live breakdown of what is filling the window, with suggestions to reduce it. It also lists which CLAUDE.md and memory files loaded. Think of it as a fuel gauge. Check it when a session feels sluggish or Claude starts forgetting things.

Start fresh: /clear

text
1/clear

/clear starts a new conversation with an empty context. It is the right move when you switch to a task that has nothing to do with the last one. Old conversation crowds out the files you need next, and it costs tokens on every message you send.

Nothing is lost. Claude Code saves the previous session, and you can bring it back with /resume. If you want to label the session you are leaving, pass a name:

text
1/clear release-prep

A session you have named with --name or /rename keeps its name after /clear. The new conversation still loads your CLAUDE.md and memory, so your lasting rules are there from the start.

Shrink the conversation: /compact

text
1/compact

/compact replaces the history with a summary and lets you keep working on the same task. You do not have to run it. Claude Code compacts automatically when the window nears full. The catch with automatic compaction is that it decides for itself what matters.

You can steer it by adding instructions:

text
1/compact focus on the auth bug fix

Do this before you start a long new stage of work, so the summary keeps what you care about.

What survives, and what does not

Compaction does not erase everything. These come back after it:

  • Your project-root CLAUDE.md and your auto memory, which are re-read from disk
  • The plan Claude wrote in plan mode
  • Up to five of the files Claude read or edited most recently
  • Skill descriptions, and the bodies of skills you used, up to a size limit

What can disappear is anything that only existed in the chat, such as a detailed instruction you gave an hour ago. This is the reason for the rule from lesson 6: put anything lasting in CLAUDE.md. Rules that load only when Claude touches certain files, and nested CLAUDE.md files in subfolders, reload on demand rather than being kept.

If you want compaction to happen sooner, /autocompact 500k sets how full the window gets before the automatic pass runs.

Go back: /rewind

Sometimes Claude takes a wrong turn, and you want the clock turned back. Claude Code makes this possible with checkpoints. Every prompt you send that starts a turn creates a checkpoint, a snapshot of your code before Claude changes it. It keeps snapshots for the 100 most recent checkpoints in a session.

Open the rewind menu in either of two ways:

  • Type /rewind.
  • Press Esc twice when the prompt box is empty. If the box has text, double Esc clears it instead, and the up arrow brings the text back.

The menu lists the prompts you sent. Pick a point, then choose what to do:

Table of the rewind options. Restore code and conversation reverts both, Restore conversation reverts only the chat, Restore code reverts only the files, Summarize from here shortens the conversation from that point on, and Summarize up to here shortens the earlier part

  • Restore code and conversation puts both back to that point.
  • Restore conversation rewinds the chat but keeps your code as it is now.
  • Restore code reverts the files but keeps the conversation.
  • Summarize from here compresses the conversation from that point on, which frees up space.
  • Summarize up to here compresses everything before that point and keeps the later messages.
  • Never mind goes back to the list.

After a restore, the prompt you rewound to appears in the input box so you can edit it and send it again. That is a handy way to try a better prompt.

You can also guide a summary. Highlight a Summarize option, type what to focus on where it says "add context (optional)", and press Enter.

What rewind cannot do

Checkpoints are for quick recovery within a session. They have limits worth knowing:

  • They track changes made by Claude's file-editing tools. If a file was changed only by a shell command, it is not tracked. Use Git for that.
  • Edits from other programs, or from other sessions running at the same time, are not tracked.
  • Most edits made by subagents (lesson 17) are not restored.
  • Snapshots are deleted about 30 days after the session last saved one, so an old rewind may fail.

Checkpoints are not a replacement for version control. Keep using Git for commits and permanent history.

Come back later: sessions

Claude Code saves every conversation as a session, tied to the folder you worked in. Here are the ways back in:

CommandWhat it does
claude --continueReopens the most recent session in this folder
claude --resumeOpens the session picker
claude --resume auth-refactorResumes the session with that name
/resumeSwitches to another session from inside Claude Code

A resumed session restores the conversation history, the model it used, and, when you resume from the terminal, its permission mode. It does not carry over every launch option, so pass flags like --add-dir again.

Name your sessions

A name makes a session easy to find later. Set one at startup, or any time during the session:

bash
1claude -n auth-refactor
text
1/rename auth-refactor

Without a name, Claude Code makes up a short title from your first prompt. Naming matters most when you juggle several tasks.

Use the session picker

Run /resume, or claude --resume with no name, to open the picker. These keys help:

KeyWhat it does
↑ ↓Move between sessions
EnterResume the highlighted session
SpacePreview the session
Ctrl + RRename the highlighted session
/ or just start typingSearch
Ctrl + AShow sessions from every project on this computer
Ctrl + BShow only sessions from the current Git branch

Try another idea safely: /branch

Say you are halfway through a feature and want to test a different approach without losing your current path. Branch the conversation:

text
1/branch try-streaming-approach

This copies the conversation so far into a new session and switches you to it. The original stays untouched, and you can go back with /resume. From the command line, claude --continue --fork-session does the same. Branching copies the conversation, not your files, so for different versions of your code, use a Git branch too.

Habits that keep sessions healthy

  1. One task, one session. When the topic changes, use /clear.
  2. Compact with a focus before a long new stage: /compact focus on ....
  3. Keep lasting rules in CLAUDE.md, not in chat.
  4. Rewind early. If Claude is clearly off track, go back right away instead of piling corrections on top.
  5. Name sessions you will want again. A good name beats scrolling a list.
  6. Glance at /context when things feel slow or forgetful.

Mistakes beginners make

  1. Never clearing. A session that has covered five unrelated tasks carries all of that weight into every answer.
  2. Using /clear when you meant /compact. /clear ends the thread of work. /compact keeps it in shorter form.
  3. Trusting chat for rules. Instructions you gave only in conversation can be lost in a summary. Put them in CLAUDE.md, or use a deny rule if it is a safety boundary.
  4. Using rewind as your only backup. It does not cover files changed by shell commands. Commit to Git regularly.
  5. Forgetting how to get a cleared session back. /resume lists it.

Quick recap

  • Check space with /context. Start fresh with /clear. Shorten a conversation with /compact, optionally with a focus.
  • /rewind or Esc Esc goes back to a checkpoint. You choose whether to restore code, conversation or both, or to summarize part of the conversation.
  • Resume with claude --continue, claude --resume or /resume. Name sessions with -n or /rename.
  • /branch copies a conversation so you can try another approach safely.
  • Lasting rules belong in CLAUDE.md. Checkpoints do not replace Git.

Try it yourself

In your practice folder, ask Claude to add a small feature, such as a footer. Run /context to see the breakdown. Then press Esc twice, pick the prompt you just sent, and choose Restore code to see the footer disappear while the conversation stays. Next run /rename footer-experiment, /clear, and then /resume to bring the named session back.

Next lesson: prompting patterns for code.