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
Record repository state
Session branching does not isolate files; establish the shared filesystem baseline first.
Step 1 git status --short git rev-parse --show-toplevelStart 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-labResume by explicit name
Avoid `--continue` when multiple projects or sessions could make 'most recent' ambiguous.
Step 3 claude --resume session-labFork 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.
| Command | Description |
|---|---|
claude | Start a new interactive session in the current directory. |
claude -c | Continue the most recent conversation in this directory. |
claude -r "name" "query" | Resume a named or ID-based session with a new prompt. |
claude --continue | Alias for continuing the latest local session. |
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.
Background and parallel sessions
Background sessions free the terminal while work continues. Agent view helps monitor many sessions and see which ones need input.
| Command | Description |
|---|---|
claude --bg "task" | Detach the session and keep it running in the background. |
claude agents --json | List active background sessions for scripting. |
/tasks | Inspect background work and finished subagents in the current session. |
Name important threads
Label sessions when switching between bug fixes, refactors, and reviews.
Read guideUse worktrees for isolation
Parallel code changes are safer when each session owns a separate git worktree.
Read guideMonitor with agent view
Use agent view when several background sessions run at once.
Read guideExport and handoff
Sessions can move between terminal, desktop, web, and other devices when handoff commands are available and authentication remains valid.
| Command | Description |
|---|---|
/export | Export the current conversation as plain text. |
/teleport | Pull a web session into the current terminal. |
/desktop | Continue the current session in Claude Code Desktop. |
Desktop app
Continue terminal work with visual diff review and parallel sessions.
Read guideWeb teleport
Pull cloud sessions into the local terminal without losing context.
Read guideAuthentication
Handoff requires valid login on both source and target surfaces.
Read guideExport for review
Share conversation text when handing off to a teammate outside Claude Code.
Read guideSession checklist
Continue before re-explaining
Use `-c` or `/resume` when the repository context is already established.
Read guideBranch risky experiments
Try broad design changes in a branch instead of overwriting the main thread.
Read guideClear between unrelated tasks
Use `/clear` when switching to a different feature or incident.
Read guideCheck auth on long sessions
Renew login before unattended background work exceeds the credential lifetime.
Read guide