Headless, JSON, RPC and the SDK
parmanu runs without its screen in three ways: -p for one message, --mode rpc for a session another program drives, and the SDK for a session inside your own TypeScript program. All three build the same chat session as the screen: the same settings, permissions, hooks, extensions and MCP servers.
-p: one message
anu -p "fix the failing test" one agent run (as before), then exit
anu -p --output-format text "what does src/add.ts do?" one chat message, the answer on stdout
anu -p --output-format json "..." one result object
anu -p --output-format stream-json "..." one JSON line per event, then the resultPlain -p is the agent run it has always been. Any of these flags runs the message on the chat engine instead:
| Flag | Meaning |
|---|---|
--output-format text|json|stream-json | how the answer is printed |
--include-partial-messages | stream-json also prints the model's text as it streams (delta lines) |
-c, --continue | continue the last session in this repo |
--session <id|path> | continue that session |
--allowedTools <rules> | allow rules for this run, such as "Bash(npm test *)" Read |
--disallowedTools <rules> | deny rules for this run |
--allowed-tools and --disallowed-tools work too. A rule list may be split by commas or spaces; spaces inside parentheses stay. Nobody can answer a permission question in -p, so a tool that would ask is refused: allow it with --allowedTools or --permission-mode.
The result object:
{"type":"result","subtype":"success","is_error":false,"result":"the answer","status":"done","verified":false,
"session_id":"20261201T101500-ab12","duration_ms":4210,"num_turns":1}stream-json starts with {"type":"system","subtype":"init","session_id":…,"model":…,"cwd":…,"mcp_servers":[…], "permission_mode":…,"version":…}. Each event follows as {"type":"user"|"assistant"|"ledger"|"todos"|"agent"|"note"|…}, and the result line comes last. The exit code is 0 when the turn is done, 2 for an infrastructure error (the model could not be reached) and 1 otherwise. Warnings go to stderr.
--mode rpc: a session over JSON lines
anu --mode rpc reads one JSON command per line on stdin and writes JSON lines on stdout. It starts with {"type":"ready","session_id":…,"model":…}.
| Command | Does |
|---|---|
{"type":"prompt","id":1,"text":"…"} | sends a message; its response comes when the turn ends, with the result |
{"type":"steer","text":"…"} | adds a message to the running turn |
{"type":"follow_up","text":"…"} | queues a message for when the turn ends |
{"type":"abort"} | stops the running turn |
{"type":"state"} | the session id, model, turns, busy, mode and queue |
{"type":"set_model","model":"…"} | switches the model |
{"type":"set_mode","mode":"plan"} | switches the permission mode |
{"type":"new_session"} | starts a new session |
{"type":"answer","id":"q1","answer":…} | answers a question |
{"type":"close"} | ends the session (so does the end of stdin) |
Every command may carry an id; its response is {"type":"response","id":…,"command":…,"ok":true,"result":…} or {…,"ok":false,"error":"…"}. Events come as {"type":"event","event":{"type":"assistant",…}}.
When the session needs a person it sends {"type":"ask","id":"q1","kind":…} and waits for the answer:
| kind | Comes with | Answer |
|---|---|---|
tool | request: {tool, detail, rule?, always?} | "yes", "always" or {"no":"why"} |
plan | plan, back | {"go":"<mode>"} or {"keep":"feedback"} |
ask | trigger: {summary, options, default} | the answer's text |
destructive | cmd | true or false |
The SDK
import { createSession, RpcClient } from 'parmanu/sdk';
const s = await createSession({ cwd: '/path/to/repo', model: 'qwen3.6-35b', allowedTools: ['Bash(npm test *)'] });
s.subscribe((e) => console.log(e.type));
const res = await s.prompt('why does the test fail?');
console.log(res?.summary);
await s.close();
const c = RpcClient.spawn({ cwd: '/path/to/repo' });
c.onAsk = (q) => (q.kind === 'tool' ? 'yes' : null);
await c.ready;
console.log((await c.prompt('hi')).summary);
await c.close();createSession reads the settings like anu does; model, baseUrl, apiKey, permissionMode, allowedTools, disallowedTools, mcpConfig, sessionId and an asker (who answers questions; by default nobody) are options. RpcClient spawns anu --mode rpc (or command) and wraps its commands as methods.
createSession runs the agent inside your process, so it needs bun. From Node, parmanu/sdk gives you RpcClient, with TypeScript types; createSession there rejects and tells you to use RpcClient.
This page is built from docs/headless.md in parmanu 0.4.14.