Use tmux to run long-lived background commands as background “tasks” like vite dev servers, commands with watch mode.
Each task should be a tmux session that the agent can start, inspect, and stop via CLI.
ALWAYS give long and descriptive names for the sessions, so other agents know what they are for.
Run a background task (e.g. Vite dev server) without blocking:
tmux new-session -d -s project-name-vite-dev-port-8034 'cd /path/to/project && npm run dev --port 8034'Every time you are about to start a new session, first check if there is one already.
List all background tasks (sessions):
tmux lsYou can assume sessions that do not have names were not started by you or agents so you can ignore them
Kill a background task:
tmux kill-session -t vite-devNever attach to a session. You are inside a non TTY terminal, meaning you instead will have to read the latest n logs instead.
Fetch the last N log lines for a task without attaching (returns immediately):
tmux capture-pane -t vite-dev:0 -S -100 -pExample pattern for a coding agent:
-
Start a task:
tmux new-session -d -s build 'cd /repo && npm run build' -
Poll logs:
tmux capture-pane -t build:0 -S -80 -p
-
List all running tasks:
tmux ls
-
Stop a task when done:
tmux kill-session -t build