Claude Code sessions: resume, rewind, branch and run in parallel
Every Claude Code conversation is saved as you work. Run claude -c to carry on with the last one in a folder, or claude -r to pick an older one. Press Esc twice or run /rewind to go back to an earlier message with the code as it was, /branch to try another approach without losing this one, and claude -w name to run a second session in its own Git worktree.
Daily use
Take this page into your AI
Open in ChatGPT (new tab)Open in Claude (new tab)A Claude Code session is one conversation, tied to the folder you started it in. It is saved to your machine as you go, so closing the terminal loses nothing: you can come back to it tomorrow, rewind it to an earlier point, or split it in 2.
Come back to a conversation
claude -c # the most recent conversation in this folder
claude -r # choose from a list
claude -r billing-bug # reopen the one named billing-bug
Inside a session, /resume does the same. The list shows each conversation's name or a title made from your first message, how long ago it was active and its Git branch. Type to search it, press Space to preview one, and Ctrl+A to see every project on the machine.
Name a session when you start it, claude -n billing-bug, or later with /rename billing-bug. With 3 tasks on the go, names are what make the list readable.
A resumed session comes back with its full history and the model it was using. Flags such as --add-dir or --mcp-config are not remembered, so pass them again.
Undo: rewind to an earlier message
Before each message you send, Claude Code saves the state of the files it is about to edit. Press Esc twice on an empty prompt, or run /rewind, and pick the message to go back to. Then choose:
- Restore code and conversation: everything as it was at that message.
- Restore conversation: rewind the talk but keep the code as it is now.
- Restore code: put the files back but keep the conversation, so Claude knows what it tried.
- Summarize from here: keep the start, squeeze the rest into a summary to free space.
The message you went back to reappears in the prompt, so you can change it and send it again.
Rewind tracks only what Claude changed with its own editing tools. A file deleted with rm, moved with mv or changed by a script it ran is not restored. Rewind is a quick undo, not a replacement for committing to Git.
Try another way without losing this one
/branch copies the conversation so far into a new session and switches you to it. The original stays untouched; /resume takes you back. From the command line, claude -c --fork-session does the same with the last conversation.
Use it when you want to compare 2 approaches, or before a risky turn you may want to abandon.
Clear or compact
/clear starts an empty conversation in the same folder. The old one is saved, and /resume reopens it. Use it whenever you move to an unrelated task: everything from the last task stays in the context, costs tokens on every turn and pulls Claude off course.
/compact keeps the conversation going but replaces the history with a summary. Add what must survive: /compact keep the failing test names and the plan. /context shows what is taking up the room. How Claude Code works explains the Context WindowContext WindowEverything a model can see at once while it writes an answer, counted in tokens. When the window is full, something has to be left out. behind both.
If you resume a large conversation after more than about an hour away, Claude Code may offer to resume from a summary, since the whole history has to be processed again once the cache has expired.
Several sessions at once
2 sessions in the same folder edit the same files, and will undo each other's work. Give each its own Git worktree instead:
claude -w fix-login # terminal 1
claude -w monthly-report # terminal 2
Each worktree is a second checkout of the repository under .claude/worktrees/<name>/, on its own branch (worktree-fix-login). The sessions share history and remote but not files, and Claude Code blocks edits from a worktree session to your main checkout.
3 things to set up once:
- Add
.claude/worktrees/to.gitignore. - A worktree is a fresh checkout, so it has no
node_modulesor build output. Ask Claude to install dependencies first. - To copy ignored files such as
.envinto each new worktree, list them in a.worktreeincludefile at the repository root.
When you leave a worktree session, Claude Code checks it for changes and new commits. If there is work in it, it asks whether to keep the worktree, and prints the command to come back to it.
Where sessions are kept
Each conversation is a JSONL file in ~/.claude/projects/, in a folder named after the project's path. They stay for 30 days after their last use; set cleanupPeriodDays in settings to change that, or run claude purge to delete a project's sessions now.
/export saves the current conversation as readable text or copies it to the clipboard. For a script, ask an old session a question and read the answer as JSON:
claude -p --resume <session-id> --output-format json "summarize what we changed" | jq -r '.result'
The JSONL format is internal and changes between versions, so do not build on it directly.
Questions
- How do I resume a Claude Code session?
- Run claude -c in the same folder to reopen the most recent conversation, or claude -r to choose from a list. Inside a session, /resume switches to another one. If you named the session, claude -r and the name reopens it directly.
- Can Claude Code undo its changes?
- Yes, for changes made with its file editing tools. Press Esc twice on an empty prompt, or run /rewind, pick the message to go back to, and choose to restore the code, the conversation or both. Files changed by shell commands, such as rm or mv, are not tracked, so commit to Git as well.
- How long does Claude Code keep my sessions?
- About 30 days by default, as JSONL files under ~/.claude/projects/ on your own machine. Change it with cleanupPeriodDays in your settings, or delete a project's sessions sooner with claude purge.
- How do I run 2 Claude Code sessions at the same time?
- Start each in its own Git worktree with claude -w and a name, such as claude -w fix-login in one terminal and claude -w new-report in another. Each gets its own copy of the files on its own branch, so they cannot overwrite each other's edits.
- What is the difference between /rewind and /branch?
- /rewind goes back in this conversation and drops what came after. /branch copies the conversation so far into a new one and switches you to it, so the original stays as it was and you can return to it with /resume.
Sources