Log inGet started

The tool system

Updated December 5, 2026

What a tool is for

A tool earns its place by doing one of three things:

  • Makes a one-off easy. One call that would otherwise be several: resolve an asset, spawn an entity, add a Model, add a collider, position it → one spawnModel(...).
  • Packs a whole workflow into one call. "Convert every material in this scene to the ps1 shader", "bake every probe in the scene", "run this input sequence". Brute force is fine: tools run on the authoring path, not the gameplay hot path.
  • Hands the agent context an API wouldn't. Spawn a model and get back its position, bounds, and neighbouring entities in one shot.

Its inputs must be settable by an agent blind to how the engine works underneath: words, intents, nil meaning "all", proxies already in hand. If using a tool requires understanding the system beneath it, it's the wrong tool.

A tool composes over a capability, the underlying engine API the tool body itself calls: the entity / component / asset globals, the modules.api.engine.* modules, and the rest of the engine surface. Gameplay logic lives in those capabilities (or a module built on them) and is called directly; a tool calls the same capability and wraps it in a schema an agent can discover and invoke. That split is what lets a tool stay freely renamable: gameplay code reaches for the capability, the agent reaches for the tool.

A tool's command line

Add your own shell command, with flags

A tool in a toolbox is how a world adds a command its shell runs: the tool add in the toolbox changelog is the command zero changelog add -m "msg" file.md, with no shell code written. Create the toolbox and tool (see "Anatomy, and creating one" below), then add --!flag lines and a render.luau to shape the command line and its output.

zero <toolbox> <tool> <args> reads the words after the tool name from the tool's own schema, so the signature is also the shell's grammar. Everything below is written beside the function; zero <toolbox> <tool> --help prints what the schema states.

  • Parameters are read by position, or by name as --name value / --name=value. Positional words fill, in order, the parameters no flag or name has filled; when there are fewer words than open parameters, a parameter a --!flag targets is left to its flag and the words fill the rest (add docs/CHANGELOG.md binds file and asks for message; add "x" docs/CHANGELOG.md binds both). A string or Path slot takes the word as written; a number or boolean slot reads it strictly; a union of string literals accepts its members; any other slot reads JSON, true / false / null, a number, a comma run of numbers (0,5,0), or text. A declared string stays text. In any other slot, a word that starts with { or [ and does not parse as JSON is refused (exit 2) with the word and the parse error, and the tool does not run. Written as a JSON string ('"[x]"'), the same text reaches such a slot as a string.
  • Every field of the trailing options table is a flag, spelled in kebab-case or camelCase (--dry-run, --dryRun). A boolean field is a switch: --force sets it, and a following true or false is its value (--force false). A field or parameter with no type, or typed any, takes the next word as its value unless that word starts with --; with no word after it, it is set to true. Every other field takes the next word.
  • --!flag <spellings> <target> names a flag the fields do not give. <spellings> lists the flag's names, short ones included; <target> is a parameter (message) or a field of the options table (opts.mode).
  • --!flag <spellings> <target> = <literal> is a switch that sets its target to the literal ("hard", 3, true).
  • --!rest <target> takes every word after -- into a list target.
  • tools.Path (export type Path = string) marks a parameter, a list element or a field as a file path. The shell resolves the word against its own directory, so . is that directory and sub is <directory>/sub.
  • A short flag takes its value as the next word (-m "fix it"). The long form also accepts --message=fix.
  • --opts '<json>' still binds the whole options table as JSON.
  • Words past the parameters are refused (exit 2) naming the first surplus words: a value that has spaces is quoted (-m "Fix the door"). A word that reads as a JSON table ({...) after the last parameter is the options table.
export type ResetOpts = {
    --- How far the reset reaches.
    mode: ("soft" | "mixed" | "hard")?,
    --- Files to reset instead of the whole head.
    paths: { tools.Path }?,
}

--!desc Move the head to a revision, or reset the named paths.
--!arg target Revision to move to.
--!arg opts How far to reset, and which paths.
--!flag --hard opts.mode = "hard"
--!flag --soft opts.mode = "soft"
--!rest opts.paths
--!example "HEAD~1", { mode = "soft" }
typed function M.reset(target: string?, opts: ResetOpts?): any
$ zero cliDoc reset --hard HEAD~1
$ zero cliDoc reset --soft HEAD~2 -- sub .
$ zero cliDoc reset --mode soft
$ zero cliDoc reset --opts '{"mode":"soft"}'

zero cliDoc reset --help lists them as:

Flags:
  --hard             → opts.mode = "hard"
  --soft             → opts.mode = "soft"
  --mode <("soft" | "mixed" | "hard")?>         How far the reset reaches.
  --paths <{ Path }?>                           Files to reset instead of the whole head.
  --                 → opts.paths (every word after the flags is read into it)

Paths: opts.paths; relative paths are read from the shell's directory.

tools.parseCommandLine(identity, words, { cwd }) runs the same reading from Luau and returns the bound arguments or a refusal with a reason and a message.

What the tool prints

A tool folder may hold a render.luau beside init.luau. It returns a function over the tool's result: a returned string is the output, and a table { out, err?, exit? } sets standard output, standard error and the exit status. out is printed byte for byte.

return function(result)
    if result.message == "" then
        return { out = "", err = "empty message\n", exit = 3 }
    end
    return "committed: " .. result.message .. "\n"
end

Without a render.luau the shell prints the result as JSON. tools.render(identity, result) runs the file from Luau, and tools.get(identity).hasRender states whether it exists.

Exit status

StatusMeaning
0The tool ran and the render stated no other status.
the render's exitThe status the render returned.
1The tool or its render raised, or the result could not be read. A raise whose message opens with <toolbox>.<tool>: is printed under zero <toolbox> <tool>: with that identity once.
2The command line could not be bound: an unknown flag, a missing or bad value, a flag given twice, a value of the wrong type, too many words, or a required argument skipped. The message names the flag and points at --help.

A tool that wants a user mistake to exit 2 declares the value as a required (non-optional) parameter: the shell refuses a missing one with exit 2 (missing <name>) before the tool runs. A check the tool makes in its body and answers with a raise exits 1.|

Three surfaces, one registry

A tool's identity is <toolbox>.<name>, a tool inside a toolbox. The same live registry answers on three surfaces, so reach for whichever one you already hold. None is a subset of the others: each can browse, read a signature, and run.

zero, the shell command, whenever you have bash. Browsing, reading a signature and running are all the same command, and --help answers at every level, so you can walk from "what exists" to a correct call without leaving the shell:

zero                                    # every toolbox and what it covers
zero entityOps                          # the tools in one toolbox (same as `zero entityOps --help`)
zero entityOps fromAsset --help         # one tool: every argument, its type, whether it's required
zero entityOps fromAsset cube           # run it
zero --search 'low poly tree'           # the search over everything published (short: -k): the counts of its two lists first, then `suggested_resources`, then the hits
zero --search --tools spawn             # the tool search, published content included

Arguments are named (--name value) or positional in signature order, and --help prints both runnable forms for the tool in front of you. A value that reads as JSON is passed as JSON (12, true, [0,5,0], {"internal":true}), a bare run of numbers like 0,5,0 becomes an array, and anything else is a string. A value that starts with { or [ and does not parse is refused with the parse error (exit 2), unless its parameter is a string, which keeps it as text; written as a JSON string ('"[x]"') it is text for any parameter that reads JSON. The dotted identity works too: zero entityOps.fromAsset cube.

tool_exec, the MCP tool call, when you're driving the engine from outside. search_tools finds the tool, and tool_exec runs a short JavaScript script against the same registry: zero.<toolbox>.<tool>(...) or tools.use("<toolbox>", "<tool>", ...), each call a promise to await. Arguments are positional in signature order, or one object naming the parameters, the same names --name value uses in the shell. The script's return is the answer's value; a tool that fails ends the script with ok = false and failure.kind = "tool". Several calls in one script keep their intermediate results out of the conversation:

// search_tools { query = "spawn asset" } found toolbox "entityOps", tool "fromAsset"; the tool_exec script:
const body = await zero.entityOps.fromAsset("cube", { name: "ragdoll", position: [0, 0, 0] })
const red = await tools.use("MaterialAuthor", "fromColor", { color: [1, 0, 0], opts: { name: "Red" } })   // by name
return { body, red }

An object whose keys are not parameter names is the tool's single table parameter, so capture.oneshot(opts) takes { pass: "depth" } as that table. Where the first parameter holds a table, an object mixing the two is that table written inline: the keys naming no parameter, and a key naming the first parameter itself, are its fields, and the keys naming a later parameter fill that parameter's slot. Where the first parameter cannot hold a table, an object mixing parameter names with other keys is refused with the parameter list.

describe_tool { toolbox, tool } is the MCP spelling of --help: one tool's full schema.

Both take a tool's identity in every form a listing prints it: toolbox and tool apart, a dotted tool = "entityOps.fromAsset", or the bare tool name when one toolbox holds a tool of that name (tool = "fromAsset" reaches entityOps.fromAsset). A name several toolboxes hold is refused naming each of them (spawn is held by entityOps, procgen and others), and so is a toolbox's own name, with the tools it holds.

tools.use(toolbox, tool, ...), from Luau, when you're authoring in code. Inside an execute() call or an editor/authoring script, this runs a tool and unwraps the envelope: the raw value on success, a raised error on failure, so you write against the return value directly with no .ok / .value threading:

local r = tools.use("entityOps", "fromAsset", "cube", { name = "ragdoll" })
-- r.id is the entity id; a failing tool raises

Because toolbox and tool are asset identities, a tools.use(...) call written with literal names is statically resolved: the LSP checks the toolbox and tool exist, and the call is captured as a dependency edge so content that ships with a tools.use call carries its tool deps with it. Library toolboxes resolve by root: tools.use("@<lib>::<toolbox>", "name", ...).

Where a tool may run

Tools write the VFS, create persistent assets, make HTTP calls, and queue heavy jobs. That is authoring work, not per-frame work, and it is the line: a tool belongs in an authoring context (an execute() call, the shell, an editor tool or panel), never in runtime code. Runtime code (a component, a scene entrypoint, anything that ticks each frame or runs on load) reaches for the underlying capability, not a tool. The engine enforces this statically:

  • A component reaches for a capability, not a tool. Calling a tool from a component is an error. A tool can opt in with declare { componentSafe = true } at the top of its init.luau, but that switch is an explicit "I acknowledge I'm using this against its intent": it's heavily frowned upon, there only for the rare case where you genuinely can't avoid duplicating the logic. The right move is almost always to extract the operation into a module the component calls directly.
  • A tool reaches for a module, not another tool. Using tools.use inside a .tool/.toolbox source is an error; shared logic goes in a require'd module.

So when a guide shows a component spawning an entity, driving a light, or reading input, it uses the capability (entity.spawn, modules.api.engine.lighting, zinput); the tool form is for the interactive authoring you do from the shell and from execute().

Toolboxes, the namespace

Tools live inside a toolbox, which gives each tool its <toolbox>.<name> identity. A toolbox can hold a shared.module for helpers more than one of its tools reuse, reached with require(".shared") from inside the toolbox. Browse the built-in toolboxes with zero in the shell, search_tools with no arguments over MCP, or asset.list("toolbox") from Luau: each gives a grouped overview of every toolbox and what it is for.

The right tool often lives in a toolbox you would not guess (re-skinning a hierarchy is under appearance, screenshots under capture, scene structure under scene, opening a file or your own text in the editor for the user to read under show), which is why browsing is worth a call before searching for a name you have imagined.

The result contract is system-enforced

A tool body returns a raw value (or calls error(msg) to fail). The asset type wraps every call into the { ok, value | error, durationMs, tool } envelope and times it. The contract lives in the type, not in each tool, so every tool behaves the same way: returning a value is success, error(...) is failure, and the envelope is added for you. tools.use, a tool_exec script and zero unwrap it; tools.tryUse reports the outcome as { ok, value, error } instead of raising.

Anatomy, and creating one

A tool is an ordinary asset folder: <toolbox>.toolbox/<name>.tool/ with an init.luau. The schema lives entirely in that Luau: the typed function signature is the tool's signature, and the --!desc / --!arg / --!return / --!example annotations above it are its per-function docs; tags live in the sibling .metadata. The function whose name matches the .tool folder stem is the canonical entry. Edit the file like any source and it hot-reloads, so a toolbox added to the world after boot is listed and callable on every surface with no rebuild.

local M = {}

export type PlaceOpts = { position: { number }?, parent: EntityRef?, count: number? }

--!desc Spawn a primitive and return the entities it created.
--!arg kind Primitive shape to spawn.
--!arg opts Placement and repetition options.
--!return The spawned entity refs.
--!example "cube", { count = 4 }
typed function M.spawn(kind: ("cube" | "sphere" | "plane"), opts: PlaceOpts?): { EntityRef }
    -- ...
end

return M

The typed keyword is what makes the signature real, and every exported tool function carries it. It compiles to a dispatch wrapper that checks each argument at call time and raises a message naming the argument, the expected type, and what arrived. A plain function is checked by nothing — including one written function M.spawn(kind: string), where the annotation informs the LSP and enforces nothing. Such a tool takes any input, runs its body on it, and returns a success envelope, which is why a wrong call to it looks like a working one.

--!closed above the declaration says its records spell every key it reads. A record type is the minimum shape an argument must have, so by default a table carrying keys beyond it is taken and the extra keys reach the body, where a tool that reads its options by name looks at none of them — a misspelled rooots or a key borrowed from a sibling tool is dropped and the call reports success. Written above the typed function, --!closed turns that into a refusal naming the key and the fields the record does spell, the answer a wrong field type already gets. It reaches every table argument of that declaration, through T?, (T), the branches of a union and a named alias — and stops at a field's own type, which is a different declaration and answers for itself. Write it on a tool whose declared record is the whole set of keys it reads; leave it off one that hands an argument on to something that reads more — pp.add reads its options against the property schema of the effect being added, which a static record cannot spell, so it names that schema's own set in its refusal.

--!desc Assign a material to every renderable under the named roots.
--!closed
typed function M.swapMaterials(material: string | AssetRef<material>, opts: SwapMaterialsOpts?): AssignSummary
appearance.swapMaterials: argument #2 'opts': no field 'targets' — the fields
it reads are: first, match, roots

Type each argument as narrowly as the operation accepts: a fixed set of accepted words is a literal union (("cube" | "sphere")), never string; a structured argument is a named export type, never { [string]: any }; an entity or asset is EntityRef / AssetRef<kind>, never any. An op-keyed dispatch table is several tools wearing one signature — split it. Reserve any for a value the tool genuinely does not constrain.

Those annotations are what zero <toolbox> <tool> --help and describe_tool print, so writing them well is what makes the tool usable by the next reader.

To make tools programmatically, tools.createToolbox and tools.create write the folder for you (lsp.describe gives their exact signatures). Whatever the route, the live surface is the reference:

tools.list()                 -- toolboxes and their tools
tools.get("entityOps.spawn") -- a tool's full schema

Reading a built-in tool's init.luau is the best way to see how one is built, and asset.inspect("<toolbox>.<name>") shows any tool's schema and docs. The asset system behind tools (identities, hot-reload, sharing) is in the assets guide.

  • documentation
  • guide