Skip to content

fix: session-end.js produces empty output because SessionEnd hook doesn't provide transcript_path #331

@shen542973499-alt

Description

@shen542973499-alt

Bug

Session files in ~/.claude/sessions/ always contain the empty placeholder [Session context goes here] instead of real session content.

Root Cause

session-end.js reads transcript_path from the hook's stdin JSON payload to parse the JSONL transcript. However, it is registered under the SessionEnd hook, which does not provide transcript_path in its payload.

Only the Stop hook provides transcript_path. So session-end.js always receives null for transcript_path and falls back to writing the empty template.

Fix

Move session-end.js from SessionEnd to Stop hook in hooks/hooks.json:

"Stop": [
  { ... },
  {
    "matcher": "*",
    "hooks": [{
      "type": "command",
      "command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/hooks/session-end.js\"",
      "async": true,
      "timeout": 10
    }],
    "description": "Persist session state after each response (Stop hook has transcript_path)"
  }
],
"SessionEnd": [
  {
    "matcher": "*",
    "hooks": [{
      "type": "command",
      "command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/hooks/evaluate-session.js\""
    }],
    "description": "Evaluate session for extractable patterns"
  }
]
No changes needed to session-end.js itself — the script logic is correct, only the hook registration is wrong.

Verified
After moving to Stop hook, session files correctly capture user messages, tools used, and modified files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcodexFlagged for Codex pickup

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions