Claude Code sessions

Sessions preserve conversation history and repository context. Good session hygiene makes long tasks recoverable and helps you keep parallel work separated.

Last verified
Applies to
Claude Code 2.1.x. CLI spellings were checked on local version 2.1.198; official docs may describe newer 2.1.x behavior.
Verification method
Session flags and naming behavior were checked in local help and the official Sessions page. No saved conversation was opened, renamed, exported, or deleted.
Official sources
SessionsCLI referenceChangelog

Reproducible practice

Branch a resumable investigation without altering the original session

Name a bounded investigation, resume it deliberately, and fork before trying a competing hypothesis.

Prerequisites

  • A trusted disposable repository with no sensitive transcript content.
  • A clean working tree or a recorded diff baseline.
  • An explicit session name that contains no customer or secret data.

Steps

  1. Record repository state

    Session branching does not isolate files; establish the shared filesystem baseline first.

    Step 1
    git status --short
    git rev-parse --show-toplevel
  2. Start and name the investigation

    Start interactively with a non-sensitive name and stop before making changes if the wrong project opens.

    Step 2
    claude --name session-lab
  3. Resume by explicit name

    Avoid `--continue` when multiple projects or sessions could make 'most recent' ambiguous.

    Step 3
    claude --resume session-lab
  4. Fork before a competing approach

    Create a new session ID while preserving the original transcript; remember both sessions still share repository files.

    Step 4
    claude --resume session-lab --fork-session

Expected result

The original session remains resumable, the fork appears separately, and filesystem changes are attributed through the shared git baseline.

Validation

  • Use the session picker to confirm the explicit name and separate fork.
  • Compare `git status --short` after each branch of work.
  • Export or share a transcript only after reviewing it for secrets and private paths.

Failure handling

Name is ambiguous

Open the picker and select by project and timestamp instead of guessing a session ID.

Fork changed files

Treat this as normal shared-worktree behavior; inspect and revert only the intended experiment.

Cleanup or rollback

  • Exit the fork and restore only its verified file changes through normal version-control review.
  • Keep or remove transcripts according to organizational retention policy, not by broad filesystem deletion.

Boundaries and when not to use it

  • Forking conversation context does not create a git branch or isolated worktree.
  • Transcripts may contain code, paths, prompts, and tool output; treat them as sensitive project data.

Start and continue sessions

Use interactive mode for exploration and print mode for scripts. Continue flags reload recent work in the current directory without re-explaining the repository.

CommandDescription
claudeStart a new interactive session in the current directory.
claude -cContinue the most recent conversation in this directory.
claude -r "name" "query"Resume a named or ID-based session with a new prompt.
claude --continueAlias for continuing the latest local session.
Resume a named thread
claude -r "auth-refactor" "Finish the remaining tests and summarize the diff."

Branch and recover inside a session

When a conversation drifts, branch or rewind instead of abandoning all prior work. Slash commands help you inspect history and return to a known-good point.

CommandDescription
/branchFork the conversation to try a different approach.
/resumeOpen the picker for earlier conversations or branches.
/rewindRoll code and conversation back to a checkpoint.
/clearStart fresh while keeping durable project memory.

Background and parallel sessions

Background sessions free the terminal while work continues. Agent view helps monitor many sessions and see which ones need input.

CommandDescription
claude --bg "task"Detach the session and keep it running in the background.
claude agents --jsonList active background sessions for scripting.
/tasksInspect background work and finished subagents in the current session.

Export and handoff

Sessions can move between terminal, desktop, web, and other devices when handoff commands are available and authentication remains valid.

CommandDescription
/exportExport the current conversation as plain text.
/teleportPull a web session into the current terminal.
/desktopContinue the current session in Claude Code Desktop.

Session checklist

Related topics