Chapter 6. Sessions and Context
Required Read this to follow this stage.One-line summary: Conversations are saved per folder, so you can reopen them anytime. When a conversation gets long, shrink it with
/compact. When you move on to something else, clear it with/clear.
Sometimes you want to continue today what you were doing yesterday. Sometimes a conversation gets so long that the answers get fuzzy. This chapter covers both.[1]
What Is a Session?
A session is a conversation saved and tied to a project folder.[2] One bundle of conversation you have after starting claude is one session.
The key words here are "tied to a folder." The default list shows only the conversations from that folder. So for every command in this chapter, you first move to the practice folder in the terminal.
cd ~/hello-ai-practice/terminalWhen you start a fresh claude, Claude doesn't know your past conversations. That's because a new session starts without the earlier conversation.[3] To pick up yesterday's discussion, you have to open the past session yourself.
Quick check
Yesterday you organized notes with Claude Code in the terminal. If you just start a new `claude` today, what happens?
Naming and Reopening
For work that takes several days, give it a name.[4] A name makes it easy to find later. Inside the session, type this.
❯ /rename weekly-meeting-notes
⎿ Session renamed to: weekly-meeting-notesIt's fine if you don't name it. Claude Code summarizes your first request and makes a title for you.[2:1]
There are three ways to reopen. For all of them, leave with /exit and type in the terminal.
| Command | When to use it |
|---|---|
claude -c | The most recent conversation in this folder[5] |
claude -r | Pick from a list[5:1] |
claude -r weekly-meeting-notes | Open directly by name[5:2] |
For a conversation you just finished, claude -c is fastest. If you type it in a folder with no conversation to continue, it tells you No conversation found to continue and exits.[6] If you see this text, check the folder first. pwd tells you which folder you're in now.
For a conversation from a few days ago, open the list with claude -r. It looks like this.
Resume session
╭──────────────────────────────────────────────────────────────────────────────────────────────╮
│ ⌕ Search… │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯
터미널
❯ weekly-meeting-notes
4 seconds ago · HEAD · 320.7KB
Ctrl+A to show all projects · Ctrl+B to only show current branch · Space to preview · Ctrl+R
to rename · Type to search · Esc to cancelChoose with the up and down arrows and press Enter to open it. There are only two places to look.
- The
❯line: The name of the conversation you picked. - The line below it: When the conversation was written (
4 seconds ago) and its size (320.7KB). You can ignore theHEADin the middle.
The bottom two lines are a guide to the keys you can use. Typing letters searches, Space previews, Ctrl+R renames, and Esc cancels. You don't need the other keys for now.
If you're already inside claude, type /resume. The same list opens.[2:2] When you reopen it, new messages keep piling up in the same session.[7]
Quick check
You want to reopen a conversation you named `weekly-meeting-notes` a few days ago. What do you type in the terminal in the same folder?
What Is the Context Window?
The context window is everything Claude is holding at this very moment. Think of it as the materials spread out on a desk.
It's not only your messages on the desk. The conversation history, the contents of files Claude read, and the results of commands it ran are there too. A file where rules are written down, notes saved automatically, loaded skills, and basic instructions are also included.[8] In order, these four are called CLAUDE.md, auto memory, skills, and system instructions. You'll learn CLAUDE.md and auto memory in Chapter 8, and skills in Chapter 9. For now, just know the names.
This space is counted in tokens. A token is the unit an AI uses to split text into small pieces and count it. One word can be one piece, or it can split into several pieces (the same pieces you saw in Stage 1, Chapter 1). If you have Claude read one long file, that many tokens take up space on the desk.
As the conversation gets longer, the space fills up. Then Claude Code compresses the conversation automatically. But instructions you gave early in the conversation can get lost.[9] If you said "write it as a table" once at the start and at some point the tables disappeared, this may be what happened.
So don't leave long-lasting rules as words in the conversation. Write them in CLAUDE.md (a file where you write the rules to follow in a project).[9:1] How to make one is covered in Chapter 8.
Quick check
Which statement is correct about everything Claude is holding right now (the context window)?
Three Commands for Handling Context
You don't need to worry about this from the start. When the answers seem to get fuzzy, just remember these three.
/context — See how full it is. It shows how full the context is as a colored grid.[10] Usage by category and suggestions for improvement appear too.[11] The result appears as text inside the conversation. You don't need to close it. Just keep typing.
/compact — Summarize to shrink it. It summarizes the conversation so far to free up space.[12] You can write after it what to keep.[11:1] If you write it, there's less chance that something you need gets left out of the summary.
Weaker example: /compact
Better example: /compact Keep only what we decided about the meeting notes formatIf you type it when there's almost no conversation, it tells you there's nothing to shrink.
❯ /compact
⎿ Not enough messages to compact.If you type it after the conversation has built up, it shrinks it and then tells you Compacted (ctrl+o to see full summary).
/clear — Clear it and start fresh. It starts a new conversation with an empty context. The previous conversation is saved, so you can go back to it with /resume.[12:1] Use it when you move on to unrelated work. That way the old conversation doesn't take up space needed for the next files.[11:2]
If you're unsure which of the two to use, ask yourself this.
- Am I continuing the same work? Then
/compact. - Am I moving on to other work? Then
/clear.
More details (click to expand)
If you use /clear, you may end up with two sessions with the same name. In that case, claude -r name shows a list of sessions with that name. Pick one by looking at the time and size.
There's one more tip. If the answer keeps missing the mark after you've corrected it twice, don't correct it a third time. It's better to /clear and start again with a better-written request.[13] That way the failed attempts aren't piled up in the conversation.
If the conversation gets too long, text like this may appear.
Context limit reached · /compact or /clear to continueNo need to panic.[14] Just type one of the two, as the text says.
Quick check
You finished the meeting minutes and want to start something completely different. Which command fits?
Conversation History Stays on Your Computer
You can reopen sessions because the history is saved on your computer. Conversation history is saved as plaintext in the ~/.claude/projects/ folder. Plaintext means text with no password protection that anyone can read. The default retention period is 30 days.[15]
It's not only what you typed that's kept there. Content that passed through tools is kept too: file contents, command output, and pasted text.[16]
So build these habits.
- Don't have Claude read files that contain passwords or login credentials. The moment it reads them, they may also be kept in the history.
- If you share the computer with others, remember that this folder exists.
You'll try a way to block reading entirely in Chapter 7.
More details (click to expand)
- There's also a
claude purgecommand that deletes the history for one project.[17] It's hard to undo, so don't run it just for practice. This guide didn't run it either. - The retention period on the server side is covered in Chapter 13.
Quick check
Which statement is correct about Claude Code's conversation history?
Try It Yourself
Try this in the practice folder ~/hello-ai-practice/terminal.
Start
claudeand ask this.text@inbox/meeting-2026-10-27-weekly.txt Tell me in two lines what was decided in this memo.Name it with
/rename weekly-meeting-notesand leave with/exit.In the terminal, reopen it with
claude -cand ask, "What did I just ask you?" If it remembers the earlier conversation, it continued properly.After leaving with
/exit, typeclaude -rin the terminal. Findweekly-meeting-notesin the list and open it with Enter.Type
/contextto see what's using the space.Type
/compact Keep only what was decided. It's fine if text appears saying there's nothing to shrink because the conversation is short.Clear it with
/clearand ask again, "What did I just ask you?" If it says it doesn't know, the context has been cleared. Try finding the earlier session again with/resume.
Ask yourself: Could I find yesterday's conversation and continue it? Can I say when to use /compact and when to use /clear?
Summary
- A session is a conversation saved and tied to a folder. When you start fresh, Claude doesn't know past conversations.
- Name it with
/rename, and reopen it withclaude -corclaude -r. - The context window holds not only the conversation but also file contents and command output.
- After automatic compression, early instructions can get lost. Write long-lasting rules in
CLAUDE.md. - To continue the same work,
/compact. To move on to other work,/clear. - Conversation history stays on your computer as plaintext. The default is 30 days.
Glossary
| Term | One-line meaning |
|---|---|
| Session | A conversation saved and tied to a folder |
| Context window | Everything Claude is holding right now |
| Token | The unit an AI uses to count text |
| Compact | Summarizing the conversation to free up space |
| Plaintext | Text with no password protection |
Finished this chapter?
Progress is saved only in this browser. See your progress on the full table of contents.
Next chapter: Chapter 7. Permissions and Undo
References (17)
The screens in this chapter are the results of running Claude Code 2.1.318 on Linux on November 6, 2026. ↩︎
Claude Code official docs, "Manage sessions". "A session is a saved conversation tied to a project directory." / "if you don't name a session, Claude Code generates a session title for it." / "Run
/resumeinside a session, orclaude --resumewith no arguments, to open the interactive session picker." code.claude.com (checked on 2026-11-06) ↩︎Claude Code official docs, "How Claude Code works". "Each new session starts with a fresh context window, without the conversation history from previous sessions." code.claude.com (checked on 2026-11-06) ↩︎
Claude Code official docs, "Best practices for Claude Code". "for work that spans several days,
/rename oauth-migrationin the session names it" code.claude.com (checked on 2026-11-06) ↩︎Claude Code official docs, "CLI reference". "Load the most recent conversation in the current directory" / "Resume a specific session by ID or name, or show an interactive picker to choose a session." code.claude.com (checked on 2026-11-06) ↩︎
Claude Code official docs, "Common workflows". "it prints
No conversation found to continueand exits." code.claude.com (checked on 2026-11-06) ↩︎Claude Code official docs, "How Claude Code works". "Resuming a session with
claude --continueorclaude --resumereopens it under the same session ID and appends new messages to the existing conversation." code.claude.com (checked on 2026-11-06) ↩︎Claude Code official docs, "How Claude Code works". "Claude's context window holds your conversation history, file contents, command outputs, CLAUDE.md, auto memory, loaded skills, and system instructions." code.claude.com (checked on 2026-11-06) ↩︎
Claude Code official docs, "How Claude Code works". "Claude compacts automatically, but instructions from early in the conversation can get lost." / "Put persistent rules in CLAUDE.md, and run
/contextto see what's using space." code.claude.com (checked on 2026-11-06) ↩︎Claude Code official docs, "Commands". "Visualize current context usage as a colored grid." code.claude.com (checked on 2026-11-06) ↩︎
Claude Code official docs, "Explore the context window". "run
/contextfor a live breakdown by category with optimization suggestions, including which CLAUDE.md and auto memory files loaded." / "run/compactwith instructions, like/compact focus on the auth bug fix, before starting a long new task." / "Old conversation crowds out the files you need next and costs tokens on every message." code.claude.com (checked on 2026-11-06) ↩︎Claude Code official docs, "Commands". "Free up context by summarizing the conversation so far." / "Start a new conversation with empty context." / "Resume the previous conversation with
/resume" code.claude.com (checked on 2026-11-06) ↩︎Claude Code official docs, "Best practices for Claude Code". "Watch the first minute, press
Escthe moment Claude drifts, and after two failed corrections run/clearand write a better prompt instead of a third." code.claude.com (checked on 2026-11-06) ↩︎Claude Code official docs, "Error reference". "Context limit reached · /compact or /clear to continue" code.claude.com (checked on 2026-11-06) ↩︎
Claude Code official docs, "Data usage". "Claude Code clients store session transcripts locally in plaintext under
~/.claude/projects/for 30 days by default to enable session resumption." code.claude.com (checked on 2026-11-06) ↩︎Claude Code official docs, "Explore the .claude directory". "Anything that passes through a tool is written to a transcript on disk: file contents, command output, pasted text." code.claude.com (checked on 2026-11-06) ↩︎
Claude Code official docs, "Explore the .claude directory". "Run
claude purgeto delete the state Claude Code holds for one project." code.claude.com (checked on 2026-11-06) ↩︎