Forty minutes into a refactor on a remote box, my SSH connection dropped and took the Claude Code session down with it. Recovery was one command after reconnecting: claude --continue, and the whole conversation plus the half-finished task came straight back. That save works because sessions are plain files on disk with a set of commands wrapped around them, and once you know the layout you can resume, branch, export and audit conversations however you like. Everything below was tested on the 2.1 CLI on Ubuntu 24.04.
Where Claude Code stores sessions
Every session is a JSONL transcript at a predictable path:
~/.claude/projects/<project-dir-slug>/<session-id>.jsonl
The slug is derived from the project directory (slashes become dashes), and each line of the file is one JSON event: a user message, an assistant reply, a tool call with its result. Plain text means greppable, which has already earned its keep for me when I needed to find which past session ran a particular schema change:
grep -l "ALTER TABLE" ~/.claude/projects/-home-user-api/*.jsonl
Transcripts don't live forever. Retention is controlled by cleanupPeriodDays and defaults to 30 days, after which old sessions get cleaned up. If yours double as an audit trail, raise it (the FAQ below covers how). The lifecycle details sit in the official sessions documentation.
claude --continue vs claude --resume
claude --continue (short form -c) reopens the most recent session for the current directory without showing a picker. It's the right tool nine times out of ten and the one to reach for after a crash or a dropped connection. claude --resume (-r) opens an interactive picker of past sessions instead and also accepts a session id or name directly:
claude --continue
claude --resume
claude --resume auth-refactor
Both are scoped to the directory you run them in, so cd into the project first; a resume attempt from the wrong folder finds nothing and that absence confuses people more than any error message would. Names come from the --name flag at launch or /rename later, and named sessions make the picker worth opening.
The third option, --fork-session, resumes a copy rather than appending to the original. I use it to try a second approach against the same conversation history without polluting the transcript I may want to return to. All three flags are listed in the CLI reference.
Switch sessions without restarting
Inside a running session the same machinery is reachable as slash commands. /resume opens the picker, /clear ends the current session and starts a fresh one (the old transcript stays on disk), /branch splits a new session off the current conversation and /rename sets the name the picker will show. I run /clear liberally because long conversations bloat the context window, and /rename right before stopping for the day, since "auth-refactor" reads a lot better than a UUID the next morning.
What a resumed session restores
Resume brings back the conversation history, the model selection and the agent you were running, and it keeps the permission mode with two exceptions: plan and bypassPermissions are never restored, a deliberate safety choice I dug into in the piece on Claude Code plan mode. Command-line flags don't survive either: anything you passed with --mcp-config or --add-dir (and --settings) has to be passed again.
claude --resume auth-refactor --mcp-config ./mcp.json --add-dir ../shared-lib
Forgetting this produces a classic confusion: the resumed session answers questions from history perfectly, then stumbles the moment it reaches for an MCP tool that's no longer attached. The clean fix is moving servers out of flags entirely; project-scoped servers live in a checked-in .mcp.json and load on every start, which the Claude Code MCP configuration guide covers scope by scope.
Export a Claude Code conversation
For a human-readable copy, /export does it in-session:
/export session-notes.txt
That writes a plain-text transcript to the file you name, good enough for pasting into a PR description or handing a teammate the context of a decision. For anything structured, script it instead. Headless mode plus resume turns any old session into something you can query:
claude -p --resume <session-id> --output-format json "summarize the decisions made in this session and list every file we changed"
That resumes the session non-interactively, runs one prompt against the full history and emits JSON you can pipe through jq. I keep a small script that walks the week's sessions this way and produces a Friday digest of what the agent changed and why. And since the JSONL files are the raw source, nothing stops you from parsing them directly for tool calls or timestamps, no export step needed.
Check token usage in a session
Three commands answer the "how much have I used" family of questions. /usage (also reachable as /cost) shows the current session's token consumption. /context is the one I open more, because it visualizes what's occupying the context window right now, from memory files and MCP tool definitions to the conversation itself, so you can see exactly what to prune when the window fills up. /status rounds things out with account state: login method, organization and where you stand against your plan's limits. What those limits mean plan by plan is a separate topic, covered in Claude Code cost and usage limits.
Keep remote sessions alive with tmux
Back to the dropped SSH story. --continue made recovery painless, but I'd rather not need it, so on servers every session now starts inside tmux; a dead connection then leaves Claude working instead of killing it, and tmux attach after reconnecting skips even the resume step. The full server workflow is in the guide to running Claude Code on a VPS. That setup has quietly become my default for long agent tasks, and it's cheap to reproduce: LumaDock's Claude Code VPS hosting is a one-click template, the box comes up instantly with the CLI preinstalled and unmetered bandwidth means an agent pulling dependencies all night adds nothing to the bill. The session keeps working after the laptop lid closes.
One habit worth stealing before you go: /rename anything unfinished when you step away. Ten seconds of naming beats scrolling a picker full of auto-generated titles at nine the next morning.

