Skip to content

feat: use transcript_path from hook payload directly instead of current-session detection #33

@junaidtitan

Description

@junaidtitan

Feature

Every Claude Code hook payload includes transcript_path: "/absolute/path/to/session.jsonl" — the exact path to the current session file. Cozempic currently ignores this and runs find_current_session() which uses 4 heuristic detection strategies (lsof, text-snippet, CWD slug, mtime fallback).

Why

  • Hook-provided path is always authoritative — no detection needed
  • find_current_session() can fail in edge cases (multiple Claude processes, non-standard installs, race conditions)
  • Simplifies guard startup: cozempic guard --transcript-path <path> instead of --session <id> + detection

Hook payload (from Claude Code source)

{
  "session_id": "uuid",
  "transcript_path": "/Users/name/.claude/projects/-Users-name-project/uuid.jsonl",
  "cwd": "/Users/name/project",
  "permission_mode": "default",
  "agent_id": "..."  
}

All events: SessionStart, PreCompact, PostCompact, Stop, SubagentStop, PostToolUse — all include transcript_path.

Implementation

  1. Update hooks.json to pass transcript_path from stdin JSON to the cozempic commands
  2. Add --transcript-path flag to cozempic guard and cozempic checkpoint
  3. When --transcript-path is provided, skip find_current_session() entirely
  4. Keep detection as fallback for CLI use (when running cozempic treat manually)

Impact

More reliable hook operation. Eliminates the entire class of "could not detect current session" failures in hook contexts.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions