Українська версія

Author: abavyka

Mid-task a side task pops up, and you can branch it off so the main session stays about one task.

Why

When topics get mixed in one session, the model gets confused and the focus gets smeared. The Claude Code docs even have a name for it — kitchen sink session: you start with one task, ask something unrelated, come back, and the context is already stuffed with irrelevant junk (why a long session goes dumb was in Context and cache).

A fresh session from scratch isn’t always an option either: if the side task depends on what’s already been gathered, you’ll have to explain everything all over again. Branching gives you a copy of the conversation with all the context, and the main session stays clean.

My case

I was fixing our MCP, and along the way I had to fix the Copilot agent. To keep the focus from getting smeared, I did /fork and sorted out Copilot separately there.

The surprise was that fork works in its own worktree, and it was hanging in the background in agent view. That’s when I learned about /branch: in a monorepo I could’ve just used that. Later I tried /branch on the same case, and for this task it fit better, because it needed input from me and testing of the Copilot agent.

/branch

Copies the conversation up to this point and switches you into the copy. The original stays as it was, to go back — /resume <name>.

/branch copilot-agent
  • no name — the branch gets named after the first prompt
  • from the terminal — claude --continue --fork-session
  • it branches the conversation, not the files: same folder, edits from both branches land in the same files

/fork

Copies the conversation into a new background session, and you stay in the current one. The copy takes the model, permission mode, effort and the permissions you already granted in the session, and shows up as a separate row in agent view (claude agents).

  • with a prompt (/fork розберись з конфігом copilot агента) — gets to work right away, without a prompt — waits for its first instruction in claude agents
  • before editing code it makes itself a worktree in .claude/worktrees/ — a separate working copy of the repo on its own branch, so it doesn’t touch your files
  • at the end it commits its branch and pushes if there’s a remote (never to main). If your CLAUDE.md says you do git yourself, it leaves it to you
  • the result doesn’t come back on its own, after the fork the sessions are independent
  • a worktree Claude created gets deleted together with the session in agent view, so commit first

There’s also /subtask

Launches a forked subagent: a background subagent that inherits the whole conversation and works while you keep going. Its tool calls don’t land in your context, only the result comes back.

/subtask допиши тести на парсер, який ми змінили

And /btw — ask something about the session without cluttering the history. It has no tools, it answers only from what’s already in the context.

How to pick

  • /branch — you go off in another direction yourself, same code
  • /fork — the side task lives separately, with its own edits
  • /subtask — a side task whose result you need here
  • new session or /clear — when the session is full of junk the side task doesn’t need: fork drags along the whole context, junk included. The docs advise the same after two failed corrections: /clear and a better prompt

Tokens

A fork starts from the same prefix, so its first request reads the original’s cache, and the original’s cache doesn’t break. But after that every copy eats its own tokens from the shared limit.

Read more