Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

background-service.md

102 lines7.0 KB

1# Running T3 Code in the background
2​
3Run T3 Code as a background user service on Linux, macOS, or Windows so your host stays reachable without keeping a terminal open.
4​
5## Manage the service
6​
7Install the `t3` CLI first ([Command line](./install.md#command-line)), then run these commands on the host machine:
8​
9| Task | Command |
10| --------------------------------------- | --------------------------------------------------------- |
11| Set up access from other devices | `t3 up` |
12| Check how other devices reach it | `t3 status` |
13| Install and start (or repair) | `t3 service install` |
14| Check status and log path | `t3 service status` |
15| Update to a newer release | `t3 update` |
16| Restart | `t3 service restart` |
17| Stop and remove from startup | `t3 service uninstall` |
18| Remove service, launcher, and downloads | `t3 uninstall` (keeps `~/.t3/userdata` and `service.env`) |
19​
20- Pairing codes are never written to logs; run `t3 pair` or `t3 up` on the host to connect a device.
21- `t3 update` asks before restarting (pass `--yes` in scripts). Pin a version with `t3 update 0.0.42`, switch tracks with `--channel nightly`, or downgrade with `--allow-downgrade`.
22​
23## Local network access
24​
25New services bind to localhost only. Run `t3 up --lan` (sets `T3CODE_LAN=true` in `service.env`) to listen on LAN and Tailscale addresses for direct desktop/mobile connections, or `t3 up --no-lan` to disable it. Anyone on that network can reach the port (gated by pairing). `T3CODE_HOST` overrides `T3CODE_LAN`. Hosted `app.t3.codes` always uses T3 Connect.
26​
27## Configure the service environment
28​
29Add `KEY=VALUE` entries to `service.env` in your T3 home directory (`~/.t3/service.env` by default). Values are literal (quote spaces or `#`; no shell expansion) and survive installs and updates.
30​
31```dotenv
32T3CODE_PORT=3773
33T3CODE_HOST=127.0.0.1
34```
35​
36- `PATH`, `T3CODE_HOME`, `T3_BOOT_SERVICE_UNIT`, and `T3_SERVICE_LAUNCHER_CONTEXT` cannot be overridden here.
37- Run `t3 service restart` after editing (and `chmod 600 ~/.t3/service.env` if it holds secrets).
38​
39## Platform support
40​
41- **Linux**: Requires systemd user services with lingering enabled so T3 Code starts at boot and survives logout.
42- **macOS**: Starts at login, stops at logout. Keep the Mac logged in and awake for unattended access. If agents can't read Desktop/Documents/Downloads, grant Full Disk Access to the `t3` path in `~/Library/LaunchAgents/com.t3tools.t3code.service.plist`.
43- **Windows**: Runs windowless via Task Scheduler (`t3code-<domain>-<user>`) while signed in and auto-restarts on exit. Lock the screen instead of signing out for unattended access.
44​
45> Note: Signing out of T3 Connect does not stop or uninstall the background service.
46​
47## Keep the server responsive under memory pressure (Linux)
48​
49On Linux, agents run at lower priority than the server, but heavy memory use can still trigger the OOM killer. Run as your normal user:
50​
51```sh
52t3 service protect
53```
54​
55It previews system changes, asks for confirmation and `sudo`, and optionally protects Tailscale and SSH too. Run `t3 service restart` for OOM-killer protection to take effect, or `t3 service protect --undo` to remove it.
56​
57When the host is in trouble, the sidebar (or a pill at the bottom of the thread
58list on mobile) says so: **Memory is slowing agents down** (this can happen before
59memory runs out), **Almost out of disk space** (where T3 Code keeps its data and
60worktrees), or **Machine overloaded** (work waiting for a CPU or for the disk).
61A machine that is merely busy shows nothing. With several machines in trouble,
62one notice covers them all. On Linux the warning names the agents using the most
63memory or CPU, and you can force stop one there to free the machine for the
64rest. Their threads also show a warning icon in the thread list.
65​
66You can hide the notice until the problem clears, for an hour, or until tomorrow
67(on mobile, swipe the pill away to hide it until the problem clears). Hiding
68lasts only on that device, and a different problem always shows. A notice hidden
69until the problem clears also shows again if the problem comes back later, or if
70no device was connected to that machine for a while. The thread warning icons
71stay. A machine running an older T3
72Code can't tell when a problem clears, so there only the timed choices are
73offered and a swipe hides the pill for an hour.
74​
75## Troubleshooting
76​
77Run `t3 service status` on the host to see the log path and health checks:
78​
79| Status | Fix |
80| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
81| `linger-disabled` | Run `sudo loginctl enable-linger "$(id -un)"` (or `ssh -t your-server '...'`), then retry setup as your normal user. Never run T3 Code as root. |
82| `linger-unavailable` | Check `loginctl show-user "$(id -un)" --property=Linger` and verify `systemd-logind`. |
83| `user-manager-unavailable` | Run `systemctl --user status` in a login session to verify systemd user support. |
84| `service-disabled` / `service-stopped` | Check the log and `systemctl --user status t3code.service`, then run `t3 service install`. |
85| `restart-pending` | Run `t3 service restart` to switch to the newly installed version. |
86​
87For T3 Connect issues, see [T3 Connect troubleshooting](./t3-connect-troubleshooting.md).
88​
89## Reclaim database space
90​
91T3 Code automatically prunes old internal history while keeping conversations. Older databases that still hold freed space show a **Reclaim** button in **Settings → Maintenance** when at least 1 GiB is reclaimable (pauses the server/agents during repair).
92​
93For manually started servers (or CLI use), stop any hand-started server or desktop app and run:
94​
95```sh
96t3 doctor # Interactive repair (auto-stops/restarts a background service)
97t3 doctor --dry-run
98t3 doctor --fix # Non-interactive recommended repairs
99```
100​
101- Needs free disk space of ~2× active data size (in `TMPDIR`/`/var/tmp` and beside the database). Large databases can take over an hour.
102- `t3 doctor` optionally offers to remove the legacy pre-0.1.0 `state.sqlite` backup only when all active projects and threads exist in the current database (`--fix` never deletes it automatically).