⌨️CLAUDE_CODE_SESSION_ID
Also known as $CLAUDE_CODE_SESSION_ID
It holds the current session's id, for scripts and hooks.
Think of it like
It is like the ticket you get when you wait in line at a shop.
Example
Lucy's hook writes a log line for each edit. Adding the session id lets her group the lines by chat later.
Why it matters
With several sessions running, the id is how you tell their logs apart.
Definition
Example code
bash
echo "$(date) $CLAUDE_CODE_SESSION_ID done" >> ~/sessions.logCommon mistake
Key takeaways
- 1Current session id. Set for you.
- 2Matches hook input. session_id.
- 3Changes on /clear. Not for MCP.