# Claude Code session ID: how to find the current one and past ones

Find your Claude Code session ID: echo $CLAUDE_CODE_SESSION_ID, the status line or a hook. Past IDs live in ~/.claude/projects; /status does not show it.

Source: https://hivemux.dev/guides/claude-code-session-id/

> Ask Claude to run `echo $CLAUDE_CODE_SESSION_ID`, which Claude Code sets to the current session ID in every Bash command it runs, or show `session_id` in your status line. Past IDs are the file names in `~/.claude/projects/<project>/<session-id>.jsonl`; the newest file is the one used last. Resume one with `claude --resume <id>`, or run `claude --resume` to pick from a list.

Every Claude Code conversation has a session ID: a UUID such as `550e8400-e29b-41d4-a716-446655440000`. You need it to reopen a specific conversation with `claude --resume <id>`, to continue one from a script, or to find its transcript on disk. Claude Code does not print the ID on the normal screen, and `/status` does not show it either (it shows the version, model, account and connectivity), so this page lists every way to get it: for the session you are in now, and for sessions that already ended.

## How to get the current session ID

### Ask Claude (quickest)

Claude Code sets the environment variable `CLAUDE_CODE_SESSION_ID` to the current session ID in every Bash command it runs. So in the session you want the ID of, ask:

```text
run echo $CLAUDE_CODE_SESSION_ID
```

The same variable is set for hook commands, so your own scripts can read it too. It follows `/clear`, which starts a new session with a new ID. (A stdio MCP server also gets it, but keeps the ID it was started with.)

### Show it in the status line

The status line command receives the session data as JSON on stdin, including `session_id` and, once the session has a name or generated title, `session_name`. To keep the ID visible at the bottom of every session, add this to `~/.claude/settings.json`:

```json
{
  "statusLine": {
    "type": "command",
    "command": "jq -r '.session_id'"
  }
}
```

This needs `jq`. If you already have a status line script, print `.session_id` from it instead of replacing it.

### Read it in a hook

Every hook event's JSON input has `session_id`, `transcript_path` and `cwd`. A `SessionStart` hook that writes them somewhere is the way to record the ID of every session as it starts, which is what hivemux does (below).

### Other places that print it

- `/branch` prints two session IDs: the new branch you are now in and the original.
- `claude -p --output-format json "<prompt>"` returns the session ID of the run in its JSON.
- `claude --bg "<task>"` prints the ID of the background session it starts.

## How to find past session IDs

Claude Code saves each conversation as a JSON Lines file named after its session ID, in a folder per project:

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

`<project>` is the working directory the session was started in, with every character that is not a letter or digit replaced by `-` (very long paths, over 200 characters, are cut short with a hash added). A session started in `/Users/me/code/api` lives in:

```
~/.claude/projects/-Users-me-code-api/
```

So the IDs of past sessions in a folder are the file names there, and the most recently used one is usually the most recently modified file:

```sh
ls -t ~/.claude/projects/-Users-me-code-api/*.jsonl | head -1
```

If several sessions ran in the same folder at once, the newest file is simply the one written last, so match it by time or content before relying on it. Sessions run with `claude -p` or the Agent SDK are saved in the same folder too. You can also skip the ID and pass the file itself: `claude --resume ~/.claude/projects/-Users-me-code-api/<id>.jsonl`. Transcripts are kept for 30 days by default (`cleanupPeriodDays` in settings).

You often do not need the ID at all. `claude --resume` with no argument opens a picker that lists sessions by name or generated title; type to search, `Ctrl+B` filters by git branch, and pasting a pull request URL finds the session that made it. Select one and press Enter.

## Resume by ID, by name, or from the picker

```sh
claude --resume 550e8400-e29b-41d4-a716-446655440000   # exact session, from any folder
claude --resume login-bug                               # by name
claude --resume                                         # picker: searchable
claude --continue                                       # latest session in this folder
```

With an ID, `--resume` looks in the current project and its worktrees first, then in every other project on the computer (when exactly one of them has that ID), so you do not have to `cd` to the right folder. `--continue` only looks in the current folder, and skips sessions run with `claude -p` or the Agent SDK. More on everyday resuming in [How to resume a Claude Code session](/guides/resume-claude-code-sessions/).

Names are easier to remember than UUIDs. Start a session with `claude -n login-bug`, or type `/rename login-bug` inside it, and the name shows in the prompt bar, the terminal title and the picker. Names do not replace the ID; both point at the same transcript.

| | Session ID | Session name |
|---|---|---|
| Who sets it | Claude Code, at start (or you, with `--session-id`) | you, with `-n`, `/rename` or `Ctrl+R` in the picker (`/rename` alone makes one up) |
| Changes | never (a new session gets a new one) | whenever you rename |
| Resume with | `claude --resume <id>` | `claude --resume <name>` |
| Shown | transcript file name, `$CLAUDE_CODE_SESSION_ID`, hook and status line input | prompt bar, terminal title, picker |

Two flags for scripts: `--session-id <uuid>` starts a session with an ID you choose, and `--fork-session` resumes into a *new* ID so the original transcript stays as it was.

## Record every session's ID with a hook

Because every hook gets `session_id` and `cwd`, a `SessionStart` hook can note each session's ID the moment it starts. That is exactly what hivemux does.

hivemux is a tmux sidebar that shows every Claude Code session — running, waiting for you, or done — and lets you jump to the one that needs you. Its hook writes the ID onto the tmux pane the session runs in:

```sh
tmux show -pv @claude_session      # in that pane: the session ID
tmux show -pv @claude_cwd          # the folder it was started in
hivemux-panes list                 # every pane with its session, as saved for the next restore
```

That pane-to-ID list is what lets hivemux type `claude --resume <id>` in every pane after a reboot, and bring every session back after you [clock out for the night](/guides/stop-claude-code-overnight/). The hook itself is explained in [Claude Code hooks in practice](/guides/claude-code-hooks-example/).

```sh
curl -fsSL https://hivemux.dev/install.sh | bash
```

## FAQ

### How do I get the ID of the session I am in right now?

Ask Claude to run `echo $CLAUDE_CODE_SESSION_ID`. Claude Code sets that variable to the current session ID in the Bash commands it runs and in hook commands. To see it all the time, add `session_id` to a status line script.

### How do I find the ID of a past session?

List the transcripts of the folder it ran in, `ls -t ~/.claude/projects/<project>/*.jsonl`, where `<project>` is the folder path with non-alphanumeric characters replaced by `-`. Each file name is a session ID, newest first. You can also skip the ID and pick the session from `claude --resume`.

### Why did my session ID change after /clear?

`/clear` starts a new conversation, and a new conversation is a new session with its own ID. The previous one stays on disk; `/resume` brings it back.

### Can I choose the session ID myself?

Yes. `claude --session-id <uuid>` starts a session with the ID you give; it must be a valid UUID. This is useful for scripts that start and later resume the same conversation.

### What is the difference between a session ID and a session name?

The ID is a UUID Claude Code assigns and never changes. The name is a label you set with `claude -n <name>` or `/rename` inside the session; it shows in the prompt bar, the terminal title and the `--resume` picker, and `claude --resume <name>` finds it.

### Does resuming a session keep its ID?

Yes, `--resume` and `--continue` reuse the original ID and append to the same transcript. Add `--fork-session` to get a new ID and a copy of the conversation, for example to try two approaches from the same point.

### How does hivemux know which session was in which tmux pane?

Claude Code's SessionStart hook sends the session ID and the working directory to the hook command. hivemux writes both onto the tmux pane as `@claude_session` and `@claude_cwd`, saves the list whenever tmux-resurrect saves, and types `claude --resume <id>` in each pane after a reboot.
