sessions/AGENTS.md
agent 0738171f1e Archive sessions, allow spaces in names, stop tripping the SSH rate limit
Connection refused: the dev box's UFW `limit` rule refuses the 6th new
SSH connection from one address within 30 s. Every page view made two
calls (list, repos) and every button one more, so stopping two sessions
and refreshing hit it (kernel log: "UFW LIMIT BLOCK" from prod's IP).
The web app now multiplexes all calls over one connection
(ControlMaster=auto, ControlPersist=120), with the socket in its private
temp dir. compose.yaml gets `init: true` so the backgrounded master is
reaped; the app warns if it runs as PID 1.

Spaces in names: `create` now takes a title (letters, digits, '-',
single spaces, <= 48 chars). The slug used for the directory, branch,
unit and tmux socket is derived from it; the title is shown on the page
and passed to claude as --name. A plain slug still maps to itself.

Archive: new remote verbs `archive` (stop + flag, keeps checkout and
conversation) and `unarchive` (back to the list, still stopped). An
archived session refuses `start`. The page lists archived sessions in a
collapsible section. `list` re-reads state under the lock before saving
a Remote Control URL so it can't undo a concurrent archive.

Also: name/branch validation used re.match with `$`, which accepts a
trailing newline; it now uses fullmatch.

Tested end to end with a throwaway 127.0.0.1 key and the real container:
24 remote calls went over 1 TCP connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rog8S9b5qKaw6nUicxXLkM
2026-10-06 09:42:40 +00:00

3.1 KiB

AGENTS.md — sessions

A remote session manager: a web page on prod that starts Claude Code sessions on the dev box through one locked-down SSH key. Read the README's "Security model" before changing anything that touches the SSH boundary.

Layout

  • dev/ runs on the dev box: sessions_ctl.py (installed as ~/.local/bin/sessions-ctl), systemd user units, install.sh.
  • web/ runs on prod in a rootless Podman container: app.py, Containerfile. compose.yaml at the root is what prod's panel deploys. Configured only through env vars; sessions-ctl keygen prints them.

Stack and conventions

  • Python ≥ 3.11, standard library only on both sides. No pip install, so there's no supply chain to audit. Keep it that way unless there's a strong reason.
  • The web page has no JavaScript. Plain forms, POST, then a redirect.
  • sessions-ctl prints exactly one JSON object (except keygen: KEY=VALUE lines on stdout, human note on stderr); exit 0/1/2.
  • The web app has no login: Authelia (Caddy forward_auth) in front of it is the login. It must keep refusing requests without the auth header, and refusing cross-site POSTs.
  • The dev port for local work on the web app is 8470, bound to 127.0.0.1. Preview via ssh -p 14922 -L 8470:localhost:8470 <dev box>.

Invariants — do not break

  1. Nothing received over SSH reaches a shell or Claude. No "initial prompt" feature, no free-text arguments. The session title (TITLE_RE: letters, digits, -, single spaces) is the only argument with a space; it becomes claude's --name via shlex.join and nothing else. New remote verbs need validation and a test in dev/tests/test_sessions_ctl.py. Validate with fullmatch: re.match(...$) accepts a trailing newline.
  2. The web app reaches the dev box over one multiplexed SSH connection. The dev box's UFW limit refuses a 6th connection in 30 s, so don't drop ControlMaster, and keep init: true so the master gets reaped.
  3. Local-only verbs (delete, refresh-access, keygen, _launch) stay out of REMOTE_VERBS.
  4. The private key is never written to disk on the dev box outside a temp dir in XDG_RUNTIME_DIR (RAM), which keygen removes.
  5. refresh-access never writes an empty from=, and never touches lines other than the one ending in sessions-manager.
  6. The session unit keeps DBUS_SESSION_BUS_ADDRESS pointed at nothing. Otherwise tmux moves claude into its own tmux-spawn-*.scope and it escapes MemoryMax and clean stops (checked 2026-09-30 with tmux 3.6).
  7. The container publishes to 127.0.0.1 only.

Test

python3 -m unittest discover -s dev/tests
python3 -m unittest discover -s web/tests

To test end to end on the dev box, add a throwaway key with from="127.0.0.1",restrict,command=".../sessions-ctl --remote" … sessions-selftest, run the container with --network host, SESSIONS_DEV_HOST=127.0.0.1 and the key as SESSIONS_SSH_KEY_B64, send requests with a Remote-User header, then remove the key line again. Never run the real keygen from an agent session: its output is a private key and would end up in the transcript.