Skip to content

fix: support grouped tmux sessions in session_map routing#69

Draft
dwong777 wants to merge 3 commits intosix-ddc:mainfrom
dwong777:fix/grouped-tmux-sessions
Draft

fix: support grouped tmux sessions in session_map routing#69
dwong777 wants to merge 3 commits intosix-ddc:mainfrom
dwong777:fix/grouped-tmux-sessions

Conversation

@dwong777
Copy link
Copy Markdown

Summary

Adds support for grouped tmux sessions (created via tmux new-session -t <target>). Previously, the session_map was keyed by session_name:window_id and the monitor/session manager only read entries matching the configured tmux_session_name prefix. With grouped sessions, windows are shared across all sessions in the group, and the SessionStart hook can fire under any of the group's session names — causing entries to be written under unpredictable prefixes that the monitor never reads.

Symptom: Messages from Claude Code are not relayed to Telegram even though the session is connected (outbound messages and status polling work fine).

Changes

  • Hook (hook.py): Clean up duplicate session_map.json entries for the same window_id across different session name prefixes, so only one entry exists per window
  • SessionMonitor (session_monitor.py): Accept entries from any session name prefix when loading session_map.json (window IDs are globally unique in tmux)
  • SessionManager (session.py): Same prefix-agnostic loading in load_session_map() and _cleanup_stale_session_map_entries()

Test plan

  • Create a grouped tmux session (tmux new-session -t ccbot -s ccbot2)
  • Start Claude Code in a shared window
  • Verify the hook writes a single entry (no duplicates across prefixes)
  • Verify the monitor picks up messages regardless of which session name the hook used

🤖 Generated with Claude Code

dwong777 and others added 3 commits March 28, 2026 23:28
Grouped tmux sessions (created via `tmux new-session -t`) share windows,
so the SessionStart hook can fire under any session name in the group.
The monitor and session manager previously only read entries matching the
configured prefix, missing entries written under other session names.

- Hook: clean up duplicate session_map entries for the same window_id
  across different session name prefixes
- Monitor/SessionManager: accept entries from any session name prefix
  (window IDs are globally unique in tmux)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Grouped tmux sessions accumulate multiple entries for the same window_id
under different session name prefixes over time. When windows are
reassigned (closed and recreated), stale entries can point to the wrong
session_id.

On startup, for each window_id with multiple entries, keep only the one
whose CWD matches the live tmux window's CWD. This ensures the monitor
picks up the correct session.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When multiple session_map entries for the same window_id all share the
same CWD (common when sessions are created in the same directory), CWD
matching alone can't determine which entry is current. Use the most
recently modified JSONL file as a tiebreaker.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dwong777
Copy link
Copy Markdown
Author

An example of how our mapping looks like on a restart with grouped tmux sessions

douglas@douglas-mbp ccmux % tmux display-message -t %0 -p "#{session_name}:#{window_id}:#{window_name}"
ccbot1:@0:__main__
douglas@douglas-mbp ccmux % tmux display-message -t %1 -p "#{session_name}:#{window_id}:#{window_name}"
ccbot1:@1:Claude-1-Startup
douglas@douglas-mbp ccmux % tmux display-message -t %2 -p "#{session_name}:#{window_id}:#{window_name}"
::
douglas@douglas-mbp ccmux % tmux display-message -t %3 -p "#{session_name}:#{window_id}:#{window_name}"
ccbot1:@3:Claude-2-Startup
douglas@douglas-mbp ccmux % tmux display-message -t %4 -p "#{session_name}:#{window_id}:#{window_name}"
ccbot1:@4:Claude-3-Startup
douglas@douglas-mbp ccmux % tmux display-message -t %5 -p "#{session_name}:#{window_id}:#{window_name}"
ccbot1:@5:Claude-4-Startup

@dwong777
Copy link
Copy Markdown
Author

Reminder to self, to have this consistently work I:

  1. Need to start ccbot process first
  2. Then start all the individual Claude Code tmux windows
  3. And finally start the grouped tmux sessions that view each individual tmux window

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.

1 participant