Background Jobs
| You want | Ask the agent | What happens |
|---|---|---|
| A long command to run while the conversation goes on | "run the test suite in the background" | bash starts it as a background job and answers at once with its job id and output file |
| A command that is taking too long to move aside | nothing, or press ctrl+b |
A foreground bash or task still running after 2 minutes becomes a background job; ctrl+b moves it at once |
| To hear when it ends | nothing — it is automatic | When the job exits, a notification with its exit code and last lines arrives in the session and the agent reacts to it |
| To wait for a point in it | "start the dev server in the background and wait until it is listening" | monitor waits inside the turn for a line matching a pattern, the job's exit, or a timeout |
| Several pieces of work done at once | "split this into independent parts and delegate them in parallel" | task with background: true starts one subagent per part; each answers at once with a job id and its child session |
| Subagents that edit files without touching your tree | "do each part in its own worktree" | task with isolation: "worktree" runs the subagent in .mbm/worktrees/<job> on branch mbm2/<job> |
| A worktree task's commits in your branch | "merge that task" | task_merge asks you to approve, showing the branch, its commits and files; only then are its commits applied and committed |
| To hand a task off yourself | /delegate <task> |
A background task in its own worktree with your text as the brief, no question to the agent; /delegate lists, merges and stops them (Parallel work) |
| To stop one job | "stop the dev server" | job_stop ends the job's whole process group, or a task's subagent turn |
| To stop all of it | delete the session, or quit mbm2's runtime | Every job of the session is stopped, its whole process group included |
A background job belongs to the session that started it. It runs on the runtime host (your
machine in local mode, the server with --attach), in its own process group, with its output in a
file under the runtime's data directory. The agent is told never to poll it: it does not sleep and
re-check, it waits to be notified. How to split a job into such tasks, brief them and check their work
before merging is in Parallel work.
Example: Tests While You Keep Talking
-
Ask:
run go test ./... in the background, then tell me about the config package. -
The transcript shows the
bashcall answering at once:Started background job job_01a2… Output file: …/job/ses_…/job_01a2….log -
The agent goes on answering your question about the config package.
-
When the tests finish, a notification arrives as a message in the session:
<job-notification> Background job job_01a2… failed. Description: Run the test suite Command: go test ./... Exit code: 1 Output file: …/job_01a2….log Last 20 lines of output: --- FAIL: TestLoad (0.00s) … </job-notification> -
If the agent was idle, the notification starts a new turn: it reads the failure and proposes a fix. If it was busy with your question, it finishes that first and then answers the notification in the same turn.
Example: A Command That Turns Out Long
You do not have to know in advance that a command is slow. A foreground bash command or task
that is still running after 2 minutes moves to the background by itself: it keeps running, the
call answers with its job id, and the agent goes on. Its result arrives as a notification, like any
background job's.
-
Ask:
build the release binaries. -
The agent runs
make releasein the foreground. Two minutes later the call answers:The command was still running after 120 s, so it moved to the background as job job_01d4…. Output file: …/job/ses_…/job_01d4….log It keeps running; its result arrives in this session as a <job-notification> when it exits. … -
The job's output file holds everything the command printed, from its first line. When it exits, the notification arrives and the agent reads it.
Do not want to wait two minutes? While a foreground bash or task runs, the status row under the
prompt reads esc interrupt ctrl+b background. Press ctrl+b and the call moves at once (the
palette's "Move to background" does the same). The toast says Moved to the background. At any other
time ctrl+b moves the prompt's cursor left, as before. Rebind it in mbm2.json as
"keybinds": {"background_call": "ctrl+alt+b"}, or turn it off with "none".
Change the 2 minutes in mbm.json, or turn the automatic move off with 0:
{ "experimental": { "background_after_ms": 300000 } }
MBM_EXPERIMENTAL_BACKGROUND_AFTER_MS in the runtime's environment wins over the file. A config
reload applies to the next call. Moving a call never asks a new permission: it already had them.
Example: Start A Server, Check It, Stop It
-
Ask:
start the dev server in the background, wait until it listens, then curl /health and stop it. -
The agent calls
bashwithbackground: true, thenmonitorwith a pattern such aslistening on. The turn waits — no polling, nosleep— until that line appears:Job job_01b7… printed a matching line: listening on :8080 The job is still running. -
It runs
curlin the foreground, reports the answer, and callsjob_stop:Stopped job job_01b7….
monitor waits at most 10 minutes (2 by default). When it sees the job exit, it answers with the
same text the notification would carry, and no separate notification follows. Press esc to abort
the turn as usual: the wait ends, the job keeps running.
You can also just type while the agent waits in monitor. Your message ends the wait: monitor
answers A user message arrived; the job is still running., the agent answers you in the same turn,
and calls monitor again if it still needs to wait. The job is not touched.
Example: Two Subagents In Parallel, Each In Its Own Worktree
-
Ask:
add input validation to the API and write the missing docs for the config package; do both in parallel, each in its own worktree, and have them commit. -
The agent calls
tasktwice in one step, each withisolation: "worktree". Both answer at once:Started background task job_01c3… (@general, session ses_…). Output file: …/job/ses_…/job_01c3….log Worktree: /path/to/repo/.mbm/worktrees/job-01c3… on branch mbm2/job-01c3… from 4f2a9c1d0b7e. -
Both subagents work at the same time, each in its own checkout of your current commit. Your working tree is not touched. The agent does not poll them; it waits.
-
As each one finishes, a notification arrives and wakes the agent:
<job-notification> Background task job_01c3… completed. Description: Add API validation Agent: @general (session ses_…; resume it with task_id ses_…) Worktree: /path/to/repo/.mbm/worktrees/job-01c3… Branch: mbm2/job-01c3… (from 4f2a9c1d0b7e) Commits: 9b1e2f3 validate request bodies Changed files: api/validate.go | 42 +++++ 1 file changed, 42 insertions(+) The worktree stays until it is merged. To bring its commits onto the current branch, call task_merge … Output file: … <task_result> Added validation for … </task_result> </job-notification> -
The agent treats the report as a claim: it reads the branch's diff, runs the checks where the report does not show them passing, and calls
task_merge. mbm2 asks you, every time, even when your permission rules allow everything; the question names the task, its branch, its commits, the diff stat and the commit message. Approve (Allow once), and the commits are applied to your current branch, committed (only the task's files), and the worktree and branch are removed. Reject, and nothing moves. Nothing is ever pushed. The agent then runs the project's checks on your branch.
A task without isolation runs in the session's own directory, so use it for work that only reads,
or for one editing task at a time. A worktree task starts from your last commit: changes you have
not committed are not in it. When a task is stopped, its session deleted or mbm2 quits, the
subagent's turn is aborted and the worktree and branch stay; merge them later with task_merge, or
remove them with git worktree remove and git branch -D.
See And Stop Jobs In mbm2
| You want | Do | What you see |
|---|---|---|
| To know something runs | look at the status row under the prompt | 1 job (or 3 jobs) while jobs of this session run; nothing when none do. Opening a session lists its jobs, so a job started before you attached is counted too |
| The list | type /jobs, or press ctrl+alt+j |
Background jobs: running jobs first, then finished ones, each with its description, kind (bash, task) and running 12s, exit 0 · 3s, stopped · 3s or lost |
| Every tab's jobs at once | type /activity, or press ctrl+alt+o |
each tab with its jobs under it, running first; return on a job opens its output in that tab, s stops it (Workers) |
| Only the tasks, with merge | type /delegate |
Delegated tasks: each task's subagent and running 12s, to merge · 3m or merged 9b1e2f3; enter reads the report, m merges a finished worktree task, s stops (Parallel work) |
| A job's output | enter on its row |
the last 200 lines of its output, read from the runtime; esc goes back to the list |
| To stop one yourself | s (or x) on a running row, then Confirm |
the job's processes are ended and the row says stopped |
A finished job's notification is not shown as a message you wrote. The transcript draws one line:
▸ ✓ job_01a2… completed · exit 0 · Run the test suite
Click it to open the notification (command, exit code, output file and last lines); click again to
close it. ✗ marks a failed job. Notifications never enter your prompt history, so up in the
prompt only walks what you typed. Rebind the key in mbm2.json as "keybinds": {"jobs_panel": "ctrl+alt+z"}.
The output view asks the runtime for the lines, so it shows them the same way when mbm2 is attached to
a runtime on another machine. When the runtime cannot answer (the job's session was deleted, or the
server is not mbm2's runtime), the view says Output unavailable: and why.
What A Job Records
| Field | Meaning |
|---|---|
| Status | running, then completed (exit 0), failed (any other exit), stopped (stopped, or its session deleted) or lost (the runtime closed or restarted while it ran; the next start offers it in Work to continue) |
| Exit code | The command's exit code; none when a signal ended it, and none for a task |
| Task | For a background task: the subagent, its child session and, with a worktree, the worktree, branch and base commit, and the merge commit once merged |
| Output file | All of its output, stdout and stderr together; the notification carries only the last 20 lines |
Permissions
A background command asks exactly what the same command asks in the foreground: the bash
permission for each command in it, and external_directory for paths outside the project
(Permissions and questions). A background task asks the task permission, as a
foreground one does. task_merge always asks you (permission task_merge): an allow rule does
not skip the question, a deny rule refuses every merge, and "always" approves only that merge. A
stopped job sends no notification.
Limits
-
The
timeoutof a foreground command does not apply; a job runs until it exits or is stopped. -
POST /session/{id}/backgroundmoves the session's running foreground calls to the background and answers{"moved": N};ctrl+bcalls it. -
The runtime lists a session's jobs at
GET /session/{id}/job, stops one atPOST /session/{id}/job/{job}/stopand answers a job's last lines as plain text atGET /session/{id}/job/{job}/output?tail=N(N from 1 to 1000, 200 by default, from the file's last 64 KiB); its/capabilitiesreportsfeatures.jobs. The TUI's jobs list is built on them. -
POST /session/{id}/taskwith{"prompt": "…"}(and optionaldescription,agent,model,isolation) starts a background task without a model turn and answers{"job": …, "warning"?: …};POST /session/{id}/job/{job}/mergeasks thetask_mergequestion on the session and answers 202, and the job'sjob.updatedcarriestask.mergedortask.mergeError./capabilitiesreportsfeatures.delegate./delegateis built on them.$ curl -s "$RUNTIME_URL/session/ses_…/job/job_01a2…/output?tail=3" compiling build ok all 12 tests passed -
The runtime serves Linux and macOS. Windows builds compile the background path but do not run it.
-
A notification still waiting when the runtime stops is not kept; the job's record is, as
stopped.
Published from revision f88fc66f 2026-11-30