Scripting mbm2: run, models, sessions, export, import, stats, todo
mbm2 run, mbm2 models, mbm2 session, mbm2 export, mbm2 import and mbm2 stats work
without opening the interface. While the interface is open they use its engine and leave it running;
otherwise each starts the local mBm engine in the current directory for the one command, as the
interface does, and stops it when the command ends. Their options, output and exit codes are v1's
mbm commands', so scripts written for mbm run keep working with mbm2 run, on Linux, macOS
and Windows alike.
| Command | Does |
|---|---|
mbm2 run [message..] [options] |
Sends one message and prints the reply |
mbm2 models [provider] [--verbose] |
Lists the models the engine can run, as provider/model |
mbm2 session list [-n|--max-count <n>] [--format table|json] |
Lists this project's sessions, newest first (100 at most) |
mbm2 session delete <sessionID> |
Deletes a session |
mbm2 export <sessionID> [--sanitize] |
Prints a session as JSON |
mbm2 stats [--days <n>] [--tools <n>] [--models [n]] [--project <id>] |
Token use and cost |
mbm2 import <file|url> |
Stores a session from a JSON export or a share URL under its own id, in this project |
mbm2 todo [list] |
The project work log docs/todo/current.md, with add, done, archive, index and history --from-git: v2's own command, with no v1 counterpart (below) |
The commands in this table are the client's command table's usage lines; mbm2 help <command> (or
mbm2 <command> --help) prints each one's purpose, flags with their defaults and examples. The
command index lists every command.
mbm2 run
$ mbm2 run "Explain what internal/cart/tax.go does in two sentences"
> safe · deepseek-v4-flash
→ Read internal/cart/tax.go
It computes the sales tax for a cart: each line's rate comes from the region table and the
result is rounded half up to the cent.
The reply goes to stdout when stdout is a pipe or a file, so mbm2 run "…" > answer.txt keeps only
the answer; the > agent · model header, tool lines and errors go to stderr. On a terminal the
reply is printed to stderr between blank lines, as v1 does.
| Option | Effect |
|---|---|
-m, --model <provider/model> |
The model, for example -m mbm/deepseek-v4-flash |
--agent <name> |
A primary agent (build, safe, plan); an unknown one or a subagent prints ! agent "…" not found. Falling back to default agent and uses the default |
-c, --continue |
Continue the newest top-level session of this directory |
-s, --session <id> |
Continue this session; Error: Session not found and exit 1 if there is none |
--fork |
Fork the session -c or -s chose and continue the fork |
--title [title] |
The new session's title; --title alone uses the first 50 characters of the message |
--format json |
One JSON line per event instead of text: step_start, text, reasoning, tool_use, step_finish, error, each with timestamp and sessionID |
--thinking |
Also print the model's reasoning as Thinking: … |
--dangerously-skip-permissions |
Approve every permission request that is not denied. Without it, each request is refused: ! permission requested: edit (b.txt); auto-rejecting |
--auto |
Run the session in auto mode: the rules, the hard guardrails and the small-model judge decide what would ask. What they hand to a person is refused without ending the turn, ! auto mode escalated (git push --force can overwrite or delete what others pushed): bash (git push --force origin main); auto-rejecting, and the agent carries on. With -s/-c the existing session is switched to auto. mbm2 auto log <session> lists the decisions |
--strict-exit |
Make the exit status tell how the run went: 1 when the run hit an error (the Error: … line, or an error line with --format json), 3 when a permission request was auto-rejected, 0 otherwise. Without it run exits 0 in both cases, as v1 does. See Exit codes |
--share |
Share the session and print its link (~ https://…) |
-f, --file <path> |
Attach files or directories, relative to --dir (or this directory); it takes every path after it, so put the message first or end the paths with --. The agent reads it before it answers: a text file's content, a directory's listing, an image or PDF for a model that takes them. A missing path prints Error: File not found: <path> and exits 1 |
--dir <path> |
Run in that directory. With --attach it is a path on that server, and a new session is made there, with that directory's configuration |
--attach <url> |
Use a server that is already running instead of starting one; -u/-p or MBM_SERVER_USERNAME/MBM_SERVER_PASSWORD authenticate. Not needed for the interface's own engine on this computer: run finds it by itself |
--port <n> |
The local engine's port (any free one by default) |
--command <name> |
Run a command with the message as its arguments: init, review, manager, maxcontext, handoff (it saves the note without printing it) or one of your own (.mbm/command/<name>.md, mbm.json command; Custom commands) |
Piped input is added to the message on a new line. run reads it until it ends, so a script that
starts mbm2 run with a pipe it never closes should give it </dev/null; after 3 seconds without
the end run says so on stderr (mbm2 run: waiting for stdin to end …):
$ git diff | mbm2 run "Review this diff for bugs" --agent plan
$ mbm2 run -c "Now write the tests for it" --dangerously-skip-permissions
$ mbm2 run --format json "List the TODOs in src" | jq -r 'select(.type=="text") | .part.text'
$ mbm2 run "Does the code match the docs?" -f internal/cart/total.go docs/
In a script that must stop when the agent could not do its job, add --strict-exit:
$ mbm2 run --strict-exit "Fix the failing test in internal/cart" || echo "run failed: $?"
> safe · deepseek-v4-flash
! permission requested: edit (internal/cart/tax.go); auto-rejecting
…
run failed: 3
Not available on the engine yet, each refused with Error: --<flag> is not served by the mBm engine yet and exit 1: --interactive (use the interface instead) and --demo. --variant <name> picks the
model's variant (its reasoning effort, as /variants lists them) for the message or the command.
--auto-correct, --no-auto-correct, --auto-correct-max and --auto-correct-confirm are
accepted as v1 spells them, and v1 reads none of them; mbm2 says so on stderr for each one given
(--auto-correct is not acted on: the auto-correct loop is the agent's auto_correct setting …) and
runs on. The loop itself is the agent's auto_correct setting
(Custom agents).
Sessions, export and models
$ mbm2 session list
Session ID Title Updated
────────────────────────────────────────────────────────────────────
ses_ffe5dfc025260ffeJdwICtzQlMBa Fix rounding in tax.go 3:04 PM
ses_ffe5dfc025361ffes1TSLfXaTOyi Explain the cart package 9:12 AM · 11/20/2026
$ mbm2 session list -n 1 --format json
[
{
"id": "ses_ffe5dfc025260ffeJdwICtzQlMBa",
"title": "Fix rounding in tax.go",
"updated": 1795363542410,
"created": 1795363500102,
"projectId": "1a2b3c4d5e6f",
"directory": "/home/me/src/shop-api"
}
]
$ mbm2 export ses_ffe5dfc025260ffeJdwICtzQlMBa --sanitize > session.json
Exporting session: ses_ffe5dfc025260ffeJdwICtzQlMBa
$ mbm2 session delete ses_ffe5dfc025361ffes1TSLfXaTOyi
Session ses_ffe5dfc025361ffes1TSLfXaTOyi deleted
$ mbm2 models mbm
mbm/deepseek-v4-flash
mbm/m-free-1
--sanitize replaces every message, tool output, file path and title with a marker such as
[redacted:text:prt_…]. export needs a session id (v1's interactive picker is not built).
models --verbose adds each model's details as JSON; models --refresh is refused, as the model
list is the one bundled with the release. On a terminal session list opens in less.
mbm2 stats
$ mbm2 stats --days 7 --models 3
┌────────────────────────────────────────────────────────┐
│ OVERVIEW │
├────────────────────────────────────────────────────────┤
│Sessions 12 │
│Messages 148 │
│Days 7 │
└────────────────────────────────────────────────────────┘
…
All projects by default; --project "" is the current project. --models alone shows every
model, --models 3 the top three; --tools 5 keeps the five most used tools.
mbm2 todo
$ mbm2 todo add Fix the redirect -p P1 -s "Login page"
Added td_8KQ2mZ0aLp in docs/todo/current.md (1 open, 0 done)
$ mbm2 todo done redirect
Checked td_8KQ2mZ0aLp in docs/todo/current.md (0 open, 1 done)
$ mbm2 todo archive Login page
Moved 1 done item to docs/todo/history/2026-11-24-login-page.md
INDEX.md updated
| Command | Does |
|---|---|
mbm2 todo [list] |
The items by section with their ids, and the open and done counts |
mbm2 todo add <text> [-p P1..P5] [-s <section>] |
Adds an open item; without -s it goes under ## Inbox |
mbm2 todo done <id|text> |
Checks the item an id, an id prefix or words of its text name; words matching several items change nothing |
mbm2 todo archive <topic> |
Moves the checked items to history/<date>-<topic>.md and writes INDEX.md |
mbm2 todo index |
Writes INDEX.md again; unchanged files give the same bytes and nothing is written |
mbm2 todo history --from-git |
One history/<date>-snapshot.md per day git changed current.md, only where none exists |
--format json |
The engine's answer as JSON |
The log is in the directory todo.dir names in mbm.json, else docs/todo, under the project's root,
in the directory the command runs in. A usage error prints the usage and exits 1 before any engine is
started; an item that does not exist, or a request the engine refused, prints mbm2 todo: <reason>
and exits 1. With MBM_SERVER_BIN naming v1's runtime the command exits 1, since v1 has no work log.
Todo lists covers the file format, archives, INDEX.md and the SYNOTI layout.
Exit Codes And Limits
| Code | When |
|---|---|
0 |
The command finished. run also exits 0 when the model failed (the Error: … line on stderr says why) or a permission was auto-rejected, unless --strict-exit is given |
1 |
run --strict-exit: the run saw an error (session or provider error); this wins over a rejected permission |
3 |
run --strict-exit: a permission request was auto-rejected and no error happened; add --dangerously-skip-permissions or run the interface to approve it |
1 |
A usage error (You must provide a message or a command, --fork requires --continue or --session, an unknown option), a session or provider that does not exist, a refused flag, a request the engine refused, an engine that did not start, or one that did not answer within 20 seconds (Error: the engine at <url> did not answer within 20s) |
130 |
Stopped by Ctrl-C or SIGTERM (timeout, kill). A turn the run started is aborted; a message waiting behind another window's turn stays queued. The process ends within 3 seconds of the signal, or at once on a second one |
mbm2 import
$ mbm2 export ses_4f2a9c > cart.json # on one computer
$ mbm2 import cart.json # on another
Imported session: ses_4f2a9c
$ mbm2 import https://tui.mbm.mn/share/Xk3p9
Imported session: ses_7d1e02
The session keeps its id and moves to the current directory's project; importing it again adds only
the messages it lacks. A file that cannot be read or is not JSON prints File not found: <file>, a
URL that is not a share link Invalid URL format. Expected: https://tui.mbm.mn/share/<slug>, and an
empty share Share not found or empty: <slug>; all three exit 0, as v1's do. A document the engine
cannot store (no ses_ id) prints Error: … and exits 1.
With The Interface Open
Only one engine owns the session store, and every mbm2 of yours shares it: the interfaces in
all your terminals and these commands. The engine records its address in the store, readable only
by you, and these commands (and every mbm2 rag command) talk to it, so
mbm2 session list in another terminal shows the sessions the interface holds. From another
directory every command answers for the directory it runs in, not the interface's: session list,
stats --project "" and import use that directory's project; run makes its session there,
with that directory's configuration, and its tools work there; models lists that directory's
providers and models; mbm2 rag acts on that repository; and mcp list, plugin, providers,
acp and github run use that directory's MCP servers, plugins, providers and sessions (see
Managing mbm2). The interface's own sessions are untouched. A record left by an
engine that crashed is ignored: the command starts the engine itself, and an interface opened
while it runs joins it and keeps it running after the command ends.
Published from revision f88fc66f 2026-11-30