fix: normalize path slashes in PostToolUse hook to prevent session_id write failure#68
Merged
SihaoLiu merged 2 commits intoPolyArch:devfrom Apr 13, 2026
Merged
Conversation
… 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>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
16dbf50 to
a1f3614
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
//→/) inHOOK_COMMANDandCOMMAND_SIGNATUREbefore the boundary-aware string match inloop-post-bash-hook.shsession_idis never written tostate.md, causing cross-instance stop hook hijacking when multiple Claude Code sessions run concurrentlyCLAUDE_PLUGIN_ROOTmay have a trailing slash, producing double slashes in the command string, while the setup script normalizes its path viacd+pwd— the strict string comparison always failsRoot Cause Detail
CLAUDE_PLUGIN_ROOT=.../marketplaces/humania/(trailing/)"${CLAUDE_PLUGIN_ROOT}/scripts/setup-rlcr-loop.sh"→"...humania//scripts/..."(double slash)COMMAND_SIGNATUREviacd "$(dirname ...)" && pwd→ normalizes to single slashtool_input.command(double slash) againstCOMMAND_SIGNATURE(single slash) → never matchessession_idstays empty →find_active_loop()backward-compat matches any session → cross-session hijackingTest plan
session_idis correctly written tostate.mdafter starting a new RLCR loop.pending-session-idsignal file is consumed (deleted) after setuptests/test-session-id.shFixes #67
🤖 Generated with Claude Code