You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request] Add session ID retrieval command for interactive sessions #1407
Currently, there's no straightforward way to retrieve a session ID from an active Claude Code session, which severely limits the utility of the claude -r "<session-id>" resume command. Users need the session ID to resume conversations later, but have no way to obtain it during an interactive session.
Problem: Without access to the session ID, the resume functionality becomes nearly impossible to use effectively, especially for long-running projects where you might want to return to a specific session days or weeks later.
Proposed Solutions:
Add session ID to interactive commands: Introduce a new command (e.g., /session) or extend the existing /status command to display the current session ID during an active Claude Code session.
Enhance the session list view: Include the session ID as a column in the claude -r table output, making it easy to copy and reference for future use.
These changes would make session management much more practical and allow developers to effectively pause and resume their work across multiple sessions.
Reacted by Dmitry Persiyanov, ronnyli, Paul Mcilreavy, matthew p robertson, Mark Rieck, amirshawn, Simon Leischnig, Alex Brinsmead, durapensa, taiga.koda and 22 more
I found this trying to figure out how to get the session ID after Claude Code - Opus started wildly underperforming after some server overloaded error messages. I think the server side context got reset, without that having been made obvious on the client. So now I'm trying to figure out how to recover from that situation in the future. Same for when the local claude process crashes while compacting its context.
Related to the session identification challenges discussed here, I've created #2112 proposing a --session-name feature that would allow users to assign custom names to sessions.
This would complement the session ID retrieval functionality by making sessions human-readable and easier to identify in the --resume picker.
Other related issues addressing session management:
Thanks @bcherny, though in the latest version I see this when I do /status:
Claude Code Status v1.0.30
L Session ID: 764c8585-3aba-4adb-bf16-...
... which does give some way to get at the session id manually. And while that is helpful, but still is limiting because only (from what I can see) only a real user can get at the session ID†.
What I'm looking and hoping for is a way to make custom commands (or manually provided prompts) get at the session ID so that we can "agentically" chain one claude execution to another. For example, have one claude process, kicked off in interactive mode or with -p do some work and then paste a command to the user (or automatically run) which will resume after some long wait.
So now I can manually copy the session id, close the current instance of claude code, and then write a command like:
./wait-until-build-finishes.sh && claude --resume <copied session id> -p "Build finished, use MCP to get status. If it failed try and fix and push the changes. If it succeeded merge the pr with gh cli"
... but I can't (very easily) do something like:
claude -p "/pr-and-write-session-id-to-file /tmp/work1.txt" && ./wait-for-build && claude --resume $(cat /tmp/work1.txt) --p "/merge-or-try-and-fix-build"
# Where /pr-and-write-session-id-to-file and /merge-or-try-and-fix-build are custom slash commands I've created
ps: I know there is the streaming output, but that is tricky to work with, especially when you want to using interactive mode most of the time. Though maybe there is a way to write a slash command that writes to look at the ~/.claude/projects/<project>/ folder to see if it can find the session id 🤔
†: Here was may attempt to "agentically" get at the session ID (that didn't succeed):
> Get the current session Id and write it to /tmp/test.txt
⏺ I'll get the current session ID and write it to /tmp/test.txt.
⏺ Bash(echo $ANTHROPIC_SESSION_ID > /tmp/test.txt)
⎿ (No content)
⏺ Read(../../../../../tmp/test.txt)
⎿ Read 2 lines (ctrl+r to expand)
⏺ The session ID appears to be empty. Let me check what environment variables are available and
try a different approach:
⏺ Bash(env | grep -i session || echo "No session variables found")
⎿ SECURITYSESSIONID=YYY
WARP_IS_LOCAL_SHELL_SESSION=1
⏺ Bash(echo "Session ID not available in environment variables" > /tmp/test.txt)
⎿ No (tell Claude what to do differently)
> Use the status slash command to get the current session id
⏺ Bash(/status)
⎿ Error: (eval):1: no such file or directory: /status
⏺ Let me try the status command differently:
⏺ Bash(status)
⎿ Error: (eval):1: command not found: status
⏺ It seems the status command isn't available as a shell command. The session ID might need to
be obtained through a different method, or it may not be accessible in this environment. Would
you like me to try a different approach to get session information?
This is what I am/was using to get to the session id :-) .
------------
> I want you to find the current session id. One idea is to look in ~/.claude and look for a unique characteristic of this
session. For exampe call the uuidgen program - find its output and then look for session jsonl (in the corresponding
~/.claude/projects/<encoded_cwd>/.. whose tail|grep has that string...
⏺ I'll help you find the current session ID by generating a unique identifier and then searching for it in the Claude session
files.
⏺ Bash(uuidgen)
⎿ FC2638E0-D228-4DE2-8CF1-7668EE726523
⏺ Now let me search for session files in the ~/.claude directory:
........
⏺ Found it! The current session ID is 69420655-04d6-4eb4-87e6-9f62741fb8cd.
.......
⏺ The current session ID is 69420655-04d6-4eb4-87e6-9f62741fb8cd
------------
and from the newly released /status
Claude Code Status v1.0.31
L Session ID: 69420655-04d6-4eb4-87e6-9f62741fb8cd
I have similar use case as @timmfin - not sure how I could use the /status command . I am recording session ids with PRs locally so as when things comes back (from jenkins/PR reviewer comments/ sentry errors post release - ) I can go from PR=> session id and launch an interactive session --resume the original one with additional pasted [user] input whatever are the complaints and have claude code give it first a try - and if it can finish up by itself again the ci/cd. Still , the info is up there in .claude/ - so with some hack like what I am describing above... its not difficult to get the session id.
In case anyone finds this usefull this is how my scripts currently work:
ithaca:test odysseas$ alias myclaude='claude "please run uuidgen and then save_claude_vars --add_session_by_unique_string <uuidgen output>. Both save_claude_vars and uuidgen are in your path"'
thaca:test odysseas$ myclaude
╭───────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: /Users/odysseas/test │
╰───────────────────────────────────────────────────╯
※ Tip: Did you know you can drag and drop image files into your terminal?
> please run uuidgen and then save_claude_vars --add_session_by_unique_string <uuidgen output>. Both
save_claude_vars and uuidgen are in your path
⏺ I'll run uuidgen to generate a UUID and then save it using save_claude_vars.
⏺ Bash(uuidgen)
⎿ FC7DCA21-1676-42D2-A3CC-AD25249902F0
⏺ Bash(save_claude_vars --add_session_by_unique_string FC7DCA21-1676-42D2-A3CC-AD25249902F0)
⎿ Session info saved for: 29f62c4c-9590-485e-8d8e-6c641f90592d
Claude PID: 57860
Terminal: 2B7F2A7E-C963-40C4-840E-7E5631853568
… +2 lines (ctrl+r to expand)
⏺ Done. Session saved with UUID FC7DCA21-1676-42D2-A3CC-AD25249902F0.
> /exit
ithaca:test odysseas$ grep -rl '18DC93BA-1E29-4888-83D9-2641ABE8F3C2' ~/.claude/recorded_sessions/
/Users/odysseas/.claude/recorded_sessions/9458d1f0-d62e-43a2-9606-cb479b037f5d.jsonl
ithaca:test odysseas$
It looks like a (volatile) workaround might be to just read the ~/.claude/projects/-workspace/*.jsonl files after starting a new Claude session, and assume the newest file is the new session ID.
It also looks like resuming a session is considered a new session with a new session ID (more like a fork), so if you want to resume the resumed session, you need the new session ID.
$ claude -p "Hello"
Hello! I'm here to help you with your video messaging application project. What would you like to work on today?
$ ls -t ~/.claude/projects/-workspace | head -n 1
27900125-3315-4d0a-a049-e6a8fd6ae4e2.jsonl
$ claude -r 27900125-3315-4d0a-a049-e6a8fd6ae4e2 -p "What was my previous message, verbatim?"
Your previous message was:
"Hello"
$ ls -t ~/.claude/projects/-workspace | head -n 1
55ace50a-73f9-4cc0-8ed0-d2f2523288b8.jsonl # <= NOTE: new session ID
$ claude -r 55ace50a-73f9-4cc0-8ed0-d2f2523288b8
> Hello
● Hello! I'm ready to help you with your video messaging application project. What would you like to work on today?
> What was my previous message, verbatim?
● Your previous message was:
"Hello"
>
$ claude -r 27900125-3315-4d0a-a049-e6a8fd6ae4e2
> Hello
● Hello! I'm ready to help you with your video messaging application project. What would you like to work on today?
>
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.
Activity
JoshHeitzman commentedon Jun 9, 2025
+1 for adding the session id to /status
I found this trying to figure out how to get the session ID after Claude Code - Opus started wildly underperforming after some server overloaded error messages. I think the server side context got reset, without that having been made obvious on the client. So now I'm trying to figure out how to recover from that situation in the future. Same for when the local claude process crashes while compacting its context.
gwpl commentedon Jun 15, 2025
Related to the session identification challenges discussed here, I've created #2112 proposing a
--session-namefeature that would allow users to assign custom names to sessions.This would complement the session ID retrieval functionality by making sessions human-readable and easier to identify in the
--resumepicker.Other related issues addressing session management:
bcherny commentedon Jun 18, 2025
Shipping in tomorrow's release!
timmfin commentedon Jun 20, 2025
Thanks @bcherny, though in the latest version I see this when I do
/status:... which does give some way to get at the session id manually. And while that is helpful, but still is limiting because only (from what I can see) only a real user can get at the session ID†.
What I'm looking and hoping for is a way to make custom commands (or manually provided prompts) get at the session ID so that we can "agentically" chain one claude execution to another. For example, have one claude process, kicked off in interactive mode or with -p do some work and then paste a command to the user (or automatically run) which will resume after some long wait.
So now I can manually copy the session id, close the current instance of claude code, and then write a command like:
... but I can't (very easily) do something like:
ps: I know there is the streaming output, but that is tricky to work with, especially when you want to using interactive mode most of the time. Though maybe there is a way to write a slash command that writes to look at the
~/.claude/projects/<project>/folder to see if it can find the session id 🤔†: Here was may attempt to "agentically" get at the session ID (that didn't succeed):
ogt commentedon Jun 21, 2025
This is what I am/was using to get to the session id :-) .
I have similar use case as @timmfin - not sure how I could use the /status command . I am recording session ids with PRs locally so as when things comes back (from jenkins/PR reviewer comments/ sentry errors post release - ) I can go from PR=> session id and launch an interactive session --resume the original one with additional pasted [user] input whatever are the complaints and have claude code give it first a try - and if it can finish up by itself again the ci/cd. Still , the info is up there in .claude/ - so with some hack like what I am describing above... its not difficult to get the session id.
PS. @bcherny you are awesome 🤩
ogt commentedon Jun 23, 2025
In case anyone finds this usefull this is how my scripts currently work:
save_claude_vars
colllin commentedon Jul 10, 2025
It looks like a (volatile) workaround might be to just read the
~/.claude/projects/-workspace/*.jsonlfiles after starting a new Claude session, and assume the newest file is the new session ID.It also looks like resuming a session is considered a new session with a new session ID (more like a fork), so if you want to resume the resumed session, you need the new session ID.
kym6464 commentedon Jul 13, 2025
I built a little tool to solve the "session retrieval" problem for myself: https://github.com/kym6464/claude-code-tools
gregor-RW commentedon Jul 18, 2025
Copying from another issue => #1335
Running --output-format json we get:
github-actions commentedon Jul 30, 2025
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.