AI
November 18, 2026
6 min read

Context and Memory in Claude Code: A Practical Guide

How Claude Code memory works, what fills the context window, and when to use /context, /compact, /clear and /rewind to keep your sessions fast and focused.

Most of Claude Code's quality depends on what sits in its context and what it remembers between sessions. This article explains how the memory system works, what takes up room in the context window, and which commands help you manage the conversation.

Two completely different memory systems

1. Automatic memory (Claude manages)

  • On by default.
  • Lives in ~/.claude/projects/<repo>/memory/MEMORY.md (and files next to it).
  • Local to your machine and not committed to git.
  • Only the first 200 lines or 25KB of MEMORY.md are loaded automatically, so it should be an index, not a storage dump.
  • Toggle it on and off with /memory.

2. A memory document in the repo (you manage)

  • A file in the repo, committed to git and subject to Code Review.
  • Usually imported from CLAUDE.md with @ and loaded in full.
  • Travels with the project and applies to every team member.

Rule of thumb: personal or temporary things go to automatic memory. Team decisions go to a document in the repo.

What is the context window made of?

The context window is made of: system instructions, CLAUDE.md, files that were read, loaded memory, Skill descriptions, tool and MCP definitions, and the conversation history.

/context: the first command to run

This command shows a colorful grid of what occupies the window in the current turn, with suggestions for saving space. According to the guide, most people discover something big that always loads for no reason, such as an MCP server with 80 tools or a huge Skill.

  • /skill-doctor: shows how much each Skill costs in context and how often it is used, so you can find what to turn off.
  • /skills: press t to sort by token count.

Managing the conversation

CommandWhen to use it
/compact [guidance]Same task, long history: summarizes and frees space. You can steer it, for example /compact focus on the API decisions
/clear [name]A different task: start clean (the previous conversation is kept in /resume)
/autocompact [auto|500k]Sets when automatic compaction kicks in
/branch [name]Splits the conversation so you can try another direction without losing the current one
/rewind (also /undo)Go back to an earlier point, in the conversation and/or the code
/btw [question]A side question about the session without adding it to the context
New sessionWhen the session got "confused": do not drag the confusion along

A practical example: you are in the middle of API work and the conversation got long. Run /compact focus on the API decisions to keep what matters. Switched to a completely different task? /clear is better.

An important truth about retrieval

There is no vector database, no embeddings and no semantic index. Claude Code searches with grep and reads files, exactly like a human developer.

The practical meaning: a clear folder structure and precise file names are worth more than any retrieval technique. A file named utils2_final.ts is a context problem.

The cost of context: "rent" on every turn

Everything loaded automatically is rent you pay on every turn. A rule for organizing things:

  • What is always relevant: in CLAUDE.md.
  • What is sometimes relevant: in .claude/rules/ or in docs/.

Since August 2026 there is a Cache meter in the interface, and since September it also shows a probable reason for each cache miss. That is useful for finding what breaks your prefix.

Models with one million tokens

Opus 5.5, Sonnet 5.5 and Fable 5.1 support one million tokens by default. That does not mean you should fill the window: a full window is slower and more expensive, and attention quality drops. The variable CLAUDE_CODE_DISABLE_1M_CONTEXT=1 returns you to 200K.

A short routine you can adopt

  1. When starting work on a new project, run /context and look for something big that loads for no reason.
  2. Check with /skill-doctor which Skills are not being used.
  3. In the middle of a long task: /compact with guidance on what to keep.
  4. Between unrelated tasks: /clear.
  5. Want to try another direction? /branch, and if it does not work out, /rewind.

What to do this week

From the guide's "ten things to do this week" list, these are the steps related to context and memory:

  • Run /context.
  • Trim CLAUDE.md to under 200 lines.
  • Move conditional rules to .claude/rules/ with paths:.
  • Run /doctor prompt-audit after moving to the 5.5 models.

Where to put what: three examples

A personal preference that matters only to you, such as how you like to receive answers, belongs in automatic memory or in your User file. A team decision, such as how your API is structured, belongs in a repo document imported with @. And a rule that matters only when touching a specific folder belongs in .claude/rules/ with paths:.

One principle stands behind all of these decisions: do not pay for what you do not need. Bloated context costs time, money and quality, so it is worth checking from time to time what is loaded and removing whatever does not serve the current work.

The full guide is free on GitHub (in Hebrew), and also available as a website: https://tovtechorg.github.io/Claude-Code-in-Hebrew/.