Expand description
Auto-start-at-login registration — issue #2977 Workstream 2,
docs/specs/SPEC_TRAY_OPTIONAL_BACKGROUND_SERVICE_2026_09_04.md §4.
§Opt-in, off by default, and separate from “close to tray”
Nothing here runs unless the user explicitly asks for it. The issue is
emphatic that these are two different decisions: “a user can have
‘close-to-tray keeps it running for this session’ without ‘starts
automatically at every login’ being bundled into the same toggle”. So
auto-start has its own state, its own enable/disable, and is never
implied by AGENTMUX_TRAY or AGENTMUX_BACKGROUND_SERVICE.
§Mechanism per platform, and what was rejected
- Windows — Scheduled Task,
LogonType=InteractiveToken. Not a Windows Service (needs admin to register, and Session-0 isolation means it structurally cannot show a tray icon), and not a bareRunregistry key (no crash supervision, no delay control). - macOS — LaunchAgent plist. This DEVIATES from the governing spec, and
the deviation has a user-visible consequence.
SPEC_TRAY_OPTIONAL_BACKGROUND_SERVICE_2026_09_04.md§4 callsSMAppService“unambiguously current best practice” and notes it is the only path that surfaces correctly in System Settings → Login Items & Extensions. Writing the LaunchAgent directly means the entry may not appear there the way a user expects, which matters more than usual here: Workstream 4 requires that a user be able to see and remove a background service, and Login Items is where they will look.SMAppServiceis only callable through its ObjC interface from inside a bundled, signed app, so adopting it means objc2 bindings plus a bundle identifier that matches the registered agent — real work that cannot be written blind or verified on a non-macOS machine. Recorded as a known gap rather than pretended away: macOS auto-start should move toSMAppServicebefore it is offered to users. (ReAgent P1 on PR #2999.) - Linux — XDG autostart
.desktop.systemd --useris deliberately NOT the default: surviving logout needsloginctl enable-linger, which is a separate, consequential decision the issue says must never be silently enabled.
§Uninstall is a first-class operation (Workstream 4)
WS4 requires “one complete, independently-testable uninstall path that
actually removes the LaunchAgent/Scheduled-Task/autostart artifact — not
just closes the window”. disable() is that path, and is_enabled()
makes it independently checkable: the pair is the whole contract, and
disable() is idempotent so an uninstaller can call it unconditionally.
§Structure
The artifact content (Task Scheduler XML, plist, desktop entry) is
generated by pure functions that take an exe path and return a string.
That keeps the part most likely to be subtly wrong — escaping, schema
fields, the InteractiveToken logon type — unit-testable without
touching the machine’s real login configuration.
Modules§
- login_
item - macOS: start at login through
SMAppService, so the entry shows in System Settings -> General -> Login Items & Extensions where people look for it, and respects the approval they give there (docs/specs/SPEC_START_WITH_OS_2026_09_25.md§3.7, phase 4).
Structs§
- Entry
- The login entry as it stands on this machine.
- Status
--autostart-status --json: what Settings shows next to the switch.
Enums§
- Plan
- What to do to bring the login entry in line with
app:startatlogin(SPEC_START_WITH_OS_2026_09_25.md§3.9). - State
- How the login entry stands (
SPEC_START_WITH_OS_2026_09_25.md§3.8).
Constants§
- APPIMAGELAUNCHER_
OFF_ 🔒PREFIX - How an AppImage’s
Execline starts. - AUTOSTART_
ID - Identifier used for the artifact on every platform: the Scheduled Task
name, the LaunchAgent label’s suffix, and the
.desktopfilename stem. Stable, becausedisable()has to find whatenable()created — including across upgrades, so it deliberately carries no version. - BACKGROUND_
FLAG - The flag every generated artifact passes to the launcher.
- MACOS_
LABEL - Reverse-DNS label for the macOS LaunchAgent, which requires that form.
- PLIST_
CHANNEL_ 🔒KEY - Owning channel, as a plist key launchd ignores.
- STABLE_
EXE_ 🔒ENV - Env var the Linux AppRun and wrappers set to their own path right before they exec the launcher.
- TASK_
CHANNEL_ 🔒MARKER - Marks the owning channel inside the Task’s
<Description>, the only free-text field Task Scheduler keeps verbatim. - XDG_
CHANNEL_ 🔒KEY - Owning channel, as a vendor key (
X-keys are ignored by the session).
Statics§
- MOVED_
FROM 🔒 - Where the AppImage this launcher runs from was before it was moved or renamed, when it was
(
agentmux_common::appimage_record::reconcile, at start). - STABLE_
EXE 🔒
Functions§
- artifact_
path - Where the artifact lives, for the platforms that use a plain file. Not used on Windows, whose artifact lives in the Task Scheduler store rather than a path we own.
- background_
env_ for - Environment the host must receive when the launcher was started with
--background. - background_
requested - Did the launcher get started in background mode?
- between 🔒
- current_
channel - Handle the auto-start CLI verbs, if present. Returns
truewhen one was handled and the process should exit. - current_
status statusof this machine, with the login item’s approval: a registration the person has not allowed (or has switched off) in System Settings isneeds_approval, noton(SPEC_START_WITH_OS_2026_09_25.md§3.8).- decode_
console_ 🔒output schtasks /XMLwrites UTF-16LE when its output is redirected.- desktop_
exec_ 🔒escape - Escape a path for use inside a quoted argument of a desktop entry’s
Exec=value. - desktop_
string_ 🔒escape - Escape a plain desktop-entry string value (
TryExec, vendor keys), per the Desktop Entry spec’s\\,\n,\t,\rescapes. A raw newline would end the line and let a path inject keys, asdesktop_exec_escapeexplains. - desktop_
string_ 🔒unescape - disable
- Remove auto-start registration. Idempotent — succeeds when nothing was registered, so an uninstaller can call it unconditionally without first asking whether the feature was ever turned on.
- enable
- Register auto-start for
exe. Idempotent: re-registering an existing entry replaces it, which is also how an upgrade repoints the artifact at a new install path. - entry_
runs_ from - Does the login entry run a file inside
dir? An uninstaller asks this with its own install folder, so it removes the entry that would be left pointing at nothing (SPEC_START_WITH_OS_2026_09_25.mdG6, G7) and leaves an entry that another install or channel owns alone. Windows paths compare without case. - exec_
prefix 🔒 - What goes before the program in the login entry’s
Execline. An AppImage is run with AppImageLauncher switched off, as the in-app upgrade’s restart does: at login that tool stops a file it hasn’t integrated behind an “Integrate or Run once” window, and AgentMux doesn’t start until someone answers it (#47873). - handle_
cli - is_
appimage 🔒 - is_
enabled - launch_
agent_ plist - macOS LaunchAgent plist.
- login_
start - Was this process started by a login entry? Every artifact passes
--background, and nothing else does. - missing_
target - The file a login entry runs, when it isn’t there: the session skips such an entry without a word
(the desktop entry’s
TryExec), so AgentMux silently stops starting at login. - moved_
from 🔒 - note_
appimage_ start - At start, for an AppImage: put its channel record back beside it if a move or a rename left that behind, and
keep where it is now (
agentmux_common::appimage_record). Remembers where it was, for the login entry to follow. - parse_
desktop_ 🔒entry - parse_
plist 🔒 - parse_
task_ 🔒xml - plan
- Pure decision.
settingisapp:startatlogin,Nonewhen never set.targetisstable_target(),Nonewhen it could not be resolved: only writing needs it, so removing or adopting never waits on it (ReAgent P1 on #3788). - read_
entry - Read the current entry back from the platform.
Nonewhen there is none. - remove_
launch_ 🔒agent_ plist - Remove the login entry written as a file (the LaunchAgent plist, the XDG desktop entry). Succeeds when it is not
there, which is what makes
disablesafe to call unconditionally from an uninstaller. - second_
instance_ opens_ window - A launcher that finds AgentMux already running forwards
open_new_windowto it, so a double-click opens a window. A login entry firing while the user already has AgentMux open must not (SPEC_START_WITH_OS_2026_09_25.md§3.6): it just exits. - set_
moved_ from - Remember where this launcher’s AppImage came from, once per run.
- stable_
target - What the login entry should run: something that survives updates
(
SPEC_START_WITH_OS_2026_09_25.md§3.1), not this process’s own path. - stable_
target_ 🔒from - started_
by_ 🔒login_ task - The Store package’s startup task starts the exe with no arguments, so a login start there is known from how
Windows activated the process, not from
--background. Nowhere else is it ever true. - startup
- What the launcher does first, before anything reads either: takes
AGENTMUX_STABLE_EXEout of the environment (take_stable_exe_env), and notes where an AppImage has been moved from (note_appimage_start). - status
- Pure: the status from what is on the machine.
registeredisis_enabled, which can say yes whenentrycould not be read (an entry this build cannot parse still starts something at login).can_writeis whether this build has a target to point an entry at. - take_
stable_ exe_ env - Read
AGENTMUX_STABLE_EXEand remove it from this process’s env, so no child (host, srv, agent shells, a dev build started from a pane) inherits a path that belongs to this launch.APPIMAGEis not used for the same reason: the AppImage runtime’s copy leaks into every agent shell. - xdg_
desktop_ entry - Linux XDG autostart desktop entry.
- xml_
escape 🔒 - Minimal XML text escaping for the two generated XML documents.
- xml_
unescape 🔒