How Claude Code worksPart 2
Sessions and forks
On this page
In short: Your new colleague keeps everything in a notebook. That notebook is a session. When you want to try a different idea without spoiling the first, you photocopy the notebook and write the new ending in the copy. That is a fork. And when there is a messy side job, you hand a copy to an assistant who comes back with one sticky note. That is a fork subagent.
Part 1 showed where your colleague works. This part is about what they remember.
What a session is
Think of it like this: A shared notebook. Everything you say, everything Claude does, every file it reads, gets written in it.
Claude has no memory of its own between conversations. Everything it knows about your task is in the notebook. That is why a long session feels sharp about your project, and a new one starts from zero.
There is a limit, though. Claude can only keep so many pages open on its desk at once. That limit is the context window. Big outputs, like long files, fill it fastest.
A notebook you and Claude write in together. Close it, open it later, and every page is still there.
Photocopy the notebook so far, then write a different ending in the copy. The original is untouched.
Hand a photocopy to an assistant. They do a messy side job and give you back one sticky note with the answer.
A session’s life: start, pause, resume, compact
Think of it like this: You can close the notebook, go home, and open it again tomorrow. When it gets too thick, you write a one-page summary and put the old pages away.
Sessions are saved as you go. Closing the app does not lose anything.
- Start a new notebook for new work.
- Resume the same notebook to carry on.
- Compact to replace old pages with a summary when the desk is full.
- Rewind to tear out the last few pages when Claude went the wrong way.
Under the hood: the commands
| You want to | Command in Claude Code | What happens |
|---|---|---|
| Start something new | claude | A fresh session with an empty history and a new ID |
| Continue where you just left off | claude --continue (-c) | Reopens the most recent session in this folder |
| Pick an older session | claude --resume (-r), or /resume | Opens a list; the one you choose loads with its full history |
| Clear the slate inside the app | /clear | Starts with an empty context. The old session is saved and can be resumed |
| Free up room but keep the gist | /compact | Replaces older history with a summary. Details go, decisions stay |
| Undo the last few turns | /rewind, or Esc twice on an empty prompt | Goes back to an earlier prompt, with the code, the conversation or both |
| Branch off a copy | /branch, or claude -r <id> --fork-session | Copies the history into a new session ID. The original stays as it was |
In the Claude desktop app, each task is its own session; you reopen it from the task list.
What a fork is
Think of it like this: Photocopy the notebook, then write a different ending in the copy. The original stays exactly as it was.
A fork copies everything said so far into a second session. From then on, the two are separate. What happens in one never shows up in the other.
Important: The photocopy is of the notebook, not of your files. If both copies work in the same project folder, they will edit the same files and get in each other’s way. Give the copy its own copy of the project first, such as a separate git branch in its own folder.
- You have built up useful context and want to try two approaches from the same starting point.
- You are about to try something risky and want the current conversation kept exactly as it is to fall back on.
- Someone (or you, later) should carry on from your setup without adding to your thread.
- The new task is unrelated. Start a fresh session: old context only adds noise and cost.
- You only want to undo a mistake.
/rewindis simpler. - The context is almost full. A fork copies the whole load, so
/compactfirst or start fresh with a short summary. - Both copies would edit the same files at the same time.
Under the hood: how to fork
Inside a session, /branch copies the conversation and switches you into the copy. From the shell, add --fork-session to --resume or --continue. For code, make a separate folder for the copy with git worktree add ../my-copy -b try/other-idea before you fork into it.
The other kind of fork: a side job that reports back
Think of it like this: You hand a photocopy to an assistant. They go off, read forty files, and come back with one sticky note: “the answer is X”. Your desk stays clear.
A fork subagent is a helper that starts with everything you have discussed, does a noisy job somewhere else, and brings back only the result. A fresh subagent is a helper who starts knowing nothing but your short brief. Fresh is cheaper; a fork already knows the background.
- The side job produces a lot of output but you only need the conclusion.
- The job depends on what you have already discussed, so briefing a fresh subagent would take long.
- You want several independent checks in parallel; each fork reports back on its own.
- The task is small. Starting one costs time and tokens; just ask directly.
- You need to see the details yourself. They stay inside the subagent.
- The job needs no background. A fresh subagent with a one-line brief is cheaper.
Rule: If briefing the helper would take a paragraph or more, send a fork. If one or two sentences would do, send a fresh helper.
Under the hood: starting a helper
In Claude Code, type /subtask followed by the job to start a fork yourself, or ask in plain words: “fork yourself to check every form for missing labels”. Claude also starts helpers on its own when a job fits, which it does by default. In the desktop app, asking in plain words works the same way.
One afternoon, worked through
A made-up example: building a landing page for a client called Acme. The names and IDs are invented.
- 1 · New session
You open Claude in the project and spend an hour on the brief, the brand tokens and the page structure. That history is now worth keeping.
cd ~/clients/acme claude
- 2 · Fork subagent
You ask: "Fork yourself to check every component for hard-coded colours and give me a list." The fork already knows the tokens you agreed on, reads 30 files, and returns a six-item list. Your session gains six lines, not thirty files.
/subtask check every component for hard-coded colours and list them
- 3 · Pause and resume
You close the laptop for the evening. The next morning you pick up the same thread.
claude --continue
- 4 · Session fork
The client wants to compare a bold hero with a minimal one. You commit your work, make a git worktree for the second version, and fork the session into it, so both directions start with everything already decided.
git worktree add ../acme-minimal -b minimal cd ../acme-minimal claude --resume 7f3a… --fork-session
- 5 · Fresh session
Later you need an invoice template for a different client. Unrelated work, so you start a new session instead of forking. No Acme context comes along.
cd ~/clients/globex claude
Which one should I use?
- Starting a different task: Start a fresh sessionOld context would only add noise and cost. Run
claude, or open a new task in the desktop app. - Coming back to yesterday's work: Resume
claude --continuefor the latest session in this folder, orclaude --resumeto pick from a list. The full history comes back. - Want to try two approaches: Fork the session
/branchinside the session, orclaude --resume <id> --fork-sessionfrom the shell, gives you a second line with the same past. Put it in its own git worktree so the two don't overwrite each other's files. - Need a big search, only want the result: Use a fork subagent
/subtask <task>, or ask Claude to fork itself. It inherits your context, does the noisy work elsewhere and hands back only the result. - Claude went the wrong way: Rewind, don't fork
/rewind, orEsctwice on an empty prompt, steps back to before the wrong turn in the same session, code and conversation. A fork would keep the mistake in both copies. - Context is nearly full: Compact or start fresh
/compactkeeps decisions and drops detail. Or ask Claude for a short summary and paste it into a new session. Forking now would copy the overload.
Under the hood: the full comparison
| Fresh session | Resume | Session fork | Fork subagent | |
|---|---|---|---|---|
| Starts with history? | No | Yes, the same thread | Yes, copied | Yes, copied |
| New session ID? | Yes | No | Yes | Runs inside yours |
| Changes the original? | No | Yes, adds to it | No | Only adds its result |
| Cost to start | Lowest | The whole history | The whole history | The whole history |
| Shares your files? | Yes | Yes | Yes, unless you isolate it | Yes, unless isolated |
| Best for | Unrelated work | Carrying on | Two directions, safe experiments | Noisy side jobs |
Three rules of thumb
Everything in the history costs tokens on every turn. Keep sessions focused, and start fresh rather than carrying old baggage.
Forks copy the conversation, never your folder. Give parallel work its own branch or worktree.
When a job is noisy, push it into a fork subagent and keep only the result.
QuizYou want to try a second design for a page without losing the first, and both will change the same files. What do you use?
Show the answer
Answer: A session fork in its own git worktree
A session fork keeps both notebooks, and the separate folder keeps their files apart. A fork subagent only brings back a note, /rewind throws the first attempt away, and /compact only shortens the notebook.
Words in this post:
- Session: one conversation and everything in it, the notebook.
- Context window: how much of the notebook Claude can keep open at once.
- Fork: a copy of a session that carries on separately.
- Subagent: a helper that does a job and reports back.
- Worktree: a second copy of your project folder on its own git branch.
The commands here were checked against the Claude Code documentation in November 2026. Flags change between versions, so claude --help is the final word for yours.
Next, Part 3: Skills, hooks and subagents covers the files you add to a project to steer your colleague.
Setting up Claude Code or AI agents for your team?
I help teams build this: agents, RAG search and Claude Code setups that hold up in production.
Series
How Claude Code works
- How Claude Code worksWhere Claude runs
- How Claude Code worksSessions and forksyou are here
- How Claude Code worksSkills, hooks and subagents
- How Claude Code worksMCP servers and plugins
- How Claude Code worksPermissions and safety
- How Claude Code worksContext and cost
- How Claude Code worksSpecs as the source of truth
- How Claude Code worksContract first
- How Claude Code worksVerify against the spec
- How Claude Code worksHandoffs and memory
- How Claude Code worksYour setup as a kit
- How Claude Code worksRolling it out