Reference·Cell APIIndexClose
Cell API
How a cell is written: nle:define-cell, its clauses, tool contracts, the config section, hooks, notices, stop, and what Nodecode shows when one is written wrong.
One nle:define-cell form declares a cell: its config section, what it adds, and how all of it comes back off. The page builds one cell, nodecode-weather: a tool, a slash command and a manual. Each section ends with the mistakes people make there. Press Mistake and Instead to see what Nodecode showed each time.
Ask for one
The shortest way to a cell is to ask the agent for it: Cells reference. It writes the cell with these verbs, through eval; you can call them yourself.
| Verb | What it does |
|---|---|
(new-cell "NAME" :description "...") | Writes cells/<you>-NAME/: the .asd, a README, cell.lisp with the package and NAME.lisp for the code, in a git repository of its own. Loads it, and makes it this session's current cell. |
(new-cell "NAME" :source "DIR") | The same, with the folder in DIR, absent or empty: a repository of yours. cells/<you>-NAME links to it. |
(current-cell) | The cell this session works in, or NIL. |
(enter-cell "NAME") | Takes a made cell up again after a restart, or from another conversation. |
(leave-cell) | Ends the session's work on the cell. What it keeps goes to the layer again. |
(move-to-cell "NAME" 'fn '*var* ...) | Moves definitions the layer already keeps into the cell, one file each. They load from it at the next start. |
(fold-cell "NAME" :drop '(...)) | Folds a cell kept one file per definition into cell.lisp and NAME.lisp, in load order, in one commit that names what it left out. :drop names definitions to leave out. |
(cell-drift "NAME") | Reads only. :live-only: what runs for the cell that no file keeps, gone at the next start. :not-live: what a file defines that is not loaded. :elsewhere: the same for the layer's and the kernel's packages, where every session's evals land; listed to read, never counted against the cell. :clean t when :live-only and :not-live are empty. |
(reload-cell "<you>-NAME") | Makes the image agree with the folder's files after an edit made outside the session: what changed is evaluated, what was cut leaves. The cell restarts when its define-cell changed. |
While a cell is current, its files are its code. A write-file or edit of NAME.lisp makes what changed live and commits it, and a definition cut from the file leaves the image. An eval there defines live and keeps nothing: its receipt names the file to write. Memories and skills are kept as before. NAME.lisp reads in (in-package #:<you>-NAME). That package uses the kernel and the evolved package's exports, so define-cell, notice and on-stop read bare. One define-cell in the file declares what the cell adds, here in tokyo-time.lisp:
(in-package #:thomas-tokyo-time)
(defun tokyo-time (args session-id)
"/tokyo-time => the answer's text."
(declare (ignore args session-id))
(multiple-value-bind (s m h) (decode-universal-time (get-universal-time) -9)
(declare (ignore s))
(format nil "~2,'0d:~2,'0d in Tokyo" h m)))
(define-cell tokyo-time
(:section ("tokyo-time"))
(:command "tokyo-time" 'tokyo-time :description "The time in Tokyo"))
| Case | Result |
|---|---|
(restart-cells "thomas-tokyo-time") | The define-cell starts. /tokyo-time answers in every attached shell. |
The define-cell edited in the file | Run restart-cells on the folder again. |
A defun only evaluated | It runs now and is gone at the next start. cell-drift lists it under :live-only. |
| One definition in the file fails to load | Only it is skipped. (cells) names the file and the definition. |
| Nodecode restarts | The cell loads from its folder and starts. The session's hold on it ends: enter-cell takes it up again. |
The clauses are the same as a hand-written cell's: define-cell.
Start from the template
The template ships with every release. It is also template/ in nodecode-ai/cells, with every cell Nodecode ships as a worked example.
| Where | Path |
|---|---|
| A release | ~/.local/share/nodecode/current/src/cells/template/ |
| GitHub | template/ in nodecode-ai/cells |
- Copy it to
~/.nodecode/cells/nodecode-<name>/. - Rename the
.asdfile and thedefsysteminside it. - Name the package after the system.
- Write one
nle:define-cellform undernlk:define-peripheral. - Start Nodecode. The landing lists the cell.
cp -r ~/.local/share/nodecode/current/src/cells/template ~/.nodecode/cells/nodecode-weather
cd ~/.nodecode/cells/nodecode-weather
mv nodecode-template.asd nodecode-weather.asd

| Part | Content |
|---|---|
nodecode-template.asd | The system. Depends on nodecode. |
cell.lisp | One section, one :tool hook, /template, one notice at start. |
config.example.jsonc | The section, commented. Nodecode does not read it. |
Renaming the .asd file and keeping the system inside it
ASDF finds no system named after the file. The folder fails its load, and the landing shows a failed row.
Instead: Rename both: nodecode-weather.asd holds (defsystem "nodecode-weather" ...).

Naming the package after the cell: weather
The loader looks for START-CELL in the package named after the system. It finds none, so the folder loads as a library and nothing starts.
Instead: Name the package after the system: nodecode-weather.
define-cell
The whole cell, as it ran for every screen on this page:
(defpackage #:nodecode-weather
(:use #:cl))
(in-package #:nodecode-weather)
(nlk:define-peripheral weather :not-running t)
(defparameter *today* '(("oslo" . 4) ("lisbon" . 19) ("tokyo" . 15)))
(nlk:define-contract forecast
(:doc "Today's forecast for one city.")
("city" :text :required t :doc "the city, as the operator wrote it"))
(defun today (city)
(let ((c (cdr (assoc (string-downcase city) *today* :test #'string=))))
(cond ((null c) (format nil "~a: no forecast" city))
((string= (setting :units) "f") (format nil "~a: ~d°F" city (round (+ 32 (* 9/5 c)))))
(t (format nil "~a: ~d°C" city c)))))
(defun look-up (request)
(today (forecast-city request)))
(defun run-slash (args session-id)
(declare (ignore session-id))
;; Typed alone, /weather offers the cities as rows, and one that asks for
;; another; a row's line comes back here with the city after the name.
(if (nle:bare-args-p args)
(values "Which city?"
(nle:list-dialog
:title "Weather"
:rows (append (mapcar (lambda (city) (nle:run-row city (format nil "/weather ~a" city)))
(or (setting :cities) '("Oslo")))
(list (nle:ask-row "Another city" "City" "/weather" :verb "look up")))))
(today args)))
(defun refresh () nil)
(nle:define-cell weather
(:section ("weather")
(:guide "units is c or f; cities is what /weather offers typed alone")
("units" :choice :options '("c" "f") :default "c" :doc "degrees")
("cities" :list :doc "what the primer names")
("timeout_seconds" :integer :default 10 :min 1 :doc "one lookup's ceiling"))
(:tool "weather" (nlk:contract 'forecast) 'look-up)
(:help :weather "weather: today's forecast for a city - (weather:today \"Oslo\")"
"(nodecode-weather::today CITY) answers today's forecast.")
(:command "weather" 'run-slash
:description "Today, where you are")
(:start (lambda ()
(let ((worker (nlk:worker-start "weather" #'refresh :wake 900)))
(nle:on-stop (lambda () (nlk:worker-stop worker)))))))


nlk:define-peripheral gives the package its condition, FAIL, the settings variable *WEATHER*, RUNNING-SETTINGS and DEFINE-VERB. nle:define-cell adds START-CELL, STOP-CELL and SETTING.
Clauses go in any order. They install in the order written and come off in reverse.
| Clause | Does | On stop |
|---|---|---|
(:section (PATH...) CLAUSE...) | Required. nlk:define-section, verbatim. | — |
(:settings FUNCTION) | (lambda (values table) ...) answers the plist the cell runs on, for a section the declaration cannot carry. | — |
(:tool NAME SCHEMA FN) | nle:register-tool. SCHEMA is a contract. See Tool arguments. | Unregistered. |
(:command NAME RUN &key ...) | /NAME in the one slash catalog. RUN takes (args session-id) and answers (values TEXT DIALOG EFFECTS). See Command effects. | Out of the catalog. |
(:help TOPIC SUMMARY TEXT) | (help TOPIC) answers TEXT. Every request's help section carries SUMMARY. | Topic removed. |
(:hook NAME FN) | nle:hook on a point or a function name. | Unhooked. |
(:route PATH FN &key public) | PATH answered on the gateway's own port, to the operator's token; to anyone under :public. A PATH ending in / answers everything under it. | Route removed. |
(:start FUNCTION) | (lambda () ...), with the settings set. Everything no clause covers. | What it gave nle:on-stop. |
A :command takes these keys:
| Key | Does |
|---|---|
:description | Its line in the slash menu. |
:label, :catches | A :catches condition answers LABEL: it. Defaults: the command's name, and error. |
:session | nil for a command that acts on no session. |
:trigger | One character that opens it when typed as the draft's first character. |
:reads | '(:draft) hands RUN the text in the shell's input box as a :draft keyword, so RUN takes (args session-id &key draft). A command that does not declare it is never sent the draft. |
A command is its name: nobody types after it. Typed alone, RUN gets an empty ARGS, which nle:bare-args-p tells, and answers a nle:list-dialog of what it offers. A row is (nle:run-row LABEL LINE), whose pick runs LINE, or (nle:ask-row LABEL ASK LINE :placeholder TEXT :verb WORD), which asks for one line of text under ASK and then runs LINE with the text after it. The shell asks in its composer, a room in its own way. RUN reads those lines as it always read its ARGS. :argument-hint and :complete are still accepted, so an older cell loads, and nothing shows them.
The draft is the input box as it is when the command runs. A command run from a key or a picker row gets what is being written, and the box keeps it. A command typed into the box used the box for its own line, so it gets "". A front end that does not send the draft (the web page today, a room, cron, slash from eval) gets nil, unless the caller passes :draft.
Command effects
A command runs where the cell runs, which may not be where the person sits. EFFECTS, the optional third value, is a list of things the shell that ran the command does itself:
| Effect | The shell |
|---|---|
(:clipboard TEXT) | Copies TEXT with its own clipboard writer, so it lands on the person's desktop. |
(:draft TEXT) | Replaces the composer's draft with TEXT. |
(:draft TEXT :how :insert) | Inserts TEXT at the caret. |
(:draft TEXT :how :append) | Adds TEXT at the end of the draft. |
(:open SESSION-ID :prompt TEXT) | Opens the session in a new tab of the terminal the shell runs in, as nodecode resume SESSION-ID -- TEXT: tmux, zellij, GNU screen, WezTerm, kitty with remote control, Windows Terminal or Ghostty. :prompt is optional. |
The shell does them in order, then shows TEXT as usual. A row's :run line can answer effects too, so Space on a row can copy it. After a row's line, the list opens again, unless the answer set the draft: then it stays closed, because the composer is where the person goes next. A shell passes over an effect it does not know. A malformed effect, one that is not a plist with keyword keys, signals and names it.
nle:*slash-effects* holds the effects the caller performs while RUN runs: (:clipboard :draft) from a shell, with :open when it runs in a terminal it can open a tab in, nil from the web page, rooms, nodecode rpc and (nle:slash LINE) from eval, which show TEXT alone. (nle:slash LINE :effects '(:clipboard)) names them from eval. Word TEXT by it, so it never claims a copy that did not happen:
nle:*slash-effects* is bound while RUN runs, so read it there: a thread RUN starts does not see it.
(defun copy-last (args session-id)
(declare (ignore args))
(let ((reply (last-reply session-id))) ; the cell's own reader
(if (member :clipboard nle:*slash-effects*)
(values "Copied the last reply" nil (list (list :clipboard reply)))
reply)))

Everything is filed under one key: the package's name, downcased. That is the folder's name.
Leaving out nlk:define-peripheral
The folder loads and starts. The first call that reads a setting fails.
Instead: Put (nlk:define-peripheral weather :not-running t) above define-cell.

Leaving out the :section clause
define-cell requires one. The file does not compile, and the folder fails.
Instead: Declare the section the cell reads.
Giving a command's RUN one parameter
RUN is called with the argument text and the session id.
Instead: Take both, and ignore the one you don't use.
Tool arguments
A tool's arguments cross into the cell through a contract, declared once. The model sees the schema the contract derives. A call that does not fit is refused before any hook or body runs, and the body reads a record.
(nlk:define-contract forecast
(:doc "Today's forecast for one city.")
("city" :text :required t :doc "the city, as the operator wrote it"))
(defun look-up (request)
(today (forecast-city request)))
(:tool "weather" (nlk:contract 'forecast) 'look-up)

| Declares | Detail |
|---|---|
| Types | :any, :string, :text (non-empty), :integer, :number, :boolean, :object, :array. |
| A member | :required, :default, :options (the schema's enum), :of to nest, :slot to rename. |
| Unknown members | Ignored, unless (:unknown :refuse). |
| Derives | FORECAST, FORECAST-CITY, MAKE-FORECAST, FORECAST-P, DECODE-FORECAST, ENCODE-FORECAST. |
| Arrives | Result |
|---|---|
JSON null | Absent. Takes the default, or is refused like a missing key. |
false | Present. NIL on a :boolean. |
| The wrong type | Refused, never coerced. "3" is not an integer. |
| A malformed declaration | Fails at macroexpansion, so the folder fails its load. |
The section
A section is the cell's part of ~/.nodecode/config.jsonc, declared once, as data. /settings, the web page's Settings tab, the model's setup primer, the cell's line in /cells, its refusal and the values it runs on all come from it.
| Field type | Value |
|---|---|
:string | Text. |
:secret | A secret written inline. |
:env | The name of an environment variable holding a secret. |
:path | A file path. |
:directory | A folder. ~/ is expanded. A relative default is under the home. |
:boolean | true or false. |
:integer | A whole number. May carry :min. |
:list | An array of strings. May carry :choices, a function of the section's table answering ((id . label) ...). |
:choice | One of :options. |
A field may be :required and carry :default and :doc. Section options: (:guide TEXT), (:check FN), (:one-of NAME...), (:any-of NAME...), (:owner NAME). :owner defaults to the package's name, downcased.
| Case | Result |
|---|---|
| Section present | The cell starts. |
"enabled": false | Nothing installs. The code stays loaded until Nodecode restarts. |
| A value of the wrong shape | NLK:CONFIG-REFUSAL. REFUSED on the cell, and a standing :error notice under the folder's name. |
A :required value absent | No refusal. /settings and /cells say still needed: KEY. |

(setting :timeout-seconds) reads a value. An underscore in the config is a dash here. (config-get '("weather")) reads the section, and (config-set '("weather") '(:units "c")) writes it, comments kept.
Writing a value the section does not allow: "units": "C"
The cell refuses to start. A standing notice names it, and the cell is REFUSED until it restarts.
Instead: Fix the value, then run (restart-cells "nodecode-weather") without relaunching Nodecode.

Reading a setting by its config spelling: :timeout_seconds
SETTING names keys with dashes. A key the section does not declare is an error.
Instead: (setting :timeout-seconds).
Marking a field :required and counting on a refusal when it is missing
Nothing refuses. The cell starts, and /settings says still needed: KEY.
Instead: Check the value where you use it, and FAIL with a sentence that says what to set.
Hooks
| NAME | FN receives |
|---|---|
:tool | (op next). One tool dispatch. OP is (:name :arguments :call-id). |
:frame | (op next). One live frame leaving the gateway. |
:credential | (op next). |
:round | (op next). One model request about to be built, every round of every turn. OP is (:session-id :turn-id :turn :round): the session and turn ids as strings, :turn the durable turn object, :round 0 for the turn's first. Key on the ids; the turn object's fields change between releases. A reminder recorded here is in that request, and (setf *reasoning-effort* "high") sets the effort from this round on. |
| A function name | (next &rest args). Around every call of it. |
Call next to run the rest of the chain. Don't, to replace it. A hook that refuses a call answers (nle:failure "ERROR: ..."), and the call is recorded failed.
:frame and :round hooks only watch. An error such a hook signals itself, outside next, is stepped over: the frame still goes out, the request is still built, and the error stands until the hook is registered again or unhooked: the footer shows 1 hook skipped, and /status names it under Needs attention. On :tool, :credential and around a function, a hook's error is the call's own error.

Two cells hooking one function under different keys both run, in load order. (nle:turn) answers the running turn as a plist, or NIL outside one: :session-id, :turn-id, :parent, what it has spent (:seconds, :rounds, :calls, the token counts), :context-tokens against :context-window, :quiet-seconds since the operator last read a sentence, and its :budget. To cap your own sessions' turns, advise nle:turn-budget and return (:seconds N :calls N :tokens N). Call next for every other session.
Writing a :tool hook that never calls next
The hook replaces every tool call in every session. It answers NIL, so the turn fails.
Instead: (funcall next op), unless you mean to replace the call. Then return a string.

Refusing a call by returning "ERROR: ..."
The call is recorded as done. The transcript draws it as a success.
Instead: Return (nle:failure "ERROR: ..."). The call is recorded failed.
Notices and restarts
(nle:notice "weather: no key set, answering from the table" :level :warning :key "nodecode-weather")
(nle:notice nil :key "nodecode-weather") ; clear it
(restart-cells) ; every peripheral, from the config as it is now
(restart-cells "nodecode-weather") ; one folder
A shell shows notices as toasts only with "tui": {"notification_popups": true}, which is off by default. A keyed notice stands either way: /cells shows it and the model reads it.
| Notice | Shown |
|---|---|
:info, :warning | A toast for five seconds. |
:error | A toast until it is closed. |
With :key | Stands. A shell that attaches later gets it, and the model reads it at the tail of its prompt until it is replaced or cleared. |
:quiet, with :key | Stands without a toast. /cells and the model read it. |

What the model's next prompt carried:
<harness key="notices">
weather: no key set, answering from the table
</harness>
hello
Posting a state that lasts without :key
It is said once, as a toast where popups are on. The model never reads it.
Instead: Give it a :key. It stands, and the model reads it until you clear it.
Posting a keyed notice at start and never clearing it
It stands after the cell stops. The restart report still lists it.
Instead: Clear it on stop, next to where you post it.
Status rows
A status row is one line a cell keeps in every shell, over the footer: a usage meter, a ticker, a job's progress. Set it where the cell starts and clear it on stop:
(nle:define-cell weather
(:section ("weather") ...)
(:start (lambda ()
(nle:status-row "weather: Oslo 4°C" :key "nodecode-weather")
(nle:on-stop (lambda () (nle:status-row nil :key "nodecode-weather"))))))
| Status row | Keyed notice | |
|---|---|---|
| Where | One line over the footer of every shell, rows of several cells joined with · | A toast where popups are on |
| A shell that attaches later | Draws it | Gets it |
| The model | Never reads it | Reads it at the tail of its prompt |
/cells | Does not list it | Lists it |
| Replace it | Call again under the same :key | The same |
| Clear it | nil or "" as the text | nil as the text |
The row is one line: line breaks become spaces, and a row wider than the window is clipped with …. Rows live in the organism, so a restart starts with none. A shell from before status rows draws none and keeps working.
A row for one session, and a row that does something
| Keyword | The row |
|---|---|
:session-id ID | Stands only in the shells showing session ID. A shell that moves to that session draws it from then on. |
:draft TEXT | Offers TEXT: Tab on an empty composer puts it there, for the person to send or change. |
:run LINE | Offers a slash line instead: Tab on an empty composer runs it as if typed, the way a chord in keybinds.json runs one. Its answer's effects work, so (:draft TEXT) can come back from the gateway. |
:verb WORD | The word beside the key, tab accept by default for a draft and tab run for a line. |
A suggestion for the next prompt of one session:
(nle:status-row "next: run the failing test again" :key "here-ticker"
:session-id session-id :draft "run the failing test again")
The key hint shows on the row's right while the composer is empty, which is when Tab takes it; with several rows that offer something, Tab takes the first. Tab is the accept-suggestion key, so keybinds.json can move it. A row offers :draft or :run, not both, and :run starts with /: anything else signals, naming it.
Setting a row at start and never clearing it
It stays in every shell after the cell is turned off or restarts.
Instead: Clear it in on-stop, next to where you set it.
Putting a state the model should know into a row
The model never reads a row.
Instead: Post a keyed notice instead, or as well.
Stop
| Property | Detail |
|---|---|
| Complete | Stop takes back exactly what start put in. |
| Idempotent | A second stop does nothing. |
| A start that fails halfway | Leaves nothing. Sibling cells still start. |
| A second start | Stops the first one. One of everything remains. |
When the declaration does not fit, write START-CELL by hand from the same pieces:
(nlk:define-section ("mine") ...) ; config alone, no cell
(nle:register-tool NAME SCHEMA FN) ; (nle:unregister-tool NAME)
(nle:register-command OWNER CMD RUN ...) ; (nle:unregister-commands OWNER)
(nle:hook NAME KEY FN) ; (nle:unhook NAME KEY)
(nle:route PATH FN) ; (nle:route PATH nil)
(nle:status-row TEXT :key KEY) ; (nle:status-row nil :key KEY)
(nlk:worker-start NAME STEP :wake N) ; (nlk:worker-stop W), (nlk:worker-poke W)
(nle:starting ...) ; answers the thunk that undoes its body
(nle:on-stop FN) ; one inverse, in the innermost scope
Starting a worker in :start without an on-stop
Each restart starts another worker. The old ones keep running.
Instead: Record its stop with nle:on-stop.

Calling nle:on-stop from a command or a tool
There is no start to record it in, so it signals. Whatever it was meant to stop keeps running.
Instead: Start long-lived things in :start, or inside (nle:starting ...).
Writing START-CELL by hand and leaving the command out of its stop
After the cell stops, /weather still answers.
Instead: Use define-cell. By hand, unregister everything you registered.
Ask a side question
A cell can put a prompt to a session of its own with nle:submit, and limit the tools that turn may call. A fork of a session holds its context, so a side question asked there is answered from it, and nothing is written to the session it came from.
(let* ((anchor (or (nlk:last-finished-turn-id session-id)
(error "nothing has finished here to ask from")))
(child (nlk:durable-session-id
(nlk:create-session :parent session-id :anchor-turn-id anchor)))
(turn (nlk:active-input-admission-turn-id
(nle:submit child question :tools '() :source "btw" :source-id session-id))))
;; poll on a thread of the cell's own, not in the command
(when (nlk:turn-terminal-kind turn)
(nlk:turn-answer child turn)))
nle:submit key | Means |
|---|---|
:tools '() | The turn may call no tool. The tools are still declared, so a fork's earlier calls stay valid and the request reuses the cached prefix, but the provider is asked with tool_choice none. A call made anyway is refused as tool_not_offered and never runs. |
:tools ("NAME" ...) | The turn may call only these. A call to any other is refused the same way. |
| left out | Every tool, as before. |
The limit is recorded with the prompt, so it holds for a prompt that waits in the queue and for a turn resumed after a restart. A steer carries its own limit to the turn it starts; the turn it cuts short keeps the one it began with.
A session forks at its head even while a turn runs there, and the fork then holds that turn as far as it has gone, perhaps a tool call with no result yet. nlk:last-finished-turn-id names the anchor that leaves it out: the head of an idle session, else the running turn's parent. It answers nil at the root and while the first turn runs, when there is nothing finished to ask from.
What a folder may do
| Act | Detail |
|---|---|
| Define | New names in nodecode.evolved or its own package. |
| Override | A shipped nodecode.evolved definition. The boot line reports it. |
| Advise | A shipped function, through a hook. Preferred to an override. |
| Add methods | To shipped generics. Only a restart removes one. |
Redefine a nodecode.kernel name | Don't. The kernel locks after the folders load, so at load the folder's definition wins, in every process. Through eval, the lock refuses it. |

A cell reads its home through (nlk:home "..."), never a literal ~/.nodecode/. It then follows a profile.
Dependencies the image lacks go in vendor/, from ql:bundle-systems. vendor/bundle.lisp loads before the folder's systems.
Redefining a kernel function in the folder
The folder's definition wins in every process. Here, nlk:home points at a directory that does not exist, and Nodecode no longer starts.
Instead: Advise the function with a hook. If a launch already fails, run nodecode --pristine and fix the folder.

Writing ~/.nodecode/ into a path
Under a profile it still points at the main home.
Instead: (nlk:home "weather.cache") follows the profile.
| To | How |
|---|---|
| Share it | git push the folder to any remote. |
| Install it elsewhere | git clone it into ~/.nodecode/cells/, or nodecode add nc://NAME once it is on the hub. |
| List it on the hub | Submit it at nodecode.ai/cells/submit. Nodecode's own cells arrive as pull requests to nodecode-ai/cells, where .github/test-cell.sh FOLDER runs one cell's tests. |
| Undo a change | nodecode rollback N puts every folder back to generation N. A folder's git HEAD is its revision. A folder with no repository is never restored, and the rollback refuses by name. |
When one goes wrong, find the line in Troubleshooting.