Introduction
You spend hours working on a login screen fix in Claude Code, only to close the terminal mid-task. The next morning, you type 'claude' again, and you find yourself having to explain 'where you left off yesterday' from scratch. This is a path many people who start using Claude Code walk at least once.
In short, Claude Code does not discard your conversations. Conversations are automatically saved in units called 'sessions,' and commands are provided to return to them. This article organizes the mechanism, three ways to resume (--continue, --resume, and /resume within a session), conversation branching (/branch), and --worktree for parallel development using decision flows and diagrams. Additionally, it compares how the same things are expressed in OpenAI's Codex CLI.
The intended audience is those who have already installed Claude Code and run it at least once. If you understand basic Git operations (branches, commits), you should be able to follow the worktree section.
Environment verified in this articleOn September 15, 2026, I verified Claude Code and Codex CLI on macOS. Claude Code was 2.1.266 at the first launch, the demonstration of resuming, branching, and worktree after the built-in automatic update was 2.1.272, and Codex CLI was 0.154.0.
Using a small Git repository for demonstration, I performed conversation termination and resumption, renaming, listing, branching, and worktree creation, as well as verification upon termination. The 'execution log playback' below is a readable redraw of actual CLI input/output. It is not a screen recording of the OS. I have shortened the wait times between operations and cleaned up the working paths and some display symbols.
For the recording launch, I added --safe-mode --tools "" --permission-mode manual --no-chrome to verify without personal customizations or tool execution. This additional specification is not required for normal resumption. The Codex side has been cross-referenced with CLI help and official documentation, and the same conversation demonstration as Claude Code below has not been performed.
First, here is a short demonstration of 'telling a password -> exiting -> resuming and checking if it can be remembered'.
Saving is automatic, and resuming is done with a single command; that is the essence of this article. In the demonstration, I was able to confirm that it answered 'blue notebook' when asked without re-sending the password.
What is a session — Understanding the saving mechanism first
A session is a single conversation saved in association with a project. A unique session ID is assigned to a new conversation, and even if you resume after exiting, it continues as the same conversation. The exchanged messages, tool calls and their results, and context are sequentially written to a transcript file for each working directory (project).
The default save location is as follows.
~/.claude/projects/<作業ディレクトリのパスを変換した名前>/<session-id>.jsonl
What is important here is the 'sequentially' part. It is not saved all at once upon exit, but written every time the conversation progresses, so even if the terminal crashes or the PC goes to sleep, the saved content remains in the file. However, this does not guarantee the continuation of tools that were running at the time of stoppage or content that has not yet been saved. The flow is organized as follows.
Start a new conversation
Relationship between conversation and saving: A new session ID is assignedProceed with the exchange
Relationship between conversation and saving: Conversation is saved sequentiallyExit with /exit
Relationship between conversation and saving: Saved conversation remainsResume with --continue / --resume
Relationship between conversation and saving: Load the saved conversation and append the continuation
After resuming, new messages are appended to the same session ID. If you suppress saving with --no-session-persistence or CLAUDE_CODE_SKIP_PROMPT_HISTORY, this premise does not apply.
Operationally, knowing these three points from the start will save you trouble later.
Transcripts are cleaned up after 30 days by default. You can change this with cleanupPeriodDays in settings.json.
If you want to change the storage location, use the CLAUDE_CONFIG_DIR environment variable. This is useful if, for example, you don't want files under ~/.claude on a company-issued PC.
The internal format of the JSONL files is subject to change with each version. For human reading, use /export; if using from a script, it is safer to use official interfaces like claude -p --resume <session-id> --output-format json.
Three + one ways to resume — A decision flow for which one to use
The entry points for resuming are divided into "startup options" and "in-session slash commands." Startup options are specified when launching claude, and you can check the list with claude --help.
claude --continue (-c)
What it does:Automatically opens the last session used in the current directory
Best for:Picking up exactly where you left off yesterdayclaude --resume (-r)
What it does:Opens the session picker (list) to choose from
Best for:Searching through a list to find which conversation it wasclaude --resume <name or id>
What it does:Opens by specifying the name, ID, or transcript path directly
Best for:When you have named it or have the ID noted down/resume (while running)
What it does:Switches to another conversation without exiting
Best for:When you want to "see that conversation" while working
Additionally, you can use claude --from-pr <number> to open a picker filtered only to "sessions associated with that pull request." This is useful when you want to return to the original context to address review comments.
If you are unsure which to use, you can decide by following this order:
It branches in three stages: "Is it running?" → "Is it the previous one?" → "Do you know the name?"
Returning to the previous conversation with --continue
This requires the fewest steps. The procedure is as follows:
Move to the directory where you were working last time (e.g., cd ~/work/taskboard).
Run claude --continue or claude -c.
The message history, tool execution results, and context of the previous session will be restored, so you can continue giving instructions as is.
# 前回のプロジェクトのディレクトリで実行する cd ~/work/taskboard claude --continue 短縮形。復元したうえで最初の指示まで一気に送ることもできる claude -c "テストが通るようになったか確認して"
There are four points to keep in mind here.
This targets the "most recently used session in the current directory." Even if you work on another project and return, the latest session within that specific directory will be selected.
Sessions created with claude -p (non-interactive mode) or the Agent SDK are not eligible for --continue. To return to these, specify the ID directly using claude --resume <session-id>. Conversely, claude -p --continue will pick up the latest session, including non-interactive ones.
Sessions where the initial prompt was /loop are also excluded from --continue.
If you have sent the previous conversation to the background and it is still running, --continue will display "Your most recent conversation is running in the background" and exit. Connect via claude agents or select a different session using --resume.
To test how it works, the following steps are simple.
Start with claude -n session-demo.
Send the message: "The password is 'blue notebook'. Please reply only with 'Understood'."
Exit with /exit, then run claude -c in the same directory.
Ask, "What was the password from earlier?" Confirm that the history is reloaded and the answer is provided.
The password is a short phrase for demonstration purposes. There is no need to use real sensitive information like actual passwords.
Selecting from a past list with --resume
When you are switching between multiple tasks, you may want to return to a conversation that wasn't the most recent one. That is where --resume comes in. Running it without arguments opens the session picker, which displays the session name (or a title auto-generated from the first prompt), time elapsed since the last update, Git branch, and file size for each entry.
# 一覧から選ぶ claude --resume 名前やIDで直接指定する claude --resume auth-fix claude -r 075c637d-54aa-4c5a-8d89-2e54ef7487c1
When you actually open /resume, you will see a list like the following. Here, the auth-fix created for the demo is displayed.
Here is a summary of the key operations frequently used in the picker.
↑ / ↓
Action:Navigate between sessionsEnter
Action:Resume the selected sessionSpace
Action:Preview contentAny character / /
Action:Enter search mode to filter (you can also paste a PR URL to search)Ctrl+R
Action:Rename the selected sessionCtrl+B
Action: Narrow down to sessions in the current Git branch onlyCtrl+W
Action: Display sessions for all worktrees in the same repositoryCtrl+A
Action: Display sessions for all projects on this machineEsc
Action: Exit the picker or search mode
When you select a session from another project using Ctrl+A, a command to cd into that directory and resume is copied to your clipboard. This is a precaution to prevent you from accidentally opening a session from an unrelated project in your current location.
Naming sessions turns your list into a "Work Board"You cannot memorize IDs. As the number of parallel tasks increases, the value of naming them grows. There are three times you can name a session.
At startup: claude -n auth-fix (--name)
While working: /rename auth-fix. The name is also displayed in the prompt bar
In the picker: Select the target and press Ctrl+R
Additionally, when you approve a plan in plan mode, if it doesn't have a name yet, a title based on the plan is automatically assigned.
Once you can recall sessions by name, the entire practice of keeping track of IDs becomes unnecessary.
Knowing the fine-grained behavior of name resolution will prevent confusion.
claude --resume <name>
Exact match: Resume immediately
When multiple exist with the same name: Opens a picker with the name as the search term/resume <name>
Exact match: Resume immediately
When multiple exist with the same name: Error. Run /resume without arguments to select one
If you try to assign a name that is already in use by a running session on the same machine, a two-word suffix like "auth-fix-graceful-unicorn" will be added to the one you just named. If you want to set it to your intended name, rename it again using /rename.
What is restored and what is not
If you assume that "resuming a session restores everything to how it was," you might get tripped up by permissions. Based on the official documentation, here is the breakdown.
Conversation history (including tool calls and results)
Handling upon resumption: Restored. However, tools that were running when the previous process ended will not be re-executed.Model
Handling upon resumption: Continues with the model used previously (exceptions apply, such as if the model is no longer available or if --model is specified).Agent (--agent)
Handling upon resumption: Continues as the same agent.Permission mode
Handling upon resumption: Using --continue / --resume <id> from the terminal or --resume <name> that matches uniquely will, in principle, restore the previous mode. However, if it ended with bypassPermissions and plan, it will revert to the default for a new session. It is not restored via the picker or /resume.Approvals granted with "Allow for this session only"
Handling upon resumption: Not restored.Startup flags such as --mcp-config, --settings, --plugin-dir, --add-dir
Handling upon resumption: Not restored. Add them again when resuming.Contents of settings.json / settings.local.json
Handling upon resumption: Reloaded at startup, so no specification is required.
The previous bypassPermissions is not automatically inherited upon resumption. However, if you have specified it again in the configuration file's defaultMode or via startup flags, that setting will be used. Since there are exceptions to the conditions for using auto and the default mode, please check the current mode on the screen after resuming.
Also, let's understand the behavior when opening a long session after a while. If you are on a Pro or Max plan and a session left idle for about an hour exceeds 100,000 tokens, a dialog will appear immediately after resuming asking whether to "resume from summary" or "read everything." Regardless of which you choose, the first request will process the entire history. Resuming from a summary makes subsequent requests lighter, but details omitted from the summary will disappear from the context. The decision criterion is "do you need every detail, or do you want to keep costs down?"
Branching conversations — /branch and --fork-session
Apart from resuming, there are times when you want to "use the conversation so far as a foundation to try a different approach." You don't want to break the original conversation, but you want to restart from the same context. The feature for this is /branch.
/branch try-streaming-approach
When executed, the conversation is copied, and you switch to a new session ID branch. The original session remains on disk, and you can return to it from the picker or via /resume <original name>. If you want to branch at startup, combine it with --fork-session, like claude --continue --fork-session.
What is copied here is the conversation. /branch alone does not duplicate project files or Git branches. Even if you return to the original conversation, files edited after branching will not automatically roll back. If you want to try different code as well, combine it with the worktree described in the next section.
As a note of caution, if you open the same session in two terminals without branching, both messages will be written alternately into a single transcript and mixed up. When you want to "work while looking at the same conversation in a different terminal," be sure to use /branch or --fork-session.
If you just want to clean up the context without crossing sessions, the following command applies.
/clear: Clear the context and start fresh. The previous conversation is saved, so you can return with /resume.
/compact [instruction]: Replaces history with a summary. You can specify the focus of the summary by adding an instruction.
/context: Displays what is currently occupying the context.
Parallel development with --worktree
From here on, we are talking about "advancing simultaneously" rather than "going back." If you launch Claude Code in two terminals for the same directory, they will both edit the same files, leading to conflicts. The --worktree (-w) option avoids this by using Git's worktree feature to create an isolated working directory and starting a session within it.
As a prerequisite, the target directory must be a Git repository. If you use version control other than Git, you will need to replace the creation and deletion logic using WorktreeCreate / WorktreeRemove hooks.
Basic stepsAt the root of the repository (the main checkout), launch the standard claude command once to complete the workspace trust verification. If this is not done, --worktree will stop with an error.
Run claude --worktree <name>. If you omit the name, a name like bright-running-fox will be automatically generated.
If you launch another instance in a different terminal with a different name, two sessions will proceed without touching each other's files.
# 機能開発用のworktreeでセッションを開始する claude --worktree feature-auth 別ターミナルで、バグ修正用のworktreeを開始する claude --worktree bugfix-123
The created directory and branch have the following structure.
<リポジトリのルート>/
└── .claude/
└── worktrees/
└── feature-auth/ # 隔離された作業ツリー(ブランチ: worktree-feature-auth)
Claude Code itself blocks operations from the worktree-side session that would rewrite the main side.
Since .claude/worktrees/ appears as a collection of untracked files from the main side, adding it to .gitignore will keep your git status clean.
How far does the isolation go?Even though it is "isolated," it is not just Claude Code running in a separate directory. According to the official documentation, the following four checks are always applied to sessions within a worktree (and sub-agents spawned from them):
Block if Edit / Write / NotebookEdit targets a path within the main checkout.
Block if the working directory for commands like Bash resolves to the main side or cannot be verified.
Block commands that point git to the main side using git -C or GIT_DIR, etc.
Block forms where it cannot be verified from the command string that git remains within the worktree (such as command names determined at runtime).
In other words, it is structurally difficult for "Claude to accidentally touch main." The fourth check cannot be turned off.
Setting up the worktree environmentSince a worktree is a new checkout, dependencies like node_modules and gitignored files like .env do not exist. You can ask Claude to "install dependencies" or run the setup yourself. If you want to automatically copy gitignored files like .env every time, place a .worktreeinclude file in the project root.
# .worktreeinclude(.gitignore と同じ書式。gitignoreされているファイルだけがコピーされる) .env .env.local config/secrets.json
When you end an interactive session with /exit, Claude Code checks for remaining work in the worktree (modified files, untracked files, new commits) and behaves as follows:
In the demonstration, I ran claude --worktree feature-auth -n worktree-demo and confirmed that .claude/worktrees/feature-auth and the worktree-feature-auth branch were created. At /exit, a prompt appeared asking whether to keep the named session, and I chose Keep worktree to finish.
Selecting "Delete" removes the directory, the branch, and the work within it. Committing within a worktree is not sufficient protection against deleting the entire branch. Please merge necessary changes into the original branch or push them to a remote to ensure they are backed up before deleting. I did not delete it in this demonstration.
Non-interactive execution with -p does not have an exit confirmation, so the worktree will remain. Manually delete it with git worktree remove; if it is locked and rejected, run git worktree unlock first.
Useful behaviors to knowReturning to the worktree when resuming: If you resume a session started within a worktree using --continue or --resume, you will return to that worktree. If the worktree has been deleted, it will continue in the directory where you launched it, and you will be notified accordingly.
Reusing the same name: If you pass an existing directory name to --worktree, it will open that worktree instead of creating a new one.
Changing the base branch: By default, a new worktree is created from the remote default branch (usually main). If you want to base it on your local unpushed commits, set "worktree": "baseRef": "head" in settings.json.
Creating from a PR: If you pass a PR number like claude --worktree "#1234", it will create .claude/worktrees/pr-1234 from the head of that PR. Quotes are required so the shell does not treat # as a comment.
Requesting during conversation: If you say "work in a worktree" during a session, Claude will create and move to a worktree using the EnterWorktree tool.
Approvals shared per repository: Bash permission rules selected with "Yes, and don't ask again" inside a worktree are saved to .claude/settings.local.json in the main checkout and apply to other worktrees as well (v2.1.211 and later).
Differences from Codex CLI
Even though both are "AI coding agent CLIs," OpenAI's Codex CLI has slightly different vocabulary and design for session management. Here is a comparison table for points that often confuse users of both.
Return to the previous conversation
Claude Code: claude --continue (-c)
Codex CLI: codex resume --lastSelect from a list
Claude Code: claude --resume (-r)
Codex CLI: codex resumeSpecify by name or ID
Claude Code: claude --resume <name id>
Codex CLI: codex resume <id name>Switch to another conversation while running
Claude Code: /resume
Codex CLI: /resumeAssign a name
Claude Code: -n, /rename, Ctrl+R in the picker
Codex CLI: /rename. Also check the command list in the running environmentBranch a conversation
Claude Code: /branch, --fork-session
Codex CLI: codex fork, codex fork --last, /forkExecute continuation non-interactively
Claude Code: claude -p --continue / -p --resume <id>
Codex CLI: codex exec resume --last / codex exec resume <id>Include sessions from other directories
Claude Code: Ctrl+A in the picker. ID specification searches the entire machine from v2.1.223 onwards
Codex CLI: --allNo persistence
Claude Code:-p with --no-session-persistence, or CLAUDE_CODE_SKIP_PROMPT_HISTORY
Codex CLI:codex exec --ephemeralSession cleanup
Claude Code:Automatic cleanup after 30 days by default, claude project purge
Codex CLI:codex archive / codex unarchive / codex deleteParallel development (worktree)
Claude Code:--worktree (-w). Defaults to under .claude/worktrees/
Codex CLI:Confirmed --worktree in local CLI 0.154.0. /worktree is also listed in the official command list. Desktop app management location is $CODEX_HOME/worktrees
Here are three differences in design philosophy that are not easily visible from the table alone.
1. How "previous" is handledClaude Code returns to the "previous state of this directory" using a dedicated flag called --continue. Codex consolidates the entry point into the resume subcommand, using --last with it. Both default to the current directory's session, and Codex can expand to other directories with --all.
2. Branching: "Session copy" or "Independent command"?Claude Code is designed to copy and branch a conversation with /branch, or by adding --fork-session to the resume flag at startup. Codex treats fork as an independent subcommand, using the same argument system as resume, such as codex fork --last. What you can achieve in practice is similar, and both share the point that the original conversation remains intact.
3. How to specify and locate worktreesIn Claude Code, you can specify a name like --worktree feature-auth; the default creation path is .claude/worktrees/feature-auth, and the branch name is worktree-feature-auth.
In Codex CLI 0.154.0, --worktree appeared in both local codex --help and codex resume --help. Since /worktree is also in the official developer command list, you do not need to assume it is "unavailable in the CLI" based on current explanations. Since the operation entry points differ between the CLI and the desktop app, check your local help.
Codex-managed worktrees for the desktop app are created under $CODEX_HOME/worktrees and usually start in a "detached HEAD" state, where no specific branch is checked out directly. There are also Handoff features to move work between Local and Worktree, and cleanup settings that keep the 15 most recent items by default.
.worktreeinclude appears in both official documents. However, the explanation on the Codex side targets worktrees managed by the local desktop app and does not guarantee the same behavior for manual git worktree add or remote worktrees in general. Please also check the official Codex Worktrees documentation.
Resuming by name is documented in the local codex resume --help as "Session id (UUID) or session name". When it is difficult to distinguish between sessions with the same name, using the ID can clarify the target.
Troubleshooting — The order to check when you cannot resume
When you get stuck with resuming, the places to check are determined by the symptoms.
Before searching for the error message, use this table to narrow down the cause.
No conversation found with session ID: ...
Potential causes:Wrong startup directory, typo in ID
Action:Run in the correct directory. From v2.1.223 onwards, other projects are also searched automatically. Also check for ID errors, retention periods, persistence suppression, and duplicates of manually copied identical IDs.Target conversation does not appear in picker or --continue
Potential causes:claude -p / SDK / sessions starting with /loop are hidden
Action:Specify the ID directly with claude --resume <session-id>The message "Your most recent conversation is running in the background" appears and it terminates
Possible cause:The previous conversation is running in the background
Solution:Connect via claude agents. If it is a different conversation, select it using --resumeFailed to resume the conversation
Possible cause:Failed to load the session
Solution:Execute the retry command displayed. If it fails within /resume, the current conversation will continue as isYour worktree <path> no longer exists
Possible cause:The worktree directory has been deleted
Solution:It will continue in the current directory. Note that isolation will not be effectiveCould not re-enter your worktree <path>
Possible cause:Started from inside the worktree, etc.
Solution:Restart from the main checkoutPermission mode has changed after resuming
Possible cause:bypassPermissions and plan are not restored by design
Solution:If necessary, resume with --permission-mode
Tips for practical use
How to combine these features assuming you are handling multiple projects alone. The recommended combination is as follows.
One session per task, always give it a name: If you start with claude -n <ticket-number-summary>, the picker will become your task list. You can filter branches with Ctrl+B, so it is easier to find them if you match the branch name with the session name.
"Continue from yesterday" with -c, "that thing from last week" with -r <name>: Follow the decision flow. Do not manage by keeping track of IDs.
Use /branch for discussing alternative approaches: Use worktree if you want to branch the conversation and edit code separately. Even if you return to the original conversation with /resume, file changes will not be reverted.
Use --worktree for parallel tasks, and push before finishing: Since deleting a worktree also deletes the branch, make it a habit to commit and push before finishing. Add .claude/worktrees/ to your .gitignore.
Decide whether to resume long-abandoned sessions from a summary: If you are handing over work where details are not needed, use summary resumption to save costs; if you need the history of detailed design decisions, read the full history.
Use /export or -p --resume for auditing or knowledge management: The latter is not just a command to read saved history, but an operation to send new requests to an existing conversation and execute them. Use /export for simple exports. It is safer not to write scripts that parse JSONL directly, assuming they will break with Claude Code updates.
Summary
Claude Code conversations are saved sequentially by session and remain as transcripts under ~/.claude/projects/.
To resume, choose in this order: /resume if running, --continue if it was the last one, --resume <nameid> if you know the name or ID, or --resume to see a list if you don't.
By using naming (-n / /rename) and branch filtering, the picker functions as a task board.
Use /branch to try a conversation with a different approach, and --worktree to proceed in parallel with separate files. Branching a conversation and isolating files are separate features.
Check the table for items not restored upon resumption (startup flags, session-specific approvals, certain permission modes) to prevent accidents.
Codex CLI provides equivalent operations with vocabulary like resume --last / fork / archive, and the CLI also has --worktree. While .worktreeinclude is in the documentation for both, check the scope of application before using it.
As a next step, understanding CLAUDE.md and the scope of configuration files (where to place them and what they affect) will ensure that instructions remain stable even in resumed sessions. Try organizing this alongside permission modes and sandboxes.
Reference Resources
Claude Code official documentation "Manage sessions": https://code.claude.com/docs/en/sessions
Claude Code official documentation "Run parallel sessions with worktrees": https://code.claude.com/docs/en/worktrees
Claude Code official documentation "CLI reference": https://code.claude.com/docs/en/cli-reference
OpenAI Codex "Developer commands" (resume / fork / exec resume / archive, etc.): https://developers.openai.com/codex/cli/reference
OpenAI Codex "Worktrees": https://developers.openai.com/codex/environments/git-worktrees
Commands verified locally: claude --version, claude --help, codex --version, codex --help, codex resume --help, codex fork --help
This article was verified against official documentation and CLI help on September 15, 2026, and the scope mentioned at the beginning was tested. Deletion, simultaneous editing of actual projects, and restoration of full permission modes were not demonstrated. Since both Claude Code and Codex are updated frequently, please compare version-dependent behavior (noted with version numbers in the text) with the --version of your execution environment.