Skip to content

Windows: History system hooks fail silently due to path handling #357

Description

@alexandru-savinov

Bug Description

The history system hooks (stop-hook.ts and subagent-stop-hook.ts) fail silently on Windows because transcript paths aren't normalized for cross-platform compatibility.

Environment

  • OS: Windows 10/11
  • PAI Version: Latest (cloned 2026-01-09)
  • Platform: Claude Code with Bun runtime

Expected Behavior

When a session ends, stop-hook.ts should capture the session/learning to the appropriate markdown file in $PAI_DIR/history/sessions/ or $PAI_DIR/history/learnings/.

Actual Behavior

The hook exits silently without creating any files. The extractResponseFromTranscript() function fails to find the transcript file because the Windows path (with backslashes) isn't being normalized.

Root Cause

The transcript_path received from Claude Code contains Windows-style paths (e.g., C:\Users\...), but the hooks pass this directly to existsSync() and readFileSync() without normalizing.

In stop-hook.ts line ~134:

response = extractResponseFromTranscript(payload.transcript_path) || undefined;

Should be:

const normalizedPath = normalize(payload.transcript_path);
response = extractResponseFromTranscript(normalizedPath) || undefined;

Fix

  1. Add normalize to the path imports
  2. Normalize the transcript_path before using it

Affected files:

  • Packs/pai-history-system/src/stop-hook.ts
  • Packs/pai-history-system/src/subagent-stop-hook.ts

Verification

After applying the fix:

  • Raw event capture works ✅ (was already working)
  • Session/learning capture works ✅ (now fixed)
  • Subagent routing works ✅ (now fixed)

Additional Context

The capture-all-events.ts hook works correctly because it only writes to files (doesn't read transcript paths). The bug specifically affects hooks that need to read the transcript file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions