clatter-bus 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. clatter_bus-0.1.0/.gitignore +22 -0
  2. clatter_bus-0.1.0/ARCHITECTURE.md +173 -0
  3. clatter_bus-0.1.0/LICENSE +201 -0
  4. clatter_bus-0.1.0/PKG-INFO +258 -0
  5. clatter_bus-0.1.0/README.md +236 -0
  6. clatter_bus-0.1.0/clatter/__init__.py +6 -0
  7. clatter_bus-0.1.0/clatter/cli.py +48 -0
  8. clatter_bus-0.1.0/commands/clat.md +39 -0
  9. clatter_bus-0.1.0/install.sh +62 -0
  10. clatter_bus-0.1.0/manual-patterns.example +21 -0
  11. clatter_bus-0.1.0/peers.example +9 -0
  12. clatter_bus-0.1.0/pyproject.toml +61 -0
  13. clatter_bus-0.1.0/relay/clatter-relay.sh +94 -0
  14. clatter_bus-0.1.0/scripts/_bus_common.sh +175 -0
  15. clatter_bus-0.1.0/scripts/bus-cleanup.sh +14 -0
  16. clatter_bus-0.1.0/scripts/bus-clear.sh +20 -0
  17. clatter_bus-0.1.0/scripts/bus-deregister.sh +17 -0
  18. clatter_bus-0.1.0/scripts/bus-desc.sh +29 -0
  19. clatter_bus-0.1.0/scripts/bus-doctor.sh +55 -0
  20. clatter_bus-0.1.0/scripts/bus-hook-deregister.sh +10 -0
  21. clatter_bus-0.1.0/scripts/bus-hook-register.sh +59 -0
  22. clatter_bus-0.1.0/scripts/bus-mode.sh +30 -0
  23. clatter_bus-0.1.0/scripts/bus-namecheck.sh +78 -0
  24. clatter_bus-0.1.0/scripts/bus-peers.sh +50 -0
  25. clatter_bus-0.1.0/scripts/bus-recv.sh +38 -0
  26. clatter_bus-0.1.0/scripts/bus-register.sh +34 -0
  27. clatter_bus-0.1.0/scripts/bus-resolve.sh +17 -0
  28. clatter_bus-0.1.0/scripts/bus-send.sh +90 -0
  29. clatter_bus-0.1.0/scripts/bus.sh +62 -0
  30. clatter_bus-0.1.0/systemd/clatter-cleanup.service +6 -0
  31. clatter_bus-0.1.0/systemd/clatter-cleanup.timer +10 -0
  32. clatter_bus-0.1.0/systemd/clatter-relay.service +12 -0
  33. clatter_bus-0.1.0/uninstall.sh +44 -0
@@ -0,0 +1,22 @@
1
+ # Local-only notes (machine-specific / private details) — kept out of the repo on purpose
2
+ INTERNAL_NOTES.md
3
+
4
+ # Runtime artifacts (only appear if you run/develop in-tree)
5
+ relay.log
6
+ registry/
7
+ mailbox/
8
+
9
+ # settings.json backups written by install/uninstall
10
+ *.bak-*
11
+
12
+ # Python build artifacts
13
+ dist/
14
+ build/
15
+ *.egg-info/
16
+ __pycache__/
17
+ *.pyc
18
+
19
+ # editor / OS cruft
20
+ *.swp
21
+ *~
22
+ .DS_Store
@@ -0,0 +1,173 @@
1
+ # Architecture
2
+
3
+ Clatter is a per-machine message bus for interactive Claude Code sessions. This document covers
4
+ how it works, the security model, and the design decisions behind it. For usage, see
5
+ [README.md](README.md).
6
+
7
+ ## The problem that dictates the shape
8
+
9
+ Three facts about Claude Code sessions drive every design choice:
10
+
11
+ 1. **They're interactive CLI processes, one per tmux pane** — not an SDK you can push messages into.
12
+ The only way to inject a turn into a live interactive session is `tmux send-keys` into its pane.
13
+ tmux delivers immediately if the pane is idle at the prompt and **queues** the keystrokes if it's
14
+ mid-turn, so a busy session picks the message up when it returns to the prompt — no interrupt
15
+ logic required.
16
+ 2. **Pane identity drifts.** A pane's id (`%76`) can be remapped by tmux resurrect/continuum on
17
+ restore, while the process keeps a stale `$TMUX_PANE` in its environment. The **tty**
18
+ (`/dev/pts/N`) is the identity that never lies. So a session registers its **pid**, and the relay
19
+ resolves pid → tty → current pane *live, at wake time*.
20
+ 3. **Nothing runs between turns.** An idle session executes nothing; hooks fire only on user/agent
21
+ events. So the wake must come from *outside* the session — a long-running relay.
22
+
23
+ A passive "bulletin board" (sessions read a shared file when the user next prompts them) cannot do
24
+ real-time round-trips: a query would sit unread until you visited that pane, and the reply until you
25
+ visited the asking pane. Real-time requires something that can wake an idle session. Hence the relay.
26
+
27
+ ## Components
28
+
29
+ ```
30
+ ~/.claude/clatter/
31
+ ├── scripts/
32
+ │ ├── _bus_common.sh # shared paths + pid→tty→pane + sessionId/live-name resolvers
33
+ │ ├── bus-register.sh # register/refresh this session (keyed by sessionId)
34
+ │ ├── bus-send.sh # drop a message (local, or over SSH to a peer machine)
35
+ │ ├── bus-recv.sh # drain inbox, render as untrusted data (backs /clat recv)
36
+ │ ├── bus-resolve.sh # resolve a live name -> local sessionId (used locally + over SSH)
37
+ │ ├── bus-peers.sh # list the registry with live names
38
+ │ ├── bus-cleanup.sh # prune dead-pid entries
39
+ │ ├── bus-deregister.sh # remove one entry
40
+ │ ├── bus.sh # /clat dispatcher (peers|ask|send|broadcast|recv|status)
41
+ │ ├── bus-hook-register.sh # SessionStart hook
42
+ │ └── bus-hook-deregister.sh# SessionEnd hook
43
+ ├── relay/clatter-relay.sh # the daemon (systemd --user)
44
+ ├── registry/<sessionId>.json # live sessions (pid-anchored; no name/pane id stored)
45
+ ├── mailbox/<sessionId>/ # <epoch_ms>-<rand>.json messages + archive/
46
+ ├── manual-patterns # cwd globs that register manual (relay never types into them)
47
+ └── peers # SSH host aliases for cross-machine discovery
48
+ ```
49
+
50
+ The message-bus terminology (`bus-*.sh`, "on the bus") is the accurate description of the mechanism:
51
+ Clatter is a message bus; the `bus-*` scripts are its implementation.
52
+
53
+ ### Registry — `registry/<sessionId>.json`
54
+ One file per live session, written by the SessionStart hook, keyed by the Claude **sessionId** (a
55
+ UUID, stable across `/rename` and `claude -c`) so a rename never re-keys anything:
56
+ ```json
57
+ { "sessionId":"a1b2c3d4-…", "pid":962981, "machine":"host",
58
+ "cwd":"/home/user/api", "mode":"auto", "started":"…" }
59
+ ```
60
+ `pid` is the liveness anchor and what the relay resolves to a pane. **No name and no pane id are
61
+ stored** — the name is resolved live (see Naming). `mode` is `auto` (relay may wake it) or `manual`
62
+ (relay never types into it).
63
+
64
+ ### Mailbox — `mailbox/<sessionId>/`
65
+ Per-session inbox. Messages are JSON files named `<epoch_ms>-<rand>.json` (the message `id`).
66
+ Processed files move to `archive/`. Writes are atomic (tmp file + `rename()`), so no partial reads.
67
+ FIFO by filename, which sorts by the millisecond prefix.
68
+
69
+ ### Relay — `relay/clatter-relay.sh` (systemd `--user` service)
70
+ Runs as your user so it can reach the tmux socket. On start it **scans existing mailboxes and
71
+ delivers anything already pending** (inotify only reports *new* events, so this closes the
72
+ relay-was-down gap). Then it watches `mailbox/` with `inotifywait` — or, if inotify-tools isn't
73
+ installed, **polls every second** (`CLATTER_POLL`) with a per-file seen-set for the same new-file
74
+ semantics. For each new `<id>.json` under `mailbox/<target>/` it rejects unsafe target names, reads
75
+ `registry/<target>.json`, and — if the target is `auto` and its pid is alive — resolves
76
+ pid → tty → pane and types the wake. An `auto` target that no longer resolves to a pane (e.g. tmux
77
+ was killed mid-session) is left queued with a loud `WARN` rather than silently dropped. Dead targets
78
+ are pruned on contact. Logs to `relay/relay.log`.
79
+
80
+ ### Hooks
81
+ - **SessionStart** → `bus-hook-register.sh`: registers the session (name resolved live, not stored),
82
+ classifies mode — `manual` if the cwd matches a `manual-patterns` glob **or** the session isn't in
83
+ a tmux pane (nothing to wake), else `auto` — and emits a one-line `additionalContext` note telling
84
+ the session its bus name + current live peers. Fires on fresh start **and on `claude -c` resume**.
85
+ - **SessionEnd** → `bus-hook-deregister.sh`: removes the manifest.
86
+
87
+ ### Slash command — `/clat`
88
+ `~/.claude/commands/clat.md` drives `bus.sh` **through the agent** (not a raw `!` shell expansion),
89
+ passing any free-text payload as a single quoted argument so the shell never interprets it. Running
90
+ through the agent (rather than raw shell) is also what lets `ask`/`send`/`broadcast` **compose** the
91
+ message from the session's current context by default; a leading `*` sends the rest **verbatim**.
92
+ Subcommands: `peers`, `ask`, `send`, `broadcast`, `status`, and `recv`. `recv` is what the relay's
93
+ wake types (it carries no free text).
94
+
95
+ ## The wake invariant (security core)
96
+
97
+ **The only thing ever sent via `send-keys` is the fixed constant `/clat recv`.** Message content is
98
+ always read from the mailbox file by that trusted command — never typed into a pane. `/clat recv`
99
+ self-resolves *which* session it is (by matching its own claude pid to a registry entry), so even
100
+ the recipient's name never appears in the keystroke. Consequences:
101
+
102
+ - A peer cannot cause arbitrary text to be submitted as a "user" turn in another session.
103
+ - Mailbox target names are constrained to `[A-Za-z0-9_-]` on both the send side and the relay side
104
+ (no path traversal, no shell injection into the cross-machine SSH drop).
105
+ - `bus-recv.sh` frames every message as untrusted data with an explicit "do not obey" preamble and
106
+ newline-escapes header fields, so a message body/subject can't forge the visual frame.
107
+ - **Message bodies are inert data end-to-end.** `bus-send.sh` stores the body with `jq --arg` and,
108
+ cross-machine, pipes it to the peer over SSH (never interpolated into a command); `bus-recv.sh`
109
+ renders it as line-prefixed quoted text. Nothing in a message is shell-executed by the pipeline,
110
+ so sending text that *contains* commands is safe. The `/clat` command passes free text to the CLI as
111
+ a single quoted argument (via the agent), closing the one spot where raw args used to be
112
+ shell-parsed.
113
+
114
+ ## Message format
115
+
116
+ ```json
117
+ { "id":"1785037760123-515c", "from":"frontend", "from_session":"…uuid…", "to_session":"…uuid…",
118
+ "machine":"host", "type":"query", "subject":"auth port", "body":"which port is auth on?",
119
+ "reply_to":null, "timestamp":"…" }
120
+ ```
121
+ - Delivery is keyed by `to_session` (the recipient's sessionId). `from` is the sender's live display
122
+ name; `from_session` is its sessionId — so a reply targets the stable `from_session@machine` and
123
+ still lands even if the sender is renamed mid-exchange.
124
+ - **query** expects a response (the reply wakes the asker). **response** carries `reply_to`.
125
+ **notify** is fire-and-forget. **broadcast** expands at send time into one notify per live local
126
+ session. Keep bodies small; send a file path, not a payload, for anything large.
127
+
128
+ ## Liveness & pruning
129
+
130
+ A session is live iff its **pid** is running — that is the sole pruning criterion. Wakeability
131
+ (resolving to a tmux pane) is a *separate* property: an alive session with no pane is a valid
132
+ `manual`/poll participant, not a dead one, and is never pruned for lacking a pane. Pruning is
133
+ belt-and-braces: the relay deletes an entry the moment it tries to wake an `auto` target whose pid is
134
+ dead, and a systemd timer (`clatter-cleanup.timer`, every 5 min) sweeps the rest with
135
+ `bus-cleanup.sh` — also pid-only.
136
+
137
+ ## Naming & addressing
138
+
139
+ The addressable **name is resolved live**, never stored, in this order:
140
+ 1. the latest `custom-title` record in the session's transcript
141
+ (`~/.claude/projects/*/<sessionId>.jsonl`) — this captures both a local `/rename` **and a web-UI
142
+ rename** (the sync daemon writes the cloud rename into the transcript, even though it does *not*
143
+ update the session file's `.name`);
144
+ 2. Claude's session-file `.name` (`~/.claude/sessions/<pid>.json`) — the derived/auto name;
145
+ 3. the cwd basename.
146
+
147
+ So `/clat peers`, `/clat status`, and `/clat ask <name>` always reflect the *current* name — rename a
148
+ session anywhere and the bus follows, with no re-keying (the key is the sessionId). Names may
149
+ contain spaces and never touch a filesystem path or an SSH command line (those use the UUID), so
150
+ there are no charset restrictions on them. Address a peer by its current name, or by a sessionId
151
+ directly (what replies use); append `@machine` to force a host. Same-name collisions resolve to the
152
+ first match — use `name@machine` or the sessionId to disambiguate.
153
+
154
+ ## Cross-machine
155
+
156
+ Address a peer explicitly as `name@machine` (an SSH host/alias). `bus-send.sh` drops the message
157
+ into that host's mailbox over SSH. The peer's own relay wakes
158
+ the pane, and `bus-recv.sh` renders a `reply to: <from_session>@<machine>` target (a sessionId, so
159
+ replies survive a rename). This reuses your existing SSH keys; verified host↔host in both directions.
160
+
161
+ Discovery is on-demand over SSH (no daemon, no sync): list peer hosts in `$CLATTER_ROOT/peers`
162
+ (SSH aliases, one per line). `bus-peers.sh` aggregates each peer's `--json` output into `/clat peers`
163
+ (rows shown as `name@host`, each peer resolving its own live names). Addressing a bare name that
164
+ isn't local runs `bus-resolve.sh` on each peer (the name piped in over stdin — never interpolated
165
+ into the remote command) to map it to that host's sessionId, routing to the first match; use
166
+ `name@host` or a sessionId to disambiguate. `broadcast` is local-machine only.
167
+
168
+ ## Why `send-keys`, not a headless run
169
+
170
+ An alternative is to resume the target session headlessly (`claude -c -p "…"`) to answer. That forks
171
+ a turn the live interactive pane never renders and races the session's transcript — wrong when a
172
+ human is watching that pane. `send-keys` drives the *real* session the user is looking at, so the
173
+ exchange shows up as visible turns in both panes.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Brandon Thomas
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,258 @@
1
+ Metadata-Version: 2.4
2
+ Name: clatter-bus
3
+ Version: 0.1.0
4
+ Summary: Real-time message bus for Claude Code sessions — one asks, another wakes and answers, hands-free.
5
+ Project-URL: Homepage, https://github.com/brandonrthomas/clatter
6
+ Project-URL: Repository, https://github.com/brandonrthomas/clatter
7
+ Project-URL: Issues, https://github.com/brandonrthomas/clatter/issues
8
+ Author-email: Brandon Thomas <brandon.thomas.r@gmail.com>
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: agents,claude,claude-code,cli,ipc,message-bus,tmux
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Communications
19
+ Classifier: Topic :: Software Development :: Libraries
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+
23
+ # Clatter
24
+
25
+ **A real-time message bus for Claude Code sessions.** Run many `claude` sessions at once — one
26
+ per tmux pane — and let them talk to each other: one session asks another a question, the other
27
+ *wakes on its own*, answers, and the reply lands back in the asking pane. No copy-paste between
28
+ panes, no human relay.
29
+
30
+ <p align="center">
31
+ <img src="docs/demo.gif" alt="Clatter — one session asks, another wakes and answers, and the reply lands back" width="860">
32
+ </p>
33
+ <p align="center"><sub>Two Claude Code sessions over the bus — ask on the left; the peer auto-wakes and answers on the right.</sub></p>
34
+
35
+ <br>
36
+
37
+ ---
38
+
39
+ ```
40
+ session "frontend" relay (per machine) session "api"
41
+ ────────────────── ─────────────────── ─────────────
42
+ /clat ask api which port is the
43
+ auth service on? ────────────▶ new message for "api"
44
+ │ resolve api → its tmux pane
45
+ └─ wake it ──────────────────────▶ (idle or busy)
46
+ │
47
+ reads the question, answers "8081",
48
+ sends the reply back:
49
+ reply appears in your pane ◀────── new message for "frontend" ◀────────────┘
50
+ ```
51
+
52
+ Clatter = **Claude** + **chatter** — it lets Claude Code sessions chatter to each other across
53
+ tmux. Under the hood it's a small, dependency-light message bus — a few bash scripts, a file-drop
54
+ mailbox, and one tiny relay daemon.
55
+
56
+ ---
57
+
58
+ ## Why
59
+
60
+ If you run a fleet of Claude Code sessions (one per project/pane), they can't see each other. You
61
+ end up hand-carrying facts between them: *"the other session set the port to 8081"*, *"the model
62
+ you loaded is aliased `qwen-large`"*. Clatter gives them a phone line. A session can consult a
63
+ peer that actually **owns** the answer, in real time, without you in the middle.
64
+
65
+ ## Features
66
+
67
+ - **Real round-trips.** `/clat ask <peer> <question>` sends a query; the answer comes back to *your*
68
+ pane asynchronously — because the relay can wake an idle session, not just leave it a note.
69
+ - **Names you recognize, live.** A session's bus name is its **Claude session name** (what `/rename`
70
+ sets, shown in your tab) — resolved live, so renaming a session (locally *or* from the web UI) is
71
+ reflected immediately, with no manual wiring. Sessions auto-register at start and on `claude -c`.
72
+ - **Self-cleaning.** Dead sessions are pruned automatically (on contact and on a timer).
73
+ - **Safe by design.** The only thing ever typed into another pane is a fixed control string — never
74
+ message content — so a peer can't inject an arbitrary "user" turn. Sensitive workspaces can be
75
+ marked read-only to the relay, and `/clat doctor` audits that the guard actually covers them. (See
76
+ [Security](#security).)
77
+ - **Small + legible.** Bash + `jq` + `inotifywait` + `tmux`. One systemd `--user` relay. No server,
78
+ no database, no ports.
79
+
80
+ ## How it works (in three facts)
81
+
82
+ 1. **Sessions are interactive `claude` CLIs, one per tmux pane.** The only way to hand a running
83
+ interactive session a new turn is `tmux send-keys` into its pane — which delivers instantly if
84
+ it's idle and *queues* if it's mid-turn.
85
+ 2. **The target pane is resolved live, never stored.** Pane ids drift (tmux resurrect/renumber), so
86
+ nothing caches a pane id: each session is keyed by a stable **sessionId** (which also names its
87
+ mailbox, so a rename never misroutes), and at wake time the relay looks up that session's **pid**
88
+ and resolves pid → tty → current pane.
89
+ 3. **Nothing runs between turns**, so the push comes from outside: a per-machine **relay daemon**
90
+ watches the mailboxes (`inotifywait`) and wakes the target pane when a message arrives.
91
+
92
+ Full design in [ARCHITECTURE.md](ARCHITECTURE.md).
93
+
94
+ ## Requirements
95
+
96
+ - Linux with **tmux** for auto-wake — a session that should be woken automatically must run in a
97
+ tmux pane. A session outside tmux still works, in manual (poll) mode (see **Manual mode** below).
98
+ - **`jq`** and **systemd** with user services + lingering. **`inotify-tools`** (`inotifywait`) is
99
+ recommended but optional — without it the relay falls back to polling.
100
+ - **Claude Code** (the `claude` CLI) with hooks and custom slash commands. Note: `claude --safe-mode`
101
+ disables *all* customizations — hooks and custom commands don't load — so a safe-mode session won't
102
+ join the bus or have `/clat`.
103
+
104
+ ```bash
105
+ sudo apt install jq inotify-tools tmux # Debian/Ubuntu
106
+ loginctl enable-linger "$USER" # so the relay survives logout/reboot
107
+ ```
108
+
109
+ ## Install
110
+
111
+ Via pip (the package is `clatter-bus`; the command is `clatter`):
112
+
113
+ ```bash
114
+ pip install clatter-bus
115
+ clatter install
116
+ ```
117
+
118
+ …or straight from the repo:
119
+
120
+ ```bash
121
+ git clone https://github.com/brandonrthomas/clatter.git
122
+ cd clatter
123
+ ./install.sh
124
+ ```
125
+
126
+ Both run the same `install.sh` — it's idempotent. It copies the code to `~/.claude/clatter/`, installs the `/clat` slash
127
+ command, wires `SessionStart`/`SessionEnd` hooks into `~/.claude/settings.json` (backing it up
128
+ first, preserving everything else), and enables the relay + cleanup timer. Open new sessions (or
129
+ `claude -c` existing ones) and they'll join.
130
+
131
+ ## Usage
132
+
133
+ From inside any session:
134
+
135
+ ```
136
+ /clat peers # who's on the bus (name, machine, alive, mode, description)
137
+ /clat ask <name> <question> # ask a peer; the answer returns to THIS pane, asynchronously
138
+ /clat send <name> <message> # fire-and-forget notify
139
+ /clat broadcast <message> # notify every live session
140
+ /clat recv # read your inbox (the relay normally triggers this for you)
141
+ /clat clear # archive your inbox without reading it
142
+ /clat status # your own bus name + pending inbox
143
+ /clat mode [auto|manual] # show or set whether the relay may wake this session
144
+ /clat desc [text] # show or set this session's description (shown in /clat peers)
145
+ /clat doctor # audit the manual-mode guard — what the patterns actually match
146
+ ```
147
+
148
+ Everywhere above, `<name>` is a peer's **Claude session name** — the name `/rename` sets, shown in
149
+ its tab — matched live, so it always tracks the session's current name. (Leave a session unnamed and
150
+ it uses Claude's auto-generated name, e.g. `host-quiet-tome`.)
151
+
152
+ If two live sessions resolve to the **same** name, they're disambiguated with a `-2`/`-3` suffix in
153
+ `/clat peers` and when addressing (the earliest keeps the bare name); a session that *renames* into a
154
+ collision gets a heads-up to pick a unique one. The suffix is display/addressing only — delivery is
155
+ keyed by sessionId, so it never misroutes.
156
+
157
+ `/clat ask` doesn't block — you keep working; when the peer answers, the relay wakes your pane and
158
+ the reply appears inline.
159
+
160
+ **Composing vs. verbatim.** For `ask` / `send` / `broadcast`, the text after the command is normally
161
+ an *instruction for what to communicate*: the session composes the actual message from its current
162
+ context and sends that — e.g. `/clat ask box tell them the port I just set` sends something like
163
+ `The auth port is 8081.` (A self-contained question is just sent as-is.) To send text **exactly** as
164
+ written — a command, a snippet, precise wording — prefix it with `*`: `/clat send api *rm -rf /tmp/cache`
165
+ stores that literal string as a message (it is never executed).
166
+
167
+ **Cross-machine.** List your other hosts in `~/.claude/clatter/peers` (one SSH alias per line).
168
+ Then `/clat peers` aggregates their live sessions (shown as `name@host`), and `/clat ask <name> <question>`
169
+ auto-locates a peer across those hosts — or address one explicitly as `name@host`. The message is
170
+ dropped over SSH into that host's mailbox and its relay wakes the pane; replies route back
171
+ automatically. Requires Clatter on each
172
+ host and key-based SSH between them.
173
+
174
+ ## Configuration
175
+
176
+ | What | How |
177
+ |---|---|
178
+ | Install location | `CLATTER_ROOT` (default `~/.claude/clatter`) |
179
+ | This machine's name | `CLATTER_MACHINE` (default `hostname -s`) — used for cross-machine addressing |
180
+ | Read-only workspaces | add globs matching your **real dir names** to `~/.claude/clatter/manual-patterns`; verify with `/clat doctor` (see `manual-patterns.example`) |
181
+ | Cross-machine peers | list SSH hosts in `~/.claude/clatter/peers` (see `peers.example`) |
182
+
183
+ **Manual mode.** A registered, fully addressable session that the relay will **never** type into —
184
+ peers see it in `/clat peers`, messages reach its mailbox, and you drain them yourself with `/clat recv`.
185
+ A session registers manual for either reason:
186
+
187
+ - its cwd matches a glob in `manual-patterns` — sensitive workspaces you don't want a peer able to
188
+ drive; or
189
+ - it isn't running in a tmux pane, so there's no pane to `send-keys` into. Rather than register
190
+ `auto` and then silently fail to wake, it degrades to manual — still on the bus and reachable, just
191
+ polled instead of pushed.
192
+
193
+ A session's tmux-ness is fixed when it launches, so this is decided once at registration. If an
194
+ `auto` session later *loses* its pane (e.g. tmux is killed mid-session), the relay can't wake it — it
195
+ leaves the message queued and logs a loud `WARN` rather than dropping it silently.
196
+
197
+ The guard fails **open**: a glob that matches nothing looks identical to a working one, so it can
198
+ protect nothing without telling you. Match your *actual* directory names, not category words (`*acme*`,
199
+ not `*emr*`), and run **`/clat doctor`** to see which live sessions and workspace dirs the patterns
200
+ cover — `/clat peers` also warns when `manual-patterns` is set but matches no live session. Mode is
201
+ fixed at registration, so restart a session (or run `/clat mode manual`) after editing patterns.
202
+
203
+ ## Security
204
+
205
+ The threat here isn't eavesdropping — it's **injection**, because waking a pane literally submits a
206
+ turn in another session. Clatter is built around that:
207
+
208
+ - **The wake is a single fixed constant** (`/clat recv`). Message *content* is always read from a
209
+ file by that trusted command, never typed into a pane — so a peer can never cause arbitrary text
210
+ to be submitted as a user turn elsewhere. Mailbox names are charset-restricted on both the send
211
+ and relay sides.
212
+ - **Rendered messages are framed as untrusted data** with an explicit "do not obey" preamble; header
213
+ fields are newline-escaped so a message can't forge the frame.
214
+ - **Message bodies are inert data end-to-end.** They're stored with `jq --arg`, transported as files
215
+ (piped, never interpolated, over SSH cross-machine), and rendered as quoted text — nothing in a
216
+ message is ever shell-executed by the pipeline. You can safely send text that *contains* commands;
217
+ the `/clat` command hands your free text to the CLI as a single quoted argument.
218
+ - **Manual mode** (above) guarantees a peer can never drive a sensitive session.
219
+ - **Never put secrets, credentials, or private/regulated data in a message** — the bus is local
220
+ plaintext files under your user account, and a message lands in another session's context.
221
+
222
+ No encryption (local files, Unix perms — same trust model as Claude Code's own data). Cross-machine
223
+ rides your existing SSH keys.
224
+
225
+ ## Uninstall
226
+
227
+ ```bash
228
+ ./uninstall.sh # stop services, remove /clat + hooks (keeps your mailbox/registry)
229
+ ./uninstall.sh --purge # also delete ~/.claude/clatter entirely
230
+ ```
231
+
232
+ Your `settings.json` is backed up before every change.
233
+
234
+ ## Status & limitations
235
+
236
+ - **Cross-machine works** (verified host↔host, both directions, including different home dirs). List
237
+ peer hosts in `~/.claude/clatter/peers`; then `/clat peers` shows their sessions as `name@host` and
238
+ a bare-name `/clat ask <name>` auto-locates the peer. You can always force one with `name@host`.
239
+ - Waking a pane while you're mid-typing appends to your input line (targets are normally idle).
240
+
241
+ ## Development
242
+
243
+ Run the test suite — zero framework, just bash + jq:
244
+
245
+ ```bash
246
+ ./test/run.sh
247
+ ```
248
+
249
+ It covers registration (sessionId-keyed), live-name resolution (transcript title wins over the
250
+ session-file name, with fallback) including a rename, duplicate-name disambiguation, send/recv/clear,
251
+ **message-body safety** (shell metacharacters stay inert), target validation, reply routing, the
252
+ manual-mode guard + `/clat doctor` (fail-open detection), the rename-collision notifier, `mode`/`desc`,
253
+ discovery `--json`, broadcast, and cleanup — against an isolated `CLATTER_ROOT` with fake session
254
+ files. The relay, tmux wake, and cross-machine SSH are integration paths, verified manually.
255
+
256
+ ## License
257
+
258
+ [Apache-2.0](LICENSE) © 2026 Brandon Thomas