a73x

9a9ccf56

docs: add CLAUDE.md, a context budget for this repo

a73x   2026-08-18 12:38

Commit message
docs: add CLAUDE.md, a context budget for this repo

A retrospective over this project's ten session transcripts put 84% of
the token bill in cache reads — context already in the window, re-sent
every turn. Growth across all sessions totalled 6.9M tokens and was
billed as 2,198M: every token added is paid for roughly 317 more times
before the session ends. The baseline at turn one is 35-40k, so nearly
all of it is self-inflicted, and reading the tree is what inflicts it —
822k tokens tracked, 9.1k lines in server.zig alone.

So this file is a budget, not an introduction. The "never cat these"
list and the //! header trick exist because grep-then-window costs a
fiftieth of a read; the toolchain pin is here because rediscovering it
costs a failed build first; the invariants are the design facts that
reviews kept re-deriving from source. Kept to ~990 tokens on the same
logic it teaches — it loads every session and is re-billed with the
rest.

The build steps were taken from `zig build --help` and the layer table
from build.zig's module table, which caught a `make check` that does
not exist: the gate is a zig step with no Makefile target.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

CLAUDE.md
Old New
@@ -0,0 +1,84 @@
1 # mux
2
3 Terminal multiplexer: ghostty-vt engine runs authoritatively in `muxd`, replicated
4 in the client. Attach = one snapshot, then row deltas. Zig, Linux only, prototype.
5
6 ## Toolchain (pinned — system zig will NOT build this)
7
8 ```sh
9 ZIG=$HOME/Downloads/zig-x86_64-linux-0.15.2/zig # ghostty pin, 0.15.x only
10 make build test e2e # Makefile already points at it
11 $ZIG build check # fmt + unit tests + shell syntax — pre-commit gate (no make target)
12 make agent soak bench xversion
13 ```
14
15 First build after a clean checkout fetches ~30MB of QUIC deps (minutes, once).
16 `make clean` deliberately spares `deps/quic`.
17
18 ## Reading this repo without burning context
19
20 Files are large and comment-dense (~44% of Zig bytes are `//`). Reading the repo
21 costs ~800k tokens; every token stays in context and is re-billed each turn.
22
23 - **Never `cat` these:** `src/server.zig` (9.1k lines, ~110k tok),
24 `test/e2e.sh` (4.2k), `docs/decisions.md` (3.7k), `src/client.zig` (3.1k).
25 Use `grep -n` for the symbol, then `sed -n 'A,Bp'` for a window.
26 - Every module has a `//!` header stating its contract. `head -12 src/X.zig`
27 answers most "what is this" questions for ~200 tokens.
28 - Pipe Bash output: `| tail -30`, `2>/dev/null`, `grep -c`. `make test` full
29 output is thousands of tokens of re-billed noise.
30 - `docs/superpowers/plans/*` are historical (16 files, ~15k lines). Grep, don't read.
31
32 ## Layout
33
34 Layers are enforced in `build.zig`'s module table (grep `.layer =` for the graph).
35
36 | Layer | Modules |
37 |---|---|
38 | 0 | `protocol` `engine` `pty` `quic` `keymap` `xdg` `sockpath` `proxy` `testtmp` |
39 | 1 | `quic_server` `quic_client` `predict` `spawn` `handoff` `delta` `cmd` `shellint` `replica` `paint` |
40 | 2 | `server` `client` `muxa` |
41 | 3/4 | `mux_main` `main`(muxd) `webhub` `webhub_main`(muxweb) |
42
43 Binaries: `muxd` (daemon), `mux` (client), `muxa` (agent client, JSON verbs),
44 `muxweb` (browser hub). Test fixtures in `test/`: `ptyclient` (real client on a
45 real pty), `wsclient` (browser stand-in), `rawmode`, `delaypipe`, `render`.
46
47 ## Invariants — do not break, they are load-bearing
48
49 - **Transport is dumb.** `proxy.zig` and the QUIC modules carry opaque bytes and
50 know nothing of frames. Keep `protocol` out of `proxy.zig`'s imports.
51 - **Prediction is an overlay.** `predict.zig` output never enters the replica.
52 - **One replay core.** CLI, wasm, and test fixtures all go through `replica.zig`.
53 Do not hand-roll a second applier.
54 - **Latest wins.** The grid follows the most recently active client.
55 - **`muxa` attaches at 0×0** so an agent never resizes a human's session.
56 - **OSC 133 marks are opt-in** (`MUX_SHELL_INTEGRATION=1`); without them `muxa`
57 falls back to `pgid`/`settle` and there is no real exit code. Every `muxa`
58 reply names the `mechanism` that answered it.
59 - **OSC 52 clipboard READ is refused deliberately.** Not a gap.
60 - No socket stealing: `muxd run` refuses a path another daemon owns.
61
62 ## Working rules
63
64 - Assert behavior, don't assume it. Mocks are assumptions.
65 - Comments say *why*, not *how*. Existing ones are load-bearing — trim noise,
66 keep rationale.
67 - Commit often with `--fixup`/`--squash`, autosquash before delivery. The final
68 history should tell the feature's story, not the development's.
69 - `git-collab` tracks issues (`git-collab issue list`); the commit-msg hook
70 stamps `Patch:` trailers. Each collab write costs a ~15s origin sync — batch.
71 - `zig build check` before commit; capture `$?` before piping (`make test | tail`
72 reports tail's exit code, not the build's).
73
74 ## Where the answers live
75
76 `docs/roadmap.md` (579 ln) what's next · `docs/decisions.md` (3.7k ln, grep only)
77 every decision + measurement · `docs/handoff.md` (199 ln) original design ·
78 `README.md` user-facing usage.
79
80 ## Session hygiene
81
82 Context is billed per turn. Compact or start fresh around ~150k rather than
83 riding to the 900k ceiling — a long session pays for its whole history on every
84 turn, including the trivial ones.