Plugin guides
nanocode agent runtime
Run OpenClaw agent turns through nanocode, the Codex and Claude agent loops in WebAssembly
Read when: You want an agent to run its turns through nanocode inside the Gateway process; you need configuration examples for the nanocode runtime; you are checking what the nanocode runtime supports today and what it does not.
The @openclaw/nanocode plugin registers a nanocode agent runtime. A session
on this runtime runs each turn in nanocode, the Codex
and Claude agent loops compiled to WebAssembly, inside the Gateway process. No
CLI or container starts per session.
nanocode owns the agent loop, its shell and its files. OpenClaw still owns sessions, model selection, credentials, tool policy, the visible transcript, and the mapping from OpenClaw sessions to nanocode sessions.
For the broader model, provider and runtime split, start with Agent runtimes. Measurements are in nanocode runtime experiments.
Requirements
- A model route that speaks OpenAI Responses (
openai-responses) or Anthropic Messages (anthropic-messages). These are the two wire formats nanocode speaks. - No request overrides on that route (headers, parameters, payload switches). The runtime does not claim such routes.
- The plugin loaded and enabled. It is not published to npm or ClawHub yet;
load it from a checkout with
plugins.load.paths.
Configuration
Route a provider, or one model, through the nanocode runtime. This example
uses NVIDIA's Responses route for Nemotron:
{
plugins: {
load: { paths: ["/path/to/openclaw/extensions/nanocode"] },
entries: { nanocode: { enabled: true } },
},
models: {
providers: {
nvidia: {
baseUrl: "https://integrate.api.nvidia.com/v1",
api: "openai-responses",
agentRuntime: { id: "nanocode" },
models: [{ id: "nvidia/nemotron-3-ultra-550b-a55b", name: "Nemotron 3 Ultra 550B" }],
},
},
},
agents: { defaults: { model: "nvidia/nvidia/nemotron-3-ultra-550b-a55b" } },
}
The runtime is explicit only: auto never selects it. The plugin has no
options of its own.
nanocode reserves the tool name tool_search, so the model sees OpenClaw's
search tool as openclaw_tool_search. The transcript and tool policy use
tool_search.
How a turn runs
| Step | What happens |
|---|---|
| Session | Each OpenClaw session keeps one nanocode database at <agentDir>/nanocode/<sessionId>.sqlite, and its nanocode runtime stays open between turns. It is reused while the provider, model, base URL, instructions and tools stay the same, and reopens from the database otherwise. Idle sessions close after 5 minutes; at most 256 idle sessions stay open, plus those in use. A reset starts the session afresh. A changed model route also starts nanocode afresh, without the conversation so far. |
| Model calls | nanocode's requests go out through the model's own guarded transport, with the credential OpenClaw prepared: the provider's network policy (configured local endpoints included), proxies, timeouts and connection pool. |
| Instructions | The agent's developer instructions are built as on the other runtimes, through the prompt hooks: tool guidance, reply and safety guidance, the agent's workspace files (AGENTS.md, SOUL.md and the rest), and the conversation context. Plugins' prompt hooks can add context, replace the instructions or narrow the turn's tools. |
| Gateway tools | The session's OpenClaw and plugin tools are offered to the model. Tools it rarely needs sit behind tool search, as on the built-in runtime: the model finds them with tool_search and runs them with dispatch_action. Each call runs through the Gateway's tool path, so tool policy, approvals, hooks and receipts apply. A failed call returns to the model as text. |
| Shell and files | nanocode's own shell and file tools work in /workspace. |
| Transcript | Each tool call and result, and each assistant message, is written to the OpenClaw transcript in the order it happened. |
| Streaming | Reply text streams token by token to live clients; tool steps show as they start and finish. |
Workspace
Each session has its own /workspace. Its files live in that session's
nanocode database, persist across turns, and are removed with the session.
The shell runs inside the Gateway process over those files only:
- It starts no host process and cannot read the host's disk.
- It has no network.
curlandwgetrefuse. - Python, WebAssembly commands and GitHub cloning are off.
The workspace does not include the agent's OpenClaw workspace directory.
When a run's tool policy restricts tools, as it does for subagent runs, nanocode's own shell and file tools are left out. The run gets exactly the OpenClaw tools the policy allows.
Swarm engine agent API
The plugin serves the agent API that a swarm engine (the
swarms tree engine) expects from its
gateway, at /nanocode/v1/agents on the Gateway's HTTP port. Calls need the
Gateway token. Each agent and each worker it spawns is an ordinary Gateway
session on the Gateway's configured model.
| Route | What it does |
|---|---|
POST /v1/agents |
Creates an agent for the caller's gateway-app. A model given as provider/model is used; otherwise the default agent's model. A git URL names the gateway that hosts the swarm's repositories. |
PATCH /v1/agents/<id> |
Replaces the agent's instructions. |
POST /v1/agents/<id>/turns, GET …/turns/<id> |
Starts an orchestrator turn, and reports its state and answer. |
GET, POST /v1/agents/<id>/subagents |
Lists the agent's workers; spawns one. A spawn with a key already used returns the same worker. An output_schema asks for one JSON object. |
POST …/subagents/<n>/budget |
Records the worker's budget. |
POST …/subagents/<n>/close |
Stops a running worker with chat.abort. A finished worker keeps its output. |
POST …/subagents/<n>/messages |
Runs the message as the worker's next turn, once its run has finished. |
- An orchestrator turn gets no tools. A worker gets three tools for its
swarm's repository when its agent was created with a
gitURL, and none otherwise; its answer is its output. - Agents and workers are kept in the plugin's state, so they survive a Gateway restart. A worker's result is recorded once its run finishes.
- A run the Gateway restarted under reports
interrupted, and the engine runs that node again. An orchestrator turn checked only after a restart reportsinterruptedtoo. - An agent belongs to the
gateway-appthat created it; other apps get 404. spent_usdis always 0: model cost is not metered per worker yet.- Steering, side questions and event streams are not served. Each answers with the status that sends the engine to its fallback: a turn, or polling.
Worker repository tools
A worker has no machine, so it reads and writes its swarm's repository through
the git API of the gateway named by its agent's git URL, as the agent's
gateway-app:
| Tool | Call to the git host | Answer |
|---|---|---|
git_files |
GET /p/<wallet>/<app>/git/<repo>/files?ref= |
Every file path. |
git_read |
GET /p/<wallet>/<app>/git/<repo>/read?path=&ref= |
The file's text. |
git_commit |
POST /v1/git/commit {name, branch, files, message} |
The new commit's sha. |
refdefaults tomain.repositorymay be left out when the swarm has one repository (POST /v1/git/list);<wallet>comes fromGET /api/keys/me.- The tools are optional plugin tools, granted only to swarm worker runs. A
worker run gets exactly these three and no other tool, nanocode's own shell
and files included. The exact surface needs the
plugin-subagent-exact-toolsentries inproduct/server/changes.json; a Gateway built without them refuses the worker run instead of widening it. - The calls carry no key, so the git host must accept the Gateway's calls
without one, as the loopback stand-in in
bench/swarmdoes.
Limitations
- Sandbox and workspace-only policies are refused. Select the
openclawruntime for those sessions. - Live steering of a running turn is not supported. Wait for the turn to end.
- The Gateway's own coding and shell tools are not offered; nanocode's workspace tools replace them.
sessions_yieldis not offered.- The
llm_inputhook is not called for nanocode turns yet. - Tool-result middleware does not apply. It is registered per runtime, and core
has no
nanocodeentry for it. - A message-tool delivery marked final does not stop nanocode's loop early.
- Each open session holds about 16 to 21 MB of Gateway memory.
- Changing the model route mid-session starts nanocode without the conversation so far; the OpenClaw transcript keeps it.
- Instructions that change mid-session, such as an edited
SOUL.md, reach the model as a new developer message before the next turn. Models may follow them less strongly than instructions present from the start. - Every session runs in the Gateway's main process. See the capacity results in nanocode runtime experiments.
Related
- Agent runtimes
- nanocode runtime experiments
- Muse Code agent runtime