feat: expose session_id in Stop hook input JSON
Resolved 💬 3 comments Opened Feb 28, 2026 by ppiankov Closed Mar 3, 2026
Problem
Stop hooks receive JSON input via stdin but it contains no session metadata. To build workflows that reference the current session (e.g., saving a resume command, logging session duration, linking sessions to external trackers), the hook must reverse-engineer the session ID by:
- Mapping
$PWDthroughsed 's|/|-|g'to find~/.claude/projects/<encoded-path>/ - Finding the most recently modified
.jsonlfile in that directory - Extracting the UUID from the filename
This is fragile because:
- The path encoding (
/→-) is undocumented - Claude Code maps to the git root, not
$PWD, so hooks running from subdirectories fail to find the project directory - Race conditions if multiple sessions exist for the same project
Proposed Solution
Include session_id (and optionally project_dir) in the Stop hook's stdin JSON:
{
"session_id": "c45e6165-b736-44b9-93f1-b0cbe12e9ddf",
"project_dir": "/Users/user/dev/my-project",
"stop_hook_active": false
}
This would make Stop hooks like "save resume command" or "log session" trivial to implement without relying on undocumented internals.
Current Workaround
work_dir=$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD")
project_dir="$HOME/.claude/projects/$(echo "$work_dir" | sed 's|/|-|g')"
session_file=$(ls -t "$project_dir"/*.jsonl 2>/dev/null | head -1)
session_id=$(basename "$session_file" .jsonl)This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗