Feature request: expose session identifier to hooks (for channel plugin integration)

Resolved 💬 3 comments Opened Mar 25, 2026 by chsm04 Closed Mar 29, 2026

Context

I built a local Channel plugin called Pulse that lets background processes (CI, build scripts, deploy hooks, cron) send notifications directly into a Claude Code session via HTTP POST — no external messengers needed.

https://github.com/user-attachments/assets/7bf4442e-8be9-4a6b-bfa0-b6dd4d41245e

Problem

For hooks (e.g. PostToolUse) to send notifications to the correct Pulse instance, they need to identify which Claude Code session they belong to. Currently:

  • CLAUDE_CODE_SSE_PORT is not set in hook environments (even with --dangerously-load-development-channels)
  • PPID differs between the MCP plugin process and hook processes
  • No other session-unique identifier is available to hooks

Current workaround

Both the Pulse MCP server and hooks walk the process tree to find the ancestor claude process PID, using that as a shared session key:

# In hook scripts
find_claude_pid() {
  local pid=$PPID
  while [ "$pid" -gt 1 ]; do
    local comm=$(ps -p "$pid" -o comm= 2>/dev/null)
    if [ "$comm" = "claude" ]; then echo "$pid"; return 0; fi
    pid=$(ps -p "$pid" -o ppid= 2>/dev/null | tr -d ' ')
  done
  return 1
}

This works but is fragile — it depends on the process name being exactly claude and requires platform-specific process tree traversal.

Proposal

Expose a session-unique identifier as an environment variable (e.g. CLAUDE_SESSION_ID or reuse CLAUDE_CODE_SSE_PORT) in hook execution environments. This would enable:

  • Channel plugins to reliably identify their session
  • Hooks to communicate with session-specific services
  • Cleaner session-aware tooling without process tree hacks

Related

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗