Skip to content
zeeshare.com

writing / FDE and agents

How Claude Code works

How Claude Code worksPart 2

Sessions and forks

On this page
  1. What a session is
  2. A session’s life: start, pause, resume, compact
  3. What a fork is
  4. The other kind of fork: a side job that reports back
  5. One afternoon, worked through
  6. Which one should I use?
  7. Three rules of thumb

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.

Main session Forked session Fork subagent (side job)

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.

Session id: 7f3a…c21 You: build a landing page for Acme Claude: reads 12 files tool output: 4,800 lines You: use the brand fonts Claude: edits index.html …every message stays in the history Context window how much Claude can hold in mind 0% full compaction zone Big tool outputs fill it fastest. When it is nearly full, Claude summarises older history to make room (/compact).
Each turn adds to the history. The meter is the cost of remembering it all.
Session

A notebook you and Claude write in together. Close it, open it later, and every page is still there.

Fork

Photocopy the notebook so far, then write a different ending in the copy. The original is untouched.

Fork subagent

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.

Startclaude Workhistory grows Close laptopsaved to disk Resumeclaude -c / -r squash Compact/compact Keep goingsummary + new turns
The pink dot is you. It waits while the laptop is closed, then carries on in the same session.
  • 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 toCommand in Claude CodeWhat happens
Start something newclaudeA fresh session with an empty history and a new ID
Continue where you just left offclaude --continue (-c)Reopens the most recent session in this folder
Pick an older sessionclaude --resume (-r), or /resumeOpens a list; the one you choose loads with its full history
Clear the slate inside the app/clearStarts with an empty context. The old session is saved and can be resumed
Free up room but keep the gist/compactReplaces older history with a summary. Details go, decisions stay
Undo the last few turns/rewind, or Esc twice on an empty promptGoes back to an earlier prompt, with the code, the conversation or both
Branch off a copy/branch, or claude -r <id> --fork-sessionCopies 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.

shared history (copied, not linked) briefread codeplantokens set fork point /branch or --fork-session Original · id 7f3a… → tries option A Branch · new id b91e… → tries option B
Two dots, two futures. Neither sees what the other does after the split.

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.

Fork when
  • 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.
Don't fork when
  • The new task is unrelated. Start a fresh session: old context only adds noise and cost.
  • You only want to undo a mistake. /rewind is simpler.
  • The context is almost full. A fork copies the whole load, so /compact first 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.

Without a fork: the search happens in your session 12 file dumps now live in your history context 88% full With a fork subagent: only the answer comes back the noise stays inside the subagent fork (full context) 3-line answer context 34% full
Same question, same answer. The lower session stays lighter and sharper for what comes next.
Use a fork subagent when
  • 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.
Skip it when
  • 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. 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. 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. 3 · Pause and resume

    You close the laptop for the evening. The next morning you pick up the same thread.

    claude --continue
  4. 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. 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: Resumeclaude --continue for the latest session in this folder, or claude --resume to pick from a list. The full history comes back.
  • Want to try two approaches: Fork the session/branch inside the session, or claude --resume <id> --fork-session from 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, or Esc twice 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/compact keeps 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 sessionResumeSession forkFork subagent
Starts with history?NoYes, the same threadYes, copiedYes, copied
New session ID?YesNoYesRuns inside yours
Changes the original?NoYes, adds to itNoOnly adds its result
Cost to startLowestThe whole historyThe whole historyThe whole history
Shares your files?YesYesYes, unless you isolate itYes, unless isolated
Best forUnrelated workCarrying onTwo directions, safe experimentsNoisy side jobs

Three rules of thumb

Context is a budget

Everything in the history costs tokens on every turn. Keep sessions focused, and start fresh rather than carrying old baggage.

Copy the talk, isolate the files

Forks copy the conversation, never your folder. Give parallel work its own branch or worktree.

Return answers, not transcripts

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.

See services
Next in this seriesHow Claude Code worksSkills, hooks and subagents7 min read