# One Claude Code session with Remote Control, inside its own tmux server. # Managed by sessions-ctl: `enable --now` = run now and at every boot, # `disable --now` = stop and stay stopped. Needs linger for boot start. [Unit] Description=Claude Code session %i After=network-online.target Wants=network-online.target # Give up after 5 crashes in 10 minutes instead of looping forever. StartLimitIntervalSec=600 StartLimitBurst=5 [Service] Type=forking # systemd user units get a bare environment; claude lives in ~/.local/bin. Environment=PATH=%h/.local/bin:/usr/local/bin:/usr/bin:/bin # tmux (built with systemd support) moves every pane into its own # tmux-spawn-*.scope over the user D-Bus, which would take claude out of this # unit's cgroup — escaping MemoryMax and a clean stop. With no bus to reach, # the move fails harmlessly and claude stays here. Nothing in a session needs D-Bus. Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/nonexistent ExecStart=%h/.local/bin/sessions-ctl _launch %i PIDFile=%t/claude-session/%i.pid ExecStop=/usr/bin/tmux -L claude-%i kill-server Restart=always RestartSec=10 TimeoutStartSec=60 # The box has ~4 GB; keep one runaway session from taking the rest down. MemoryHigh=1200M MemoryMax=1600M [Install] WantedBy=default.target