Skip to main content

How Memory Works

Module: Memory & Context | Lesson: 1 of 4 | Time: ~10 minutes

What You Will Learn

  • What the context window is and why it matters
  • What tokens are and how they relate to text
  • How memory works within a session vs across sessions
  • Why long conversations eventually need to be compacted

Prerequisites


The Context Window: Claude's Working Memory

Every time you start a conversation with Claude Code, it opens a context window. This is Claude's working memory for the current session — it holds everything you have said, everything Claude has said, and any file contents Claude has read.

Think of the context window like a desk. You have a limited amount of desk space. As you work, you pile on papers — your questions, Claude's answers, code snippets, file contents. Eventually, the desk gets full and you need to clear some space.

The desk analogy

Imagine you are working at a desk with a fixed surface area:

  • Small task: You spread out a few papers. Plenty of room.
  • Medium project: The desk is getting crowded but still manageable.
  • Huge project: Papers are falling off the edges. You need to file some away and keep only what you need right now.

That is exactly how Claude's context window works. The more you say and the more files Claude reads, the closer you get to filling it up.


What Are Tokens?

Claude does not measure text in words or characters. It measures text in tokens.

A token is a small chunk of text — roughly 0.75 words per token, or about 4 characters. Some examples:

TextApproximate Tokens
"Hello"1 token
"How are you doing today?"6 tokens
A typical paragraph (50 words)~67 tokens
A full page of text (~500 words)~667 tokens
A large source code file (~1000 lines)~5,000-10,000 tokens

You do not need to count tokens yourself. Claude Code tracks this automatically, and you can check your usage with the /cost command (more on that in Lesson 4).

Why tokens matter

Every message you send, every response Claude gives, and every file Claude reads takes up tokens in the context window. When the window fills up, Claude either needs to forget older parts of the conversation or you need to compress the history using /compact.


Memory Within a Session

Within a single session, Claude remembers everything. From the moment you launch Claude Code until you close it or start a new session, Claude has access to the entire conversation history.

This means:

  • If you tell Claude your project uses React, it remembers that for the rest of the session.
  • If Claude reads a file early in the conversation, it can reference that file later.
  • If you make a mistake and correct yourself, Claude understands the correction.

You do not need to repeat yourself during a session. Claude's within-session memory is automatic.

You: My project uses Python 3.11 and Flask
Claude: Got it! I'll keep that in mind.

... 20 messages later ...

You: Create a new route for the contact page
Claude: I'll create a Flask route for the contact page using Python 3.11 conventions...

Claude remembered the technology choices from earlier in the conversation without you repeating them.


Memory Across Sessions

Here is the important part: when you close Claude Code and open it again, Claude starts fresh. It does not remember your previous conversation.

This is like clearing off your desk at the end of the day. Tomorrow morning, the desk is empty — you need to put your papers back out.

Session 1:
You: My project uses Python 3.11 and Flask
Claude: Got it!

--- You close Claude Code and reopen it ---

Session 2:
You: Create a new route for the contact page
Claude: What framework and language is your project using?

Claude forgot because it started a new context window.

This catches people off guard

Many beginners assume Claude "remembers" them between sessions, like a chat app. It does not — unless you set up persistent memory, which we cover in the next three lessons.

The solution: persistent memory tools like CLAUDE.md files (Lesson 2), user-level memory (Lesson 3), and auto-memory features. These load information into Claude's context at the start of every session, so it acts like it "remembers" you.


Token Limits and Long Conversations

As your conversation gets longer, you use more tokens. Eventually you may notice:

  • Claude's responses slow down — it has more context to process.
  • Claude starts forgetting earlier details — very old parts of the conversation may be dropped.
  • You see a warning — Claude Code tells you the context is getting full.

When this happens, you have two options:

  1. Use /compact — This compresses your conversation history, keeping the key points but freeing up space. We cover this in detail in Lesson 4.
  2. Start a new session — Close Claude Code and open it again. Best when you are switching to a completely different task.
Rule of thumb

If you have been working for more than 30-45 minutes on complex tasks, it is probably a good time to use /compact or start fresh. Short, focused sessions tend to work better than marathon ones.


Quick Reference: Memory Types

Memory TypeHow It WorksPersists Across Sessions?
Context WindowAutomatic — everything in the current conversationNo
CLAUDE.mdA file loaded at the start of every sessionYes
Auto-memoryClaude saves learnings automaticallyYes
User-level CLAUDE.mdGlobal preferences for all projectsYes

You will learn about each persistent memory type in the next three lessons.


Try It Yourself

Let us see the context window in action:

  1. Open Claude Code in your practice project folder.
  2. Tell Claude something specific about your project: "This project uses JavaScript and is a personal website."
  3. Ask Claude a related question a few messages later: "What language does my project use?" Claude should remember.
  4. Close Claude Code completely (type /exit or close the terminal window).
  5. Reopen Claude Code in the same folder.
  6. Ask the same question: "What language does my project use?" Notice that Claude no longer remembers.

This demonstrates the difference between within-session and across-session memory.


What You Learned

  • The context window is Claude's working memory for the current session — like a desk with limited space.
  • Text is measured in tokens (roughly 0.75 words per token).
  • Within a session, Claude remembers everything automatically.
  • Across sessions, Claude starts fresh unless you use persistent memory tools.
  • Long conversations use more tokens and eventually need /compact to free up space.
  • Persistent memory (CLAUDE.md, auto-memory) bridges the gap between sessions.

Help Us Improve

How was this lesson? Take 2 minutes to share your feedback — it helps us make the tutorials better for everyone.

Give Feedback →

Next Up

Next: Project Memory with CLAUDE.md