AI-101

Lesson 7

Session Management

AI Confidence: 90%

AI-generated

Session Management

Learning Objectives

Resume previous conversations with /resume and command-line flags

Name sessions for easy retrieval later

Fork conversations at decision points with /branch

Export conversations for sharing or documentation

Manage multiple sessions across different tasks

Introduction

Claude Code saves your conversations automatically. When you exit, your session is stored locally. When you return, you can pick up exactly where you left off. This is powerful for tasks that span multiple work periods.

But saved sessions are only useful if you can find them again. This lesson covers how to name sessions, resume them, fork them when you want to explore alternatives, and export them when you need to share what happened.

Good session management means you never lose work and always know where to find past conversations.

Resuming Sessions

When you start Claude Code with the claude command, you begin a fresh session. But often you want to continue previous work.

Continue the most recent session:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

This opens the last session you had in the current directory. No picker, no selection. Just straight back to where you were.

Resume any session:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

This opens a picker showing your recent sessions. Use arrow keys to navigate and Enter to select. Sessions are grouped by project and show metadata like the time elapsed, message count, and git branch.

Resume by name:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

If you named your session, you can resume it directly by name.

From inside Claude Code:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

This opens the same picker while Claude Code is running. You can switch from one session to another mid-work.

Sessions are stored per project directory. The picker shows sessions from the same Git repository, including worktrees. Sessions created in non-interactive mode (with claude -p) do not appear in the picker, but you can still resume them if you have the session ID.

Naming Sessions

Named sessions are much easier to find than unnamed ones. The picker shows unnamed sessions by their first message, which is not always helpful.

Name a session at startup:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

The -n flag sets the name when you start.

Name during a session:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

This names the current session and shows the name on the prompt bar.

Auto-generate a name:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Running /rename without a name auto-generates one from your conversation history.

Rename from the picker:

When using /resume, navigate to any session and press R to rename it.

Good naming practices:

Use descriptive names like payment-bug-fix or new-api-endpoints

Include the date if you have multiple sessions on the same topic

Use consistent naming so you can search across sessions

Forking Conversations

Sometimes you reach a decision point. You could refactor one way or another. You want to try both approaches without losing either.

The /branch command (alias /fork) creates a copy of your conversation at the current point:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

You now have two sessions with identical history up to this point. Changes in one do not affect the other.

When to fork:

Trying different implementation approaches

Exploring a risky change you might want to undo

Splitting a large task into parallel workstreams

Forked sessions appear grouped together in the /resume picker under their root session. This makes it easy to see which sessions are related.

Note that /branch only forks the conversation. It does not create a Git branch or copy your code. The code on disk is shared. If you need code isolation too, look into Git worktrees (covered in a later lesson).

Exporting Conversations

Sometimes you need to save a conversation outside of Claude Code. Maybe you want to share it with a colleague, add it to documentation, or keep a record.

Export to clipboard or file:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

This opens a dialog where you can copy the conversation to your clipboard or save it to a file.

Export directly to a file:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

This writes the conversation as plain text to the specified file.

Exported conversations include your messages and Claude's responses in readable format. They do not include internal tool calls or intermediate steps unless you exported from verbose mode.

When to export:

Documenting how you solved a problem

Sharing a solution with teammates

Creating a record before clearing context

Saving a conversation for later reference

Session Picker Features

The /resume picker has several useful features:

Keyboard shortcuts in the picker:

| Key | Action |

|-----|--------|

| Up/Down arrows | Navigate between sessions |

| Left/Right arrows | Expand or collapse grouped sessions |

| Enter | Resume the selected session |

| P | Preview the session content |

| R | Rename the selected session |

| / | Search to filter sessions |

| A | Toggle between current directory and all projects |

| B | Filter to sessions from your current git branch |

| Escape | Exit the picker |

Preview before resuming:

Press P on any session to see its content before resuming. This helps when session names are not descriptive enough.

Search across sessions:

Press / in the picker to enter search mode. Type keywords to filter sessions.

Branch filtering:

Press B to show only sessions from your current Git branch. This is useful in repositories with many branches.

Practical Session Patterns

Here are workflows that make session management effective:

Name as you go. When you start a significant task, immediately run /rename with a descriptive name. This takes two seconds and saves time later.

One task, one session. Avoid mixing unrelated tasks in one session. Start fresh or resume the relevant session for each task.

Fork before experimenting. When trying something risky, /branch first. If the experiment fails, you have the original to return to.

Export before clearing. If a session contains valuable information you might need later, /export before /clear.

Use command-line flags. claude --continue for quick resumption of recent work. claude --resume name for specific sessions. These save time compared to using the picker.

Key Takeaways

Sessions are saved automatically and can be resumed with /resume or --continue

Name sessions with /rename or -n for easy retrieval

Fork sessions with /branch to try different approaches

Export sessions with /export to save or share them

The session picker supports preview, search, rename, and filtering

Good session management means you never lose work

Try It Yourself

Practice session management with these steps:

Start Claude Code with claude.

Ask a few questions to build some history.

Run /rename practice-session to name it.

Type exit to end the session.

Run claude --resume practice-session to return directly.

Run /branch to fork the conversation.

Run /resume and notice how the forked session appears grouped.

Run /export session-log.txt to save the conversation.

Check the exported file to see what it contains.

This exercise demonstrates the full session management workflow.

Sources

https://code.claude.com/docs/en/common-workflows - Session resumption, naming, and practical patterns

https://code.claude.com/docs/en/cli-reference - Command-line flags for --continue, --resume, -n

https://code.claude.com/docs/en/commands - /rename, /branch, /export, /resume commands