Skip to content

fix: normalize path slashes in PostToolUse hook to prevent session_id write failure#68

Merged
SihaoLiu merged 2 commits intoPolyArch:devfrom
gyy0592:fix/session-id-double-slash
Apr 13, 2026
Merged

fix: normalize path slashes in PostToolUse hook to prevent session_id write failure#68
SihaoLiu merged 2 commits intoPolyArch:devfrom
gyy0592:fix/session-id-double-slash

Conversation

@gyy0592
Copy link
Copy Markdown

@gyy0592 gyy0592 commented Apr 4, 2026

Summary

  • Normalize consecutive slashes (///) in HOOK_COMMAND and COMMAND_SIGNATURE before the boundary-aware string match in loop-post-bash-hook.sh
  • Fixes a bug where session_id is never written to state.md, causing cross-instance stop hook hijacking when multiple Claude Code sessions run concurrently
  • Root cause: CLAUDE_PLUGIN_ROOT may have a trailing slash, producing double slashes in the command string, while the setup script normalizes its path via cd+pwd — the strict string comparison always fails

Root Cause Detail

  1. CLAUDE_PLUGIN_ROOT = .../marketplaces/humania/ (trailing /)
  2. Command template: "${CLAUDE_PLUGIN_ROOT}/scripts/setup-rlcr-loop.sh""...humania//scripts/..." (double slash)
  3. Setup script records COMMAND_SIGNATURE via cd "$(dirname ...)" && pwd → normalizes to single slash
  4. PostToolUse hook compares tool_input.command (double slash) against COMMAND_SIGNATURE (single slash) → never matches
  5. Signal file never consumed → session_id stays empty → find_active_loop() backward-compat matches any session → cross-session hijacking

Test plan

  • Verify session_id is correctly written to state.md after starting a new RLCR loop
  • Verify .pending-session-id signal file is consumed (deleted) after setup
  • Verify two concurrent Claude Code sessions do not interfere via stop hooks
  • Run existing session-id tests: tests/test-session-id.sh

Fixes #67

🤖 Generated with Claude Code

… write failure

When CLAUDE_PLUGIN_ROOT has a trailing slash, the command template
produces double slashes (e.g. "humania//scripts/setup-rlcr-loop.sh").
The setup script normalizes its own path via cd+pwd (single slash),
but tool_input.command preserves the original double-slash string.
This causes the boundary-aware string match in loop-post-bash-hook.sh
to always fail, so the .pending-session-id signal is never consumed
and session_id is never written to state.md.

With an empty session_id, find_active_loop() backward-compat logic
matches any session, causing cross-instance stop hook hijacking when
multiple Claude Code sessions run concurrently.

Fix: normalize consecutive slashes with tr -s '/' before comparison.

Fixes: PolyArch#67

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gyy0592 gyy0592 changed the base branch from main to dev April 4, 2026 18:35
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ZenusZhang ZenusZhang force-pushed the dev branch 2 times, most recently from 16dbf50 to a1f3614 Compare April 7, 2026 03:38
@SihaoLiu SihaoLiu merged commit 28813b6 into PolyArch:dev Apr 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: session_id never written to state.md — double-slash path mismatch in PostToolUse signal verification

2 participants