Documentation / HTTP API
HTTP API
The daemon owns all task state. The dashboard, the natamux command and the agents’ hooks all use this API.
Base URL and auth
Section titled “Base URL and auth”-
Base URL:
http://127.0.0.1:4317by default (NATAMUX_PORTchanges the port). In the Docker test stack, the API is also under/apion the published port. -
Send the token in a header on every request:
Terminal window curl -H "Authorization: Bearer $NATAMUX_TOKEN" http://127.0.0.1:4317/tasks -
GET /healthneeds no token and answers{"status":"ok"}. -
A wrong or missing token gets 401.
The agent token
Section titled “The agent token”The terminals of each task get that task’s own token, the agent token, in NATAMUX_TOKEN. It looks like T-42.<secret>. The daemon keeps it in memory only, so after a daemon start new shells get new tokens. Deleting the task ends its token at once. When the task becomes Done or Cancelled, its token ends 60 seconds later, together with the terminal tickets it asked for. When the token ends, its open /events socket and the terminal sockets opened with its tickets close (close code 4401); a task reopened before then keeps it, and new shells of a task reopened later get a new token. Agents and the natamux command in a task terminal use it, so the history shows what an agent did.
Every route has a name for what it does (for example task.read.own or git.push.own). A route without one answers 403 to the agent token, so a new route stays closed until it gets one. The agent token of a task may call only:
- the routes under
/tasks/<its id>that have a name, so notDELETE,fan-outorci-approve; - reads of its direct subtasks:
GET /tasks/<id>gives onlyid,title,state,stage,parentId,pr,prStatus,stageSinceandbranch; the events, review comments, files and attachments of the subtask are readable as for the desktop; GET /tasks: its own task in full and its direct subtasks in the short form above. Other tasks are not listed;GET /jobs,/activity,/usage,/diffstatsand/workspaces/preparing, with only the rows of its own task;GET /repos: only the id and name of its own task’s project, no folders.GET /repos/:id/settings,/repos/:id/skills,/git/branchesand/git/remote-branchesonly for that project; another project answers 403;GET /events: only the messages of its own task, and the task messages (task.created,task.updated,task.changed) of its direct subtasks, each with only the short form above and no event.jobs.changed,repos.changedandlimits.changedare not sent;POST /taskswithparentIdset to its own task. Arepoother than the parent’s, or adependsOnoutside its own task and its direct subtasks, answers 403;PATCH /tasks/<its id>:dependsOnonly on its own task and its direct subtasks;repoorparentIdin the body answers 403;POST /hooks/:agent. The hook is for the token’s task; theX-Natamux-Taskheader and the folder are not used;POST /limits/:agent, whichnatamux statuslinesends for Claude Code.
GET /templates and GET /limits answer 403: they have no task to cut them to. Everything else answers 403 forbidden, and the daemon log gets one line agent-api: denied <action> <route> task=<own task>, with no body, query or token, and with control characters escaped. With the audit log on, every refusal of an agent token also writes one agent-api.denied line to it, also one a route makes after this check. At most two requests with a large body (POST /tasks, POST /workspaces, PUT /tasks/:id/file) are read at once; others wait.
In Strict mode with agentApi.mode: scoped, the agent token gets only these actions: task.read.own, task.update.own, event.post.own, stage.report.own, hook.post, limits.post, subtask.create, subtask.read.status, terminal.ticket.own, files.rw.own, workspace.commit.own and agent.message.own. agentApi.grants can add git.push.own, pr.create.own, issue.create.own, agent.start.own, agent.reopen.own, workspace.create.own, rollback.own, subtask.read.workspace (the files of direct subtasks), events.subscribe, repo.read.own and tasks.list. With requireHumanForPush (the default), git.push.own is never given. The dashboard reads (/jobs, /activity, /usage, /diffstats, /workspaces/preparing) answer 403, and GET /events takes the agent token only in the Authorization header, not in ?token=. The push, pull request and issue routes check the grant again in their handler.
With the agent token:
POST /tasks/:id/eventsrecordssource: agent, whateversourcethe request names.- Stage actions record
source: agent. Every send-back by the agent counts formaxSendBacks, with or without aterminal. - These answer 403
forbiddenand change nothing:POST /tasks/:id/eventswithreview.approved,stage.approved,stage.passed,stage.skippedorstate.overridden, and with the events only the daemon sends:stage.checked,stage.started,stage.reopenedandpr.mergedPOST /tasks/:id/fan-outPOST /tasks/:id/stagewithapprove,skiporpass. The one exception: the script of a command stage passes it with a one-time ticket in theX-Natamux-Stage-TicketheaderPUT /tasks/:id/ci,PUT /tasks/:id/skip,PUT /tasks/:id/workflowPUT /repos/:id/settingsGET /repos/:id/trust,POST /repos/:id/trust
To do these from a script, use the daemon’s own token, not the one in a task terminal.
POST /tasks/:id/stage with report for a stage that has a command answers 409 conflict and changes nothing: such a stage passes when its command passes.
Main endpoints
Section titled “Main endpoints”| Method and path | Meaning |
|---|---|
GET /tasks?state=<state> |
List tasks |
POST /tasks |
Create a task (title is required). An optional model is passed to the task’s agent as --model; see Models |
GET /tasks/:id |
One task |
DELETE /tasks/:id |
Delete the task, its notes and its history. A workspace and its branch are removed too, also when the branch has commits that are not merged. Answers 409 when that workspace has changes that are not committed, and the task, the worktree and the branch stay. ?force=true discards those changes and deletes anyway |
PATCH /tasks/:id |
Change title, description, priority, labels, dependsOn or model. A model of null or "" clears it |
GET /tasks/:id/events |
The event log of a task |
POST /tasks/:id/events |
Send an event { source, type, payload? }. Answers { task, accepted } |
POST /tasks/:id/stage |
A stage action { action, stage?, terminal?, to?, reason? }. Actions: approve, reopen, skip, pass, fail, report, start |
PUT /tasks/:id/ci |
Whether a stage waits for CI before it passes { stage, on }. Answers 400 when the stage does not offer it |
PUT /tasks/:id/skip |
Whether a stage not reached yet is skipped when the task reaches it { stage, on }. Answers 400 when marking the current stage or an earlier one or the context stage, and for any change on a task that is over |
PUT /tasks/:id/workflow |
Whether a stage runs as a workflow the next time it starts { stage, on }. Answers 400 when the stage does not offer it or the agent is not Claude Code |
POST /tasks/:id/workspace |
Create the worktree and branch. Body { base?, branch? }. branch is 1 to 255 characters and a valid branch name, else 400. Answers 409 when a local branch of that name is checked out in another worktree, and for a mainCheckout task that was detached |
DELETE /tasks/:id/workspace?deleteBranch=true |
Remove the worktree. Answers 409 when it has changes that are not committed; &force=true discards them and removes anyway. A mainCheckout task is only detached: its terminals end and its stage files are archived; the folder, its changes and its branch stay |
POST /tasks/:id/agent |
Start an agent { agent, prompt?, base?, branch? }. branch works as on POST /tasks/:id/workspace, for a task without a workspace |
POST /tasks/:id/agent/reopen |
Start the agent of Terminal 1 of a done or cancelled task again, on its last session: { task }. The task keeps its state. Answers 409 when the task is not finished, has no workspace or no agent, or an agent runs in Terminal 1 |
GET /tasks/:id/changes |
Files changed in the workspace. The answer is kept for 5 seconds; ?fresh=1 reads git now |
GET /tasks/:id/graph |
The history of the task branch next to the base branch. Kept and ?fresh=1 as for changes |
POST /tasks/:id/commit-message |
A commit message for the changes, by the task’s agent: { message, source, agent, reason? }. source is draft when the agent failed and the message is a simple one; reason says why. Answers 409 when nothing changed |
POST /workspaces |
Make a task with a worktree and optionally start an agent. The body can have base and branch. With worktree: false, the task works in the project folder (the main checkout): its workspace is that folder, branch the branch checked out there, and mainCheckout is true; nothing is checked out, base and branch are not used, and the agent starts at once. Answers 409 and makes no task when another open task of the project works in its main checkout. Set mode to single-agent with a known agent for only Context and Agent; omit it for the project’s full pipeline. An optional model is passed to the task’s agent as --model (see Models). An invalid branch, mode or model answers 400 and no task is made. Answers 202 with the task as soon as it is made; the worktree and agent come after (see workspace.preparing) |
GET /workspaces/preparing |
The workspaces being made, and the step of each: { preparing: { "T-0001": "checkout" } } |
POST /hooks/:agent |
Where an agent’s hook posts. Always answers 200 {} for a known agent |
GET /repos |
Projects Natamux manages, and the daemon’s worktree folder: { repos, worktreesDir }. A project with its own worktree folder has worktreesDir. Each project has trusted: whether its commands are approved |
POST /repos |
Add a project { path, name?, worktreesDir? }. worktreesDir is an absolute folder for the project’s worktrees; it is made when missing. Answers 400 when it is not absolute or cannot be made |
DELETE /repos/:id |
Forget a project. Any project can be removed. Answers 409 while it has workspaces |
GET /repos/:id/settings |
The settings of a project: settings, error, path, text (the text of .natamux.json, or null without a file) and version (none without a file) |
PUT /repos/:id/settings |
Save the settings to .natamux.json. Send the version you read in the header If-Match: <version>. Answers { settings, version }. Answers 409 conflict when the file changed since that version. Keys of the file that Natamux does not know are kept. The saved commands count as approved, unless a setup script or an agent config file changed since the last approval. Such a save approves only that content: it does not cover later changes the way POST /repos/:id/trust does |
GET /repos/:id/trust |
The commands of a project that run on this machine: { trusted, covered, hash, commands, setup, agentFiles }. A command is { where, text }; a setup script or an agent config file is { file, text }. A project with no commands is trusted, and so is a project you approved once, also after a change (Strict mode: only the approved content). covered is true once you approved the project with POST, and always in Strict mode. While it is false the app asks once per project: after you add it, before Start a task, and in the project settings. A client that gets no covered (an older daemon) reads it as true. With ?task=<id> it reads that task’s worktree and adds the changed files |
POST /repos/:id/trust |
Approve the commands { hash }, with the hash GET gave. Answers the new view. Answers 409 conflict when the commands changed since. With ?task=<id> it approves that task’s worktree; outside Strict mode this is also the one approval of the project |
GET /security |
Strict mode: { strict, keys, ignored, warning, isolation }. Each key is { value, blocked, reason }. isolation is { mode, backend, abi, ok, reason } for this daemon run. Any token may read it, also an agent token |
PUT /security |
Save Strict mode with a body in the shape of security.json. Daemon token only: an agent token gets 403. Answers 400 for a key looser than its Strict value, else the new state. Sends security.changed |
GET /support-bundle |
The support bundle: { createdAt, daemonVersion, os, arch, uptimeSecs, security, tasks, log }, no task text. Daemon token only: an agent token gets 403 |
GET /repos/:id/skills |
The skills of every agent for the project: { skills, notices }. A skill is { name, description, origin, agents, path }, and origin is project, plugin or user. A notice says, for example, that a plugin is on but not installed |
The task is named in a hook by the X-Natamux-Task header. The X-Natamux-Terminal header names the terminal.
Models
Section titled “Models”A task’s model is optional; without it the agent uses its own default. It is 1 to 100 characters of A-Z a-z 0-9 . _ - : / @ [ ], after trimming, and does not start with -. Anything else answers 400 invalid_request with the issue at ["model"], and POST /tasks and POST /workspaces make no task. Natamux keeps no list of model names: a well-formed but wrong name reaches the agent, which reports it.
The daemon adds --model '<model>' when it starts the task’s agent, a built-in agent or a custom one on a built-in base. A stage with another agent gets none, and a stage whose args name a model (--model, --model=, -m) keeps its own.
More endpoints
Section titled “More endpoints”Files, git, GitHub, terminals and templates.
| Method and path | Meaning |
|---|---|
GET /tasks/:id/files |
The stage files of a task: { files } |
GET /tasks/:id/files/:name |
One stage file, such as spec.md: { name, text }. Answers 404 when it does not exist |
PUT /tasks/:id/files/:name |
Replace a stage file { text }, for example to fix the spec before you approve it |
GET /tasks/:id/attachments |
The files attached to a task: { attachments } |
GET /tasks/:id/attachments/:name |
One attachment. Images come with their type, any other file downloads |
GET /tasks/:id/ended-shells |
The last screens of the terminals of a done or cancelled task: { shells }. Each has name, agent, stage, session (the agent’s last session, or null), endedAt and text |
GET /tasks/:id/changes/file?path=<file> |
The diff of one changed file |
GET /tasks/:id/changes/image?path=<file>&side=original|modified |
One side of a changed image |
GET /tasks/:id/blame?path=<file>&side=original|modified |
Who last changed each line: { path, tracked, commits, runs }. modified (the default) is the file in the worktree, original a changed file at the last commit. Each commit has sha, author, time (unix seconds) and summary; a line not committed has a sha of 40 zeros. Each run is { start, count, commit }: lines from start (0-based) and the index of their commit. tracked is false, with no runs, for a file git does not track. Answers 413 for a file larger than 1 MB |
GET /tasks/:id/tree?path=<folder> |
One folder of the worktree: { entries }. No path is the root. .git is never listed |
GET /tasks/:id/file?path=<file> |
One file of the worktree: { path, text, binary, tooLarge, version } |
PUT /tasks/:id/file?path=<file> |
Save a file that exists { text }, with the version you read in If-Match. Answers 409 when the file changed since |
POST /tasks/:id/agent/message |
Paste a comment into the agent’s terminal { text }. Answers 400 when no agent runs there |
GET /tasks/:id/review-comments |
The review comments of the task: { comments }, by file then line. Each has id (c1, c2, …), path, side (old or new), start and end (1-based lines; both 0 for the whole file), quote, body, state (draft, sent or resolved), createdAt, sentAt, resolvedAt and outdated (true when the quoted code is gone). Each comment follows its code when the file changes |
POST /tasks/:id/review-comments |
Add a draft { path, side, start, end, body }: { comment }, status 201. body is 1 to 5000 characters. Answers 400 for lines outside the file or end before start |
PATCH /tasks/:id/review-comments/:cid |
Change a comment { body?, state? }: { comment }. body only while it is a draft. state is resolved (from sent) or sent (from resolved). Answers 409 otherwise, 404 for an unknown id |
DELETE /tasks/:id/review-comments/:cid |
Delete a comment in any state. Answers 204 |
POST /tasks/:id/review-comments/send |
Write .natamux-task/review-comments.md, paste one prompt into the agent’s terminal and mark every draft sent: { task, comments }. Answers 409 when there is no draft or no agent runs there |
POST /tasks/:id/commit |
Commit all changes { message } |
POST /tasks/:id/rollback |
Put changed files back as they are in the last commit { paths } (1 to 5000): { files }. A new file is deleted. Answers 404 for a path that is not changed, and 409 for a conflict; then nothing changes |
POST /tasks/:id/rollback/undo |
Bring back the files of the last rollback as they were before it: { files }. Answers 409 when there is nothing to undo |
POST /tasks/:id/push |
Push the task branch |
POST /tasks/:id/pull-request |
Open the pull request: { task } |
POST /tasks/:id/pull-request/refresh |
Ask GitHub now for the state of the pull request, instead of waiting for the next check |
POST /tasks/:id/issue |
Open a GitHub issue for the task now |
PUT /tasks/:id/issue |
Link an issue that exists { provider, key, url } |
POST /tasks/:id/fan-out |
Run more tries of a task { count, start? }. count is 1 to 5 |
GET /tasks/:id/terminals |
The open terminals of a task: { terminals, agents, lanes, programs, restoring, closing, shells }; shells maps each open terminal to its shell id |
DELETE /tasks/:id/terminals/:terminal |
Close one terminal. :terminal is its number |
POST /tasks/:id/terminal/ticket |
A one-time ticket for the terminal WebSocket |
GET /templates |
The saved task templates: { templates } |
POST /templates |
Save a template |
POST /templates/:id/tasks |
Make a task from a template |
GET /github/issues?repo=<id> |
The open issues of a project: { issues } |
POST /github/issues/import |
Import issues as draft tasks { numbers, repo? }. Up to 100 numbers |
GET /git/branches?repo=<id> |
The branches of a project, for Branch from |
GET /git/remote-branches?repo=<id> |
The branches of origin as { branches: ["origin/<name>"] }, also ones never fetched. Asks origin over the network; no origin remote gives an empty list |
GET /activity |
What the agent of each task does now, from its last hook |
GET /usage |
Tokens and estimated cost of each task: { usage: { "<taskId>": { tokens, costUsd, unpricedModels, stages: [{ stage, agent, model, input, cacheRead, cacheWrite, output, costUsd }] } } }. costUsd is an estimate at API list prices, null when no row has a price. stage is "" for work on no stage. Answers before the login PATH |
GET /jobs |
The background jobs that run now, oldest first: { jobs: [{ id, kind, label, taskId, startedAt }] } |
GET /diffstats |
The size of the changes of every workspace |
GET /custom-agents |
Your custom agents: { agents: [{ id, base, command }] }. See Custom agents |
PUT /custom-agents |
Replace the whole list { agents }: the saved list. Answers 400 for a bad or taken id, an unknown base, an empty or multi-line command, or more than 20 agents. The agent token may not call it |
Live updates and terminals
Section titled “Live updates and terminals”A browser cannot set headers on a WebSocket, so:
GET /events(WebSocket) streams live task changes, includingtask.deletedwhen a task is deleted. Pass the token as?token=<token>. Each message is JSON with akind. Besides the task messages it sends:repos.changedwhen a project is added or removed, or the approval of its commands changes, so a dashboard can readGET /reposagain.activity.changedwith{ taskId, activity }when what an agent does changes.activityis the task’s whole activity by terminal, asGET /activitygives it;{}means none.usage.changedwith{ taskId, usage }when a task’s usage changes.usageis the task’s entry, asGET /usagegives it.shells.changedwith{ taskId }when a terminal of the task starts or ends, when the program in front of a terminal changes (checked about every 500 ms while it prints, and when its output goes quiet), when an agent that comes back after a restart starts or is up, or when a hook changes the state of an agent that works on no stage, unless the lastGET /tasks/<id>/terminalsfound no agent in that terminal.workspace.dirtywith{ taskId }when files in the task’s workspace may have changed: after an agent hook for a tool that ran or for the end of a turn, when its terminals go quiet, after a commit or a rollback, or after a save in the editor. Each comes 750 ms after a change. Up to 3 in a row come that soon; while changes go on after that, at most one per task every 10 s, and one more after the last change.review-comments.changedwith{ taskId }after a review comment is added, changed or deleted, a send, or when a file edit moved a comment. ReadGET /tasks/<id>/review-commentsagain.workspace.preparingwith{ taskId, step }while a new workspace is made:stepisfetchorcheckout, thennullwhen it ended. A failure also haserror.jobs.changedwith{ jobs }when a background job starts or ends.jobsis the whole list, asGET /jobsgives it.security.changedwith{ strict, warning }when Strict mode changes, orsecurity.jsonchanged outside Natamux, so a dashboard can readGET /securityagain.resyncto one socket that missed messages because it read too slowly. The dashboard loads everything again.
- Terminals open with a one-time ticket. Call
POST /tasks/:id/terminal/ticketto get{ ticket }, then openGET /tasks/:id/terminal?ticket=...(WebSocket) within 30 seconds.
The full table
Section titled “The full table”A request with a bad field answers 400 with an error that names the field and the reason, such as which field is too long.
The Rust daemon routes define each endpoint and its errors in crates/natamux-daemon/src/http/routes.