feat(tmux): route attention to Claude Code windows (#3-#9) #34
No reviewers
Labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
public/dotfiles-public!34
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/claude-tmux-attention"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Attention routing for Claude Code windows in tmux, built on the
@claude_statusthe claude-status hook already keeps. One helper,~/.local/bin/tmux-claude-attention, plus small changes to the hook andtmux.conf.local.Closes #3, closes #4, closes #5, closes #6, closes #7, closes #8, closes #9
What each issue gets
?Nneeds permission, orange*Nwaiting, green*Ndone,⋯Nworking (same glyphs and colours as the tab markers). The counts are stored in@claude_countson each hook event, on window/session close (indexedset-hook, so reloading the config doesn't add duplicates) and once a minute fromstatus-checks.sh, so a redraw never starts a shell.prefix + a: jumps to the next window that needs you, across sessions: needs-permission first, then waiting, then done. Repeatable and cycles. Listed in theprefix + ?cheat sheet.?block. It is reverse video, so it still stands out in terminals that don't blink.noreverse noblinkputs the tab back without touching its colours.@claude_title). This shows in the Ghostty tab and the OS window list.@claude_notify off, choose states with@claude_notify_states, or swap the transport with@claude_notify_cmd.@claude_away_cmd(for exampleset -g @claude_away_cmd 'matrix-bridge send'). When a window is still waiting on you after@claude_away_minutes(default 10), it runs once with the message as$1(details are inCLAUDE_TMUX_*env). It is skipped if the window had output in the last minute, which covers an approved prompt where Claude keeps working (there is no "approved" hook event). Caveat: a CLImatrix-bridge sendmay contend with a running MCP instance for the bridge store (single-instance store takeover), so check that before enabling it.claude --resume: the hook storessession_idandcwdfrom its JSON stdin on the pane (@claude_session_id/@claude_cwd).@resurrect-hook-post-save-allwrites the panes still running Claude to~/.local/share/tmux/claude-resume.tsv.@resurrect-hook-post-restore-alltypescd -- <cwd> && claude --resume <id>into the restored shells. Disable with@claude_resurrect_resume off.Behaviour change
The hook now sets
@claude_status=busyinstead of unsetting the option, so working windows can be told apart from plain shells. The tab markers only test idle/waiting/prompt, so tabs look the same. Busy only counts while Claude is still the pane's command.No
settings.jsonchange is needed: the existing UserPromptSubmit / Stop / Notification hooks already pass the JSON on stdin. The helper is plain bash 3.2 (no associative arrays or mapfile), so it works with macOS/bin/bash.Testing
bash test/test-tmux-claude-attention.shpasses 23/23. It runs on a private tmux server with its own socket and HOME, and covers states, session id, counts, stale busy, next ordering and wrap, notify debounce/re-arm/off, the away ping (fires, same stretch, stale timer) and resurrect save/restore/off.scriptpty): the off-screen window gotESC]777;notify;Claude · …;needs permission (main:1)and the focused window got nothing.chezmoi execute-template, no apply) loads cleanly withsource-fileinto a private server. The title and markers expand as expected.shellcheck0.11 is clean on all touched scripts.Not verified: how blink and the OSC look in Ghostty on the Mac (no GUI here).
🤖 Generated with Claude Code
https://claude.ai/code/session_01XMf4EKNjKMd6bwCpS7K4jU
- prefix + a: single quotes inside the run-shell string; session ids ("$1", ...) were expanded to nothing by /bin/sh (F1) - counts, next and a new minute `sweep` only trust a state while some pane of the window still runs Claude; sweep clears stale @claude_status/@claude_notified (F2) - status-checks.sh: mkdir lock dir with pid + stale-age takeover instead of flock (absent on macOS); TERM releases it at once (N1) - hook reads only the first 8 KiB of the payload and drains the rest; first session_id/cwd occurrence wins (N2) - resurrect-restore types `claude --resume` only into a bare shell (N4) - document that `prompt` stays set after approval until Stop (N5) - tests: binding line sourced and pressed on a control-mode client, stale states, sweep, lock, big payload, non-shell restore (51 cases) Co-Authored-By: Claude Opus 5.5 <[email protected]>Review (maximus): MERGE-WITH-NITS
Reviewed head
a61c9f4in a detached worktree. I did not runchezmoi apply.Verified
bash test/test-tmux-claude-attention.sh: 51/51 pass on tmux 3.6a. The PR body still says 23/23, so update it.status-checks.shand the test.tmux.conf.local.tmplwithchezmoi execute-template(throwaway config/state) and loaded it with the real oh-my-tmux into a fully isolated private server (env -i, own HOME/XDG/TMUX_TMPDIR). No errors.prefix ais bound with-r, the indexedwindow-unlinked[42]/session-closed[42]hooks are there, apromptwindow renders#[fg=#d70000 reverse blink] ? #[noreverse noblink fg=default], and the title expands to❓ host ❐ main ● 1 one. Spaces instead of commas in the#[...]styles inside#{?...}were the right call. No{{in the new tmux strings, so the template is safe.@claude_counts/@claude_titlehold only digits and fixed glyphs/styles. Window names reach the OSC 777 only throughclean(), which strips C0, DEL and;.@claude_notify_cmd/@claude_away_cmdget the message as$1, never interpolated into the shell string.session_idis matched by[0-9A-Za-z-]and checked again on restore.cwdexcludes"and\, and on restore it is%q-quoted and must pass-d. Thenextbinding quotes$1-style session ids correctly.m/r. Counts run on hook events, on window/session close and in the minute sweep. The hook adds about 10 tmux client calls per event.-xand the markers render empty. bash 3.2 constructs only, and BSD-safehead -c/grep -o/find -mmin.Nits (none blocking)
claude --resume <id>and Enter (executable_tmux-claude-attention:326). After a reboot of a box with many Claude windows (spl-vm05 runs 5 to 7 agent windows overnight), every one of them starts at once. That's a memory/CPU spike against the box load budget, and it also resumes agent sessions that had already finished. Suggest typing the line without Enter so Bear presses Enter where he wants it (the same convention as for user-run commands), or defaulting@claude_resurrect_resumeto off on servers.CLAUDE_CMD_RE(:56) doesn't matchnode. On a host where Claude came from npm, the minute sweep clears the tab marker within 60 s. Before this PR the marker stayed until the next event. That's fine for the native installer, which both hosts use as far as I can see.status-checks.sh:9falls back to/tmpwhenXDG_RUNTIME_DIRis unset (macOS, some et sessions). On a multi-user host another user can pre-create/tmp/tmux-status-checks.lock.dand stop your loop (DoS only: the sticky bit stops the rm/mkdir, so there's no symlink write).${TMPDIR:-/tmp}would be per-user on macOS.osc_notifywrites to the client tty next to tmux. Rarely, it can land inside one of tmux's escape sequences and garble the screen until the next redraw. That's acceptable; just note it in the comment.on_screenrelies on thefocusedclient flag (tmux 3.3+). On older tmux every event notifies.bind -r a: withinrepeat-timeafter a jump, a typedajumps again instead of reaching the pane. That's standard-rbehaviour; just be aware of it.🤖 Generated with Claude Code