Claude Code sessions productivity CLI developer-tools

Claude Code --continue and --resume: Never Lose Your Session Context Again

Prompt Shelf ·

One of the most underused features in Claude Code is session management. Most developers just open a new session every time, which means re-explaining the codebase, restating context, and repeating setup work on every return.

Claude Code stores every session. With the right flags, you can resume exactly where you left off — whether your connection dropped, you switched machines, or you deliberately paused a complex refactor to handle something urgent.

This guide covers every session management feature available as of June 2026.


Why Session Context Matters

When you start a fresh Claude Code session and ask it to continue a task, you’re not resuming — you’re rebuilding. Claude has to re-read files, re-understand the codebase structure, and reconstruct the mental model of what was being attempted.

A resumed session carries:

  • Full conversation history
  • All file reads and diffs from the previous session
  • The reasoning chain behind previous decisions
  • Awareness of what has already been tried and failed

For long refactors, architecture discussions, or debugging sessions spanning hundreds of tool calls, this context has real value. Losing it means starting over.


Session Storage

Claude Code stores sessions at:

~/.claude/projects/<project-path>/<session-id>.jsonl

Each session is a JSONL file (newline-delimited JSON), with one event per line. Sessions are kept for 30 days by default. To change the retention period:

// ~/.claude/settings.json
{
  "cleanupPeriodDays": 90
}

Set to 0 to keep sessions indefinitely (disk space permitting).


The Core Flags

--continue / -c: Resume the Latest Session

# Resume the most recent session in the current project
claude --continue
claude -c  # shorthand

This is the fastest way to return to where you left off. No picker, no searching — it finds the most recent session for your current working directory and opens it.

Works with -p for headless use:

claude -c -p "Continue the database migration from where we left off"

--resume / -r: Interactive Session Picker

# Open the interactive session picker
claude --resume
claude -r  # shorthand

# Resume a specific session by name or UUID
claude --resume auth-refactor
claude --resume 7f3a9c2b-...

The picker shows sessions grouped by recency, with timestamps and a preview of the last message in each session.

Picker keyboard shortcuts:

ShortcutAction
Ctrl+AShow all sessions across all projects on this machine
Ctrl+WShow sessions across all worktrees of the current repository
Ctrl+BFilter to sessions on the current git branch
/Search mode — type to filter sessions

Paste a GitHub PR URL directly into the picker to find sessions associated with that PR.

--from-pr: Resume a Session Linked to a PR

claude --from-pr 482
claude --from-pr https://github.com/org/repo/pull/482

When you started a Claude Code session while working on a PR and that session was associated with the PR, this flag finds it. Useful when returning to a PR review after a few days.


Naming Sessions

Anonymous sessions get auto-generated names. Named sessions are searchable and meaningful:

# Start a new named session
claude -n "payment-gateway-refactor"
claude --session-name "fix-race-condition-auth"

Rename a session mid-conversation:

/rename payment-v2-migration

The session name appears in the prompt bar when active, making it easier to know which context you’re in when multiple sessions are running.


Forking a Session

Sometimes you want to branch from a session without affecting the original — for example, trying an alternative approach to the same problem.

# Resume a session but fork it (creates a new session branching from the resumed one)
claude --continue --fork-session
claude --resume auth-refactor --fork-session

The original session is preserved exactly as-is. The fork starts from the same context but is treated as an independent session going forward. Changes in the fork don’t affect the original.

This is particularly useful for:

  • Testing two different implementation approaches without losing either
  • Exploring a risky change while keeping a clean recovery point
  • Handing off a session to a teammate while keeping your own copy

The /resume Command (In-Session)

To switch sessions without exiting:

/resume

Opens the same interactive picker from within an active session. The current session is automatically saved.


Exporting a Session

To save the full session for documentation, handoff, or archival:

/export

Copies the session transcript to the clipboard. With a filename argument, writes to disk:

/export session-auth-refactor-2026-06-17.md

The export includes all conversation turns, tool calls, and file operations in a readable format.


Checkpointing: Rewind Without Losing Work

Separate from session resumption, Claude Code also checkpoints automatically at each user prompt. These checkpoints let you rewind within a session — not just resume across sessions.

To access checkpoints:

  • Press Esc twice when the input field is empty
  • Type /rewind

The checkpoint picker shows every user turn in the current session. For each checkpoint, you have five actions:

ActionWhat It Does
Restore code and conversationReverts both the conversation and all file changes to this point
Restore conversationReverts only the conversation; keeps file changes as-is
Restore codeReverts only the file changes; keeps the conversation as-is
Summarize from hereCompresses all messages after this point into a summary (/compact variant)
Summarize up to hereCompresses all messages before this point into a summary

Important limitation: Checkpointing tracks files modified through Claude Code’s file editing tools. Files changed by Bash commands (e.g., sed, mv, git checkout) are not tracked and won’t be reverted.

This is different from --fork-session. Forking creates a separate session from a resumed point. Checkpointing rewinds within the current session.


Practical Patterns

Pattern 1: Daily Continuation

Start each day by continuing yesterday’s session on the feature you’re working on:

# Start with context from yesterday
claude -c

# Or be explicit about which task
claude --resume feature-user-auth

This is faster than explaining “I’m working on the user authentication flow, the JWT implementation is in src/auth/, and we were in the middle of implementing refresh token rotation…”

Pattern 2: Safe Exploration with Fork

Before making a risky structural change:

# Save the current state and branch from it
claude --continue --fork-session -n "try-new-db-schema"

If the experiment goes badly, the original session is intact. Return to it with --resume.

Pattern 3: Parallel Work on Multiple Features

# Session for feature A
claude -n "feature-analytics-v2" --bg "Implement the analytics dashboard, start with the data model"

# Session for feature B in a different terminal
claude -n "feature-notifications" --bg "Build the notification system, email + push"

# Check all running sessions
claude agents

# Attach to whichever finishes first
claude attach feature-analytics-v2

Pattern 4: Handoff Documentation

Before handing off a complex session to a teammate or archiving it:

/export handoff-feature-payments-2026-06-17.md

The export gives a complete record of decisions made, approaches tried, and the current state of the work.


Headless Session Resumption

For automation, session context can be passed through --session-id:

# Get the session ID of the last session
LAST_SESSION=$(claude -p "" --output-format json 2>/dev/null | jq -r '.session_id' | head -1)

# Resume that session in a later job
claude -p "Continue the task" --session-id "$LAST_SESSION" --output-format json

Or capture the session ID when starting:

SESSION_DATA=$(claude -p "Start analyzing the API for rate limit issues" --output-format json)
SESSION_ID=$(echo "$SESSION_DATA" | jq -r '.session_id')

# Save for later
echo "$SESSION_ID" > .claude-session-id

# Resume in next CI step
claude -p "Report findings and suggest fixes" \
  --session-id "$(cat .claude-session-id)" \
  --output-format json

Troubleshooting

--continue opens a fresh session instead of resuming

The most common cause: the previous session is in a different working directory. Session lookup is project-path based. If you opened Claude Code from ~/projects/myapp/src last time and you’re now in ~/projects/myapp, they’re treated as different projects.

Solution: always run Claude Code from a consistent root directory for a given project, or use --resume with an explicit session name.

Session picker shows no recent sessions

Sessions older than cleanupPeriodDays (default 30 days) are deleted. If the project path changed (rename, move), sessions won’t appear for the new path.

Checkpoint rewind didn’t restore a file

Files modified by Bash commands aren’t checkpointed. If Claude ran git checkout -- src/auth.ts or used sed -i to modify a file, that change is outside the checkpoint scope. Only edits made through Claude Code’s built-in file tools are tracked.


Summary

GoalCommand
Continue most recent sessionclaude --continue or claude -c
Pick a session interactivelyclaude --resume or claude -r
Resume by nameclaude --resume session-name
Resume from a PRclaude --from-pr 482
Start a named sessionclaude -n "name"
Fork a session before risky workclaude --continue --fork-session
Switch sessions mid-conversation/resume
Export session transcript/export
Rewind within a session/rewind or double Esc
List all running sessionsclaude agents

The session system in Claude Code is sophisticated enough to support multi-day workflows, parallel tracks, safe experimentation, and handoffs. Most developers are leaving significant productivity on the table by starting fresh every time.


Related Articles

Claude Code --continue と --resume 完全ガイド2026——セッションコンテキストを二度と失わない方法

Claude Codeのセッション管理を完全解説。--continue, --resume, --fork-session, セッション命名, インタラクティブピッカー, チェックポイントまで網羅。中断したセッションをいつでも正確に再開する方法。

claude -p JSON Output Breaks in Production — Fix It with Structured Output

Running claude -p in a pipeline and getting malformed JSON? Here's exactly why it happens, what --output-format json actually does, and how to build a Python implementation with validation and retry.

Claude Code Secrets Management with 1Password CLI: op run, Shell Integration, and MCP — Complete 2026 Guide

Stop committing .env files. This guide covers three production patterns for vaulting Claude Code secrets in 1Password — op run runtime injection, shell integration (zsh/fish/bash), and the 1Password MCP server — with a decision matrix against Doppler, Infisical, HashiCorp Vault, and SOPS.

GitHub Copilot CLI vs Claude Code CLI: 2026 Engineer Comparison (Models, Pricing, Workflows)

2026 Q2 updated comparison of GitHub Copilot CLI and Claude Code CLI. Model availability (Opus 4.7 / GPT-5 / Gemini 3 Pro), agent architecture, pricing tiers, SWE-bench scores, AGENTS.md compatibility, ideal use cases, and how senior engineers compose both. FAQ included for AGENTS.md and pricing questions.

Explore the collection

Browse all AI coding rules — CLAUDE.md, .cursorrules, AGENTS.md, and more.

Browse Rules