Skip to content

macOS LaunchAgents and LaunchDaemons ​

Declare LaunchAgents for your macOS user in [bootstrap.macos.launchd.agents]. mise bootstrap, or mise bootstrap macos launchd-agents apply, writes each agent to ~/Library/LaunchAgents/dev.mise.<name>.plist and loads it into your login session.

To run one program in the background on macOS, Linux, and Windows from a single declaration, use a user service instead. Use a LaunchAgent when you need launchd features such as calendar schedules, launch events, queue directories, a process type, or resource limits. A name cannot be declared in both places, because both write the same plist.

For a program that runs at boot, as root or a service account, without anyone logged in, declare a LaunchDaemon instead.

Example ​

Install the program and create any log directories first. my-sync stands in for your own program:

[bootstrap.macos.launchd.agents.my-sync]
program = "~/.local/bin/my-sync"
args = ["--watch"]
run_at_load = true
keep_alive_on_failure = true
environment = { PATH = "/opt/homebrew/bin:/usr/bin:/bin" }
working_directory = "~"
stdout_path = "~/Library/Logs/my-sync.log"
stderr_path = "~/Library/Logs/my-sync.err.log"

Run apply as the user who owns the agent. When that user is logged in to the Mac's desktop, agents load into their gui/<uid> launchd domain.

A user with no desktop login, such as a service account or an account you reach only over SSH, has no gui/<uid> domain. For that user mise loads the agent into the background user/<uid> domain instead and adds LimitLoadToSessionType = Background to the plist, which launchd requires there. The agent runs now, but launchd may not start it again after a restart until the user logs in, and apply warns about this. Once the user logs in at the desktop, the next apply rewrites the plist and moves the agent to gui/<uid>.

sh
mise bootstrap macos launchd-agents apply --dry-run
mise bootstrap macos launchd-agents apply

mise writes ~/Library/LaunchAgents/dev.mise.my-sync.plist and loads it with launchctl bootstrap gui/<uid> (or user/<uid> with no desktop login). The agent starts now, and launchd restarts it after it fails. An agent in gui/<uid> also starts at each desktop login; one installed without a desktop login does so only after an apply has moved it to gui/<uid>, as described above.

The agent gets launchd's environment, not your shell's, so mise activation and tools from [tools] are not on its PATH. Use absolute paths and declare the environment variables it needs. program and args form the argument list directly, without a shell: for pipes or redirection, run /bin/sh -c '...' or a wrapper script.

Run on a schedule ​

start_interval starts the agent every so many seconds. start_calendar_interval starts it at calendar times, using any of minute (0-59), hour (0-23), day (1-31), weekday (0-7, where 0 and 7 are Sunday), and month (1-12). A field you leave out matches every value. For several schedules, use an array:

[bootstrap.macos.launchd.agents.daily-sync]
program = "~/.local/bin/my-sync"
start_calendar_interval = [{ hour = 3, minute = 0 }, { hour = 12, minute = 0, weekday = 1 }]

This runs at 03:00 every day and at 12:00 on Mondays. If you set both start_interval and start_calendar_interval, either one can start the agent.

queue_directories starts the agent whenever one of the listed directories is not empty, and launchd expects the agent to empty them. Each entry must be an absolute path, ~, or a path starting with ~/.

Start on launch events ​

launch_events writes launchd's LaunchEvents dictionary. Nest tables by event stream, then by a name you choose for the event. Properties inside each event use launchd's original, case-sensitive names:

[bootstrap.macos.launchd.agents.usb-handler]
program = "~/.local/bin/device-handler"

[bootstrap.macos.launchd.agents.usb-handler.launch_events."com.apple.iokit.matching".apple-usb]
IOProviderClass = "IOUSBHostDevice"
idVendor = 1452
IOMatchLaunchStream = true

This subscribes to matching Apple USB devices. The program must consume the event stream using xpc_set_event_stream_handler; LaunchEvents is not a general-purpose way to run an arbitrary command on a notification. Use a handler that supports the selected stream.

Event properties preserve strings, booleans, integers, reals, arrays, and nested tables. TOML datetime values are not supported. Quote stream names containing dots so TOML treats each as one key. String values support templates, but ~ in event properties is passed through unchanged.

Keep a program running ​

  • run_at_load = true starts the agent when it is loaded, at apply and at login.
  • keep_alive = true restarts the program after any exit.
  • keep_alive_on_failure = true restarts it only after it exits with an error. Set at most one of keep_alive and keep_alive_on_failure.
  • throttle_interval is the minimum number of seconds between launches (launchd's default is 10).
  • kickstart = true runs launchctl kickstart after loading, which starts the program if it is not already running.

Set the agent's priority ​

process_type sets launchd's scheduling band: Background, Standard, Adaptive, or Interactive. Use Background for work that should yield to you; launchd limits its CPU and disk I/O. Values are case-sensitive. mise warns about any other value and skips the agent, because launchd silently ignores a ProcessType it does not recognize and the job would run in the default band.

nice sets the process's niceness, from -20 to 20. Higher values run at lower priority.

[bootstrap.macos.launchd.agents.indexer]
program = "~/.local/bin/indexer"
start_interval = 3600
process_type = "Background"
nice = 10

low_priority_io = true throttles only the job's disk I/O, the way launchd throttles background work, and leaves its CPU priority alone. Use it for a job that should keep its CPU share but stay out of the way on disk.

Keep background work running after the job exits ​

When a job exits, launchd kills every process left in its process group, so work it started in the background dies with it. abandon_process_group = true lets those processes keep running. Use it for a short poller that starts a longer task and exits:

[bootstrap.macos.launchd.agents.pr-poll]
program = "~/.local/bin/pr-poll"
start_interval = 300
abandon_process_group = true

Raise resource limits ​

launchd starts agents with a soft limit of 256 open files, which a server that holds many connections exceeds. soft_resource_limits sets the limits the program starts with, and hard_resource_limits sets the ceilings it cannot raise them above. Each is a table of core, cpu, data, file_size, memory_lock, number_of_files, number_of_processes, resident_set_size, and stack, written to the plist as launchd's SoftResourceLimits and HardResourceLimits. Set only the limits you need; the rest stay as launchd leaves them. Sizes are in bytes, cpu is in seconds, and a soft limit must not exceed the hard limit for the same key.

[bootstrap.macos.launchd.agents.proxy]
program = "~/.local/bin/proxy"
run_at_load = true
keep_alive = true
soft_resource_limits = { number_of_files = 10240 }
hard_resource_limits = { number_of_files = 65536 }

Use templates ​

String values are Tera templates, rendered with the declaring config's context. That includes entries in args, environment, and queue_directories:

[bootstrap.macos.launchd.agents.my-sync]
program = "{{ config_root }}/bin/sync"
working_directory = "{{ config_root }}"
stdout_path = "{{ config_root }}/log/sync.log"

Here {{ config_root }} is the declaring config's root: the project directory for a project config, or MISE_GLOBAL_CONFIG_ROOT (default $HOME) for the global config. It does not change with the directory you run mise from. A value without template syntax is written unchanged, and ~ expansion still applies after rendering. exec() is not available; see templates in bootstrap.

How configs combine ​

Agents merge by name across the config hierarchy. A more local config replaces the whole declaration for that name; mise does not merge keys across files. An agent that fails validation or whose template fails to render is reported with a warning and skipped, and the other agents still apply.

mise manages only plists in ~/Library/LaunchAgents whose label starts with dev.mise.. It does not touch other agents. Daemons in /Library/LaunchDaemons are declared separately.

Remove an agent ​

Deleting a declaration leaves the agent installed and loaded. To unload it and delete its plist, run mise bootstrap services remove:

sh
mise bootstrap services remove my-sync

The command works whether or not the agent is still declared; if it is, the next mise bootstrap installs it again. Without mise, run launchctl bootout gui/$(id -u)/dev.mise.my-sync and delete ~/Library/LaunchAgents/dev.mise.my-sync.plist.

Preview and apply ​

Check each agent with mise bootstrap macos launchd-agents status, and preview the commands before you apply them:

sh
mise bootstrap macos launchd-agents status            # state of each agent
mise bootstrap macos launchd-agents status --json     # the same, as JSON
mise bootstrap macos launchd-agents status --missing  # exit 1 if any agent is not loaded
mise bootstrap macos launchd-agents apply --dry-run   # print the commands
mise bootstrap macos launchd-agents apply             # apply after a confirmation prompt
mise bootstrap macos launchd-agents apply --yes       # apply without prompting

launchd is a shorter alias for launchd-agents.

Status reports each agent as loaded, unloaded, differs (the plist on disk does not match the declaration), or missing. Apply changes every agent that is not loaded: it writes the plist, unloads the old job if one is loaded, loads the new one with launchctl bootstrap, enables it with launchctl enable, and runs launchctl kickstart when kickstart = true. Unloading stops the agent's running process.

Reference ​

Keyplist keyNotes
programProgramArguments[0]Required; ~ expanded
argsProgramArguments[1..]Passed as written
run_at_loadRunAtLoadStart when loaded
keep_aliveKeepAliveRestart after any exit
keep_alive_on_failureKeepAlive = { SuccessfulExit = false }Restart after a failure; not with keep_alive
start_intervalStartIntervalSeconds
start_calendar_intervalStartCalendarIntervalTable or array of tables with minute, hour, day, weekday, month
queue_directoriesQueueDirectoriesAbsolute paths or ~/ paths
launch_eventsLaunchEventsTables keyed by stream and event name; properties keep their original case
throttle_intervalThrottleIntervalMinimum seconds between launches
process_typeProcessTypeBackground, Standard, Adaptive, or Interactive
niceNice-20 to 20
low_priority_ioLowPriorityIOThrottle disk I/O only
abandon_process_groupAbandonProcessGroupLeave processes the job started running after it exits
soft_resource_limitsSoftResourceLimitsTable of number_of_files, stack, core, ...; see above
hard_resource_limitsHardResourceLimitsSame keys; each soft limit must not exceed its hard limit
environmentEnvironmentVariablesTable of variables
working_directoryWorkingDirectory~ expanded
stdout_pathStandardOutPath~ expanded
stderr_pathStandardErrorPath~ expanded
kickstartNot written to the plistRun launchctl kickstart after loading
restart_whenNot written to the plistA check that must pass before mise reloads a running job; see Restart only when it is safe

Agent names may contain letters, numbers, ., _, and -. Each agent's label is dev.mise.<name>.

On Linux and Windows ​

The section is ignored on other platforms, so one config can serve several machines. status lists each agent as skipped, and apply and the full mise bootstrap do nothing with it.

Troubleshooting ​

To see why an agent is loaded but not running, inspect it with launchd and read its output files:

sh
launchctl print gui/$(id -u)/dev.mise.my-sync
tail ~/Library/Logs/my-sync.err.log

For a user with no desktop login, print user/$(id -u)/dev.mise.my-sync instead. launchctl print shows the job's state, its last exit status, and the program and arguments launchd runs. A program that works in your terminal but fails here usually needs an absolute path or a variable in environment.

LaunchDaemons ​

A LaunchDaemon runs in launchd's system domain: launchd loads it at boot, without anyone logged in, and runs its program as root or as the account in user. The program starts at boot only with run_at_load (or keep_alive); otherwise it starts on its trigger, such as start_interval. Use one for a server or a CI runner on a Mac that nobody logs in to. Declare it in [bootstrap.macos.launchd.daemons] with the same keys as an agent, plus user, group, and requires_paths:

[bootstrap.macos.launchd.daemons."ci.actions-runner"]
user = "mise-ci"
group = "mise-ci"
program = "/opt/mise-ci/actions-runner/run.sh"
working_directory = "/opt/mise-ci/actions-runner"
environment = { HOME = "/opt/mise-ci/home", PATH = "/usr/local/bin:/usr/bin:/bin" }
run_at_load = true
keep_alive = true
stdout_path = "/opt/mise-ci/log/actions-runner.log"
stderr_path = "/opt/mise-ci/log/actions-runner.log"
# load it only once the runner is registered
requires_paths = ["/opt/mise-ci/actions-runner/.runner"]

mise bootstrap, or mise bootstrap macos launchd-daemons apply, writes /Library/LaunchDaemons/dev.mise.ci.actions-runner.plist, owned by root:wheel with mode 0644 (launchd refuses a daemon plist that anyone else can write), and loads it with launchctl bootstrap system. Writing the plist and running launchctl need root, so mise asks for sudo, and only when a daemon has to change: a loaded daemon whose plist matches is left alone. The plist is written through the same privileged helper as [bootstrap.files].

sh
mise bootstrap macos launchd-daemons status            # state of each daemon
mise bootstrap macos launchd-daemons status --json     # the same, as JSON
mise bootstrap macos launchd-daemons status --missing  # exit 1 if any daemon differs from the config
mise bootstrap macos launchd-daemons apply --dry-run   # print the commands
mise bootstrap macos launchd-daemons apply             # apply after a confirmation prompt

Status reports each daemon as loaded, unloaded, differs (the plist's content, owner, or mode does not match), missing, or waiting (see below). launchd reads a plist only when it loads the job, so when the plist changes, apply runs launchctl bootout system/<label>, waits until the job is gone, writes the plist, and loads it again. If a run stops partway, the daemon is left unloaded, and the next run loads it. An unloaded daemon is enabled with launchctl enable and loaded with launchctl bootstrap, and kickstart = true runs launchctl kickstart after that. Unloading stops the daemon's running process. To wait until it has nothing in progress, such as a CI runner between jobs, set restart_when.

Who it runs as ​

user and group write UserName and GroupName. Without user the daemon runs as root; without group it runs with the user's primary group. The account must exist before mise loads the daemon: apply, and the dry run, stop with an error that names the daemon when it does not. [bootstrap.users] and [bootstrap.groups] create accounts only on Linux, so on macOS create a service account beforehand, for example in a hook that runs before packages.

A daemon gets neither your environment nor your home directory. Its program, working_directory, stdout_path, stderr_path, and queue_directories must be absolute paths: mise does not expand ~ for a daemon, and rejects a value that starts with ~ or is relative.

Wait for a file before loading ​

A daemon with keep_alive = true whose program is not installed yet would be restarted over and over. requires_paths lists absolute paths that must all exist before mise writes and loads the daemon. Until then, status reports it as waiting for <path>, apply leaves it alone, and it does not count as missing for --missing. Run apply again once the path exists, for example at the end of the script that installs the program. A path the current user cannot see is checked with sudo, but only for a daemon that has to change: one that is already loaded with a matching plist is reported as loaded without checking.

requires_paths is checked only by mise. It is not written to the plist, so once the daemon is loaded, launchd keeps running it even if a path goes away.

To run several copies of a daemon, such as one runner per slot with the count set per host, declare it once in a [bootstrap.repeat] block.

Remove a daemon ​

Deleting a declaration leaves the daemon installed and loaded, and mise bootstrap unapply does not remove daemons. To remove one:

sh
sudo launchctl bootout system/dev.mise.ci.actions-runner
sudo rm /Library/LaunchDaemons/dev.mise.ci.actions-runner.plist

Daemons merge across configs, render templates, and are skipped on other platforms the same way as agents. To see why one is not running, use sudo launchctl print system/dev.mise.ci.actions-runner.

Keyplist keyNotes
userUserNameAn account name, not a numeric UID. Root when unset
groupGroupNameA group name, not a numeric GID. The user's primary group when unset
requires_pathsNot writtenAbsolute paths that must exist before mise loads the daemon
Any agent keyAs for agents~ is not expanded

See also ​

  • Bootstrap for where agents and daemons fall in the run order.
  • Services for background programs declared once for every platform.
  • macOS defaults for user preferences.
MIT LicenseCopyright © 2026jdx.dev