Skip to content

Pass client_id in session-start hook for event bus session resumption #93

Description

@evansenter

Context

PR evansenter/agent-event-bus#30 renamed pid to client_id and changed the deduplication key from (machine, cwd, pid) to (machine, client_id). This enables session resumption when a stable identifier is passed.

Current State

The session-start hook (~/.claude/hooks/session-start.sh) prompts Claude to register with only name and cwd:

Register with event bus: mcp__event-bus__register_session(name: "$SESSION_NAME", cwd: "$CWD")

This means every registration creates a new session (no deduplication).

Proposed Change

The hook already receives session_id from Claude Code in the input JSON. Pass it as client_id:

SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // ""')

# In output:
Register with event bus: mcp__event-bus__register_session(name: "$SESSION_NAME", cwd: "$CWD", client_id: "$SESSION_ID")

Benefits

  • Sessions can resume across context reloads within the same CC conversation
  • list_sessions won't show duplicate entries for the same conversation
  • Event polling with last_event_id works correctly on session resume

Notes

  • If session_id is empty/unavailable, fall back to no client_id (current behavior)
  • The CC session_id should persist within a conversation, enabling resumption

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions