[Feature Request] Add session ID retrieval command for interactive sessions
Status Fixed / completed
Maintainer reply ✓ Yes — bcherny
Workaround ✓ Mentioned in thread ↓
Activity 10 comments · opened May 29, 2025 · closed Jun 17, 2025
💡 Likely answer: A maintainer (bcherny, collaborator)
responded on this thread — see the highlighted reply below.
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/statuscommand 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 -rtable 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.
Related to #1335
10 Comments
+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.
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:
Shipping in tomorrow's release!
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):
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 🤩
In case anyone finds this usefull this is how my scripts currently work:
save_claude_vars
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.
I built a little tool to solve the "session retrieval" problem for myself: https://github.com/kym6464/claude-code-tools
Copying from another issue => https://github.com/anthropics/claude-code/issues/1335
Running --output-format json we get:
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.