Hook output leaks across git worktrees in multi-agent setup
Summary
When running multiple Claude Code sessions in git worktrees (multi-agent setup), hook output from one session leaks to other sessions.
Environment
- Multiple git worktrees:
main,agents/1,agents/2, etc. - Each worktree has its own Claude Code session
- Shared plugin hooks across worktrees
Steps to Reproduce
- Set up git worktrees:
``bash``
git worktree add agents/1 -b agents/1
git worktree add agents/2 -b agents/2
- Install a plugin with Stop hook (e.g., ralph-local)
- Run Claude Code in main worktree, trigger Stop hook that outputs text
- Observe: Other worktree sessions (agents/1, agents/2) receive the hook output as
<system-reminder>even though they didn't trigger it
Expected Behavior
Hook output should be scoped to the session that triggered it. Other sessions in different worktrees should not receive messages from hooks triggered by other sessions.
Actual Behavior
Hook output is broadcast to ALL running Claude Code sessions, regardless of which $CLAUDE_PROJECT_DIR triggered the hook.
Example
Main agent runs Ralph loop, outputs:
COMPLETED:
- [x] Fix dashboard
- [x] Index markdown
Agent 3 (different worktree) receives:
<system-reminder>
Stop:Callback hook blocking error from command: "callback":
COMPLETED:
- [x] Fix dashboard
- [x] Index markdown
</system-reminder>
Impact
- Confuses agents in multi-agent setups
- Leaks context between isolated sessions
- Makes it hard to maintain agent separation
Suggested Fix
Scope hook output to the session/worktree that triggered it, possibly by checking $CLAUDE_PROJECT_DIR matches.
---
🤖 Generated with Claude Code
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗