Extensions

An extension is one ClojureScript file in ~/.config/xi/extensions/. It can give the agent a tool, give you a slash command or a keyboard shortcut, react to what happens in a chat, add to the system prompt, or add a page to the web client. No build step, no restart.

The smallest extension

;; ~/.config/xi/extensions/hello.cljs
(ns hello)

(def extension
  {:id :hello
   :commands [{:name "hello"
               :description "Say hello"
               :handler (fn [_state {:keys [room-id]}]
                          {:effects [[:app/dispatch {:type :ui/status
                                                     :room-id room-id
                                                     :text "Hello from an extension."}]]})}]})

Enable it by listing the file in your config:

;; ~/.config/xi/config.edn
{:type       :xi/config
 :version    1
 :extensions ["hello.cljs"]}

Start Xi (or run /ext reload in a running one) and type /hello. The status line shows the text.

The top of a new terminal chat lists the loaded extensions, the files that failed to load with their error, and the files in the directory that are not listed. The web home page shows the failed and unlisted ones in an Extensions card. A headless server prints them on startup.

A file that is not listed is never read. This is deliberate: the agent cannot write to ~/.config/xi, so nothing the agent does, and nothing in a project you cloned, can get code loaded. Only you can.

Demo extensions

Xi ships a few working extensions. Enable one by its file name under :demo-extensions; no file to copy:

;; ~/.config/xi/config.edn
{:type            :xi/config
 :version         1
 :demo-extensions ["notes.cljs" "hn.cljs"]}
FileGives youBuilt in
notes.cljsA notes_add tool, a /notes command and a Notes page in the web clientTutorial: a page in the browser
ping.cljsCtrl+Shift+N or /ping toggles a desktop notification when a turn endsTutorial: a command and a key
hn.cljsAn hn_search tool for Hacker NewsTutorial: a web tool
deploys.cljsA deploys/board agent block kind, /deploys, which posts one, and a deploy_map tool with an app viewAgent blocks
scene.cljsA scene_show tool: the agent describes 3D objects, the web client shows them as a three.js app view you can orbit and clickApp views

They run like your own extensions: sandboxed, through the rules, and reloaded by /ext reload. Their source is in resources/extensions/ of the Xi package. An extension of yours cannot take the id or a tool name of an enabled demo.

What an extension can add

KeyGives you
:tool-definitions + :tool-registryA tool the agent can call
:commandsA /command you can type
:keybindingsA key in the terminal client
:handlersCode that runs when something happens (a turn ends, a dialog opens, …)
:fxSide effects: read a file, run a program, make a request
:system-promptText added to the agent's instructions
:prompt-badgeA marker next to the prompt, for state you want to see
:initThe extension's own state, per chat or per process
:mcp-serversMCP servers only this extension can call
:block-kindsA kind of agent block the agent and the extension can show
a <name>/web.cljs fileA page and menu entries in the web client

The tutorials go through each of these with a working example:

  1. A tool: the agent writes to a notes file
  2. A command and a key: a desktop notification when a turn ends
  3. A web tool: search Hacker News from a tool
  4. A page in the browser: the notes, with a form
  5. Your own MCP server: a headless browser for one tool
  6. Users and roles: roles in config.edn, rules per role, and an extension that grants them

How an extension runs

Extensions run sandboxed. There is no access to the file system, to processes, to the network or to environment variables, except through a small API, xi.api.*:

NamespaceFor
xi.api.fsRead, write and list files; the extension's own data directory
xi.api.storeKeep plain data under keys of your own, saved under the extension's id
xi.api.shRun a program
xi.api.httpMake an HTTP request
xi.api.mcpCall an MCP server's tool
xi.api.dialogAsk the user something
xi.api.blocksShow an agent block in a chat
xi.api.jsonParse and produce JSON
xi.api.promiseChain the promises the other functions return

Every call through fs, sh, http or mcp goes through the rules, tagged with the extension's id, like an agent's tool call: the extension's own data directory is free, credential paths are blocked, and everything else asks until a rule allows it. So an extension can do no more on your machine than you let the agent do, and you can see in /rules what you allowed it.

Code also runs with a few guards on Xi's state: an extension can change its own state slice and nothing else, and can dispatch its own events plus a few chosen ones. A throwing extension is logged, not fatal.

Editing and reloading

Edit the file and run /ext reload. Xi evaluates the file again and swaps the new code in while the server runs: handlers, commands and effects apply at once, tools from the next turn, a web page on the next page load. The extension's state is kept. If the file does not evaluate, Xi reports why and unloads the old version, so nothing half-old keeps running.

An agent can call the same thing as a tool, ext_reload, which is how you have the agent help you write an extension: it edits the file, reloads, and sees the error if there is one.

/ext list shows what is loaded. /ext disable <id> turns one off for the session.

Where things live

PathWhat
~/.config/xi/extensions/<name>.cljsThe extension
~/.config/xi/extensions/<name>/Its helper namespaces and its web half, web.cljs
~/.local/share/xi/extensions/<id>/Its data directory; (fs/data-dir ctx) returns it

An extension's id (:id :notes) is what the rules and the data directory use. It must not clash with another loaded extension or with a built-in one.

Next

Start with Tutorial: a tool. Everything a map may contain, with every API function, is in the extension reference.