Skip to main content

User extensions

An extension is a TypeScript or JavaScript module that adds your own tool, / command, launch flag or event hook to the agent. An extension loads from the next start.

The agent writes the extension itself

Describe what you need in the chat: "Make an extension that blocks commands with rm -rf". The agent picks the right mechanism, writes a file to ~/.explyt/extensions/, checks it with explyt extensions check and tells you how to turn it on.

When you need an extension​

An extension is arbitrary code that runs in every session of every project. If a lighter mechanism solves the task, use it instead:

What you needWhat to use
A reusable instruction or scenarioa skill
"Always do X" in a project or everywherea rule
A tool that calls a service, an API or a CLIan MCP server
A shell command at a fixed moment: before or after a tool call, on a message, at the end of a turna hook in .explyt/hooks.json
A ready-made set of skills, rules, agents and MCP servers from other authorsa Marketplace plugin
A hook the hooks.json format can't express, a new / command or a tool that runs inside the agent processan extension (this page)

Where extensions live​

Only in ~/.explyt/extensions/. There are no project extensions: a file in <project>/.explyt/extensions/ is not loaded. This way a cloned repository can't run its code in your session. If the directory doesn't exist, create it.

What is in ~/.explyt/extensions/Loaded
foo.ts or foo.jsyes, this file
foo/index.ts or foo/index.jsyes, the index file
foo/package.json with "pi": { "extensions": ["./src/main.ts"] }yes, every existing file from the list; a path outside foo/ skips the extension
foo/package.json with an empty pi.extensions or with missing files, and no indexskipped: there is no entry file
foo/skills/, foo/prompts/, foo/themes/no, only entry files load
foo/bar/baz.ts without an index or a manifest in foo/no
A name ending in .off or .bak, a file or a directoryno, never
notes.md, foo.mjsno
A path containing "skipped

Candidates load in path order. Put an extension made of several files into a directory: a helper file next to a single-file extension isn't part of the check, and an edit only in it won't be noticed. Keep everything the extension needs inside its directory: a symbolic link pointing outside it and a .git/ directory are not part of the check either.

How to write an extension​

An extension exports a default function that receives the ExtensionAPI. The function can be async. TypeScript runs as is; no build step is needed. The typebox package and the engine's own packages are available without installation.

A tool for the model:

import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
import { Type } from "typebox";

export default function (pi: ExtensionAPI) {
pi.registerTool({
name: "word_count",
label: "Word count",
description: "Count words in a text",
parameters: Type.Object({ text: Type.String() }),
async execute(_toolCallId, { text }) {
// `content` is what the model reads; `details` is structured data for the UI and the session.
return { content: [{ type: "text", text: String(text.split(/\s+/).filter(Boolean).length) }], details: {} };
},
});
}

A command only:

import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";

export default function (pi: ExtensionAPI) {
pi.registerCommand("today", {
description: "Show today's date",
handler: async (_args, ctx) => {
ctx.ui.notify(new Date().toDateString(), "info");
},
});
}

A hook only, blocking a dangerous command before it runs:

import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";

export default function (pi: ExtensionAPI) {
pi.on("tool_call", async (event) => {
if (event.toolName === "bash" && String((event.input as { command?: string }).command ?? "").includes("rm -rf")) {
return { block: true, reason: "rm -rf is blocked by a user extension" };
}
});
}

The full API description (all events, ctx, rendering, providers) is in the engine's own documentation. explyt extensions check prints the absolute path to it on the engine API: line.

Dependencies​

Use the built-in Node modules (node:fs, node:path, node:child_process) and the global fetch first. If you can't do without a package, make the extension a ~/.explyt/extensions/<name>/ directory with a package.json that lists the package in dependencies and an index.ts file, then run npm install in that directory. node_modules/ there is picked up automatically.

An extension whose imported package is not installed is skipped with a hint to run npm install in its directory. After the installation it loads from the next start without editing the file.

Reserved names​

An extension can't register a tool or a flag whose name is already taken:

  • the engine's built-in tools: read, bash, powershell, edit, write, grep, find, ls;
  • the engine's built-in flags, for example --model and --extension;
  • all tools and flags of Explyt CLI itself, for example bash_output, fork, subagent, use_skill, web_search, --mcp-config;
  • a name that another user extension registered earlier.

An extension with a taken name is skipped entirely. explyt extensions check --verbose prints the full list of reserved names on the reserved: line. You can't override a built-in tool by registering the same name.

Hooks are different: a handler on tool_call, tool_result or any other event can watch and block any tool, built-in ones included.

There is no reservation for / commands. The engine keeps duplicate commands as /name:1, /name:2 and hides a command that matches a built-in one.

Subagents, forks and /btw load the same extensions as the main agent, so hooks work in all child agents. If an agent file sets a tools: list, an extension tool is available to that agent only if the list names it.

Check: explyt extensions check​

Right after creating or editing an extension, run:

explyt extensions check

The command loads every candidate the same way the next start will, but without the cached results, and prints:

LineMeaning
<file> loads: tools=… flags=… commands=… handlers=…the extension is accepted
<file> skipped: <reason>skipped, the reason is given
<name> disabled (settings: extensions.disabled)turned off in the settings, not checked
no user extensions in ~/.explyt/extensions/nothing to load
user extensions not loaded: the preflight failed: <reason>the check itself couldn't run
last restart: <file>: <error>the engine failed to load this file at the last start
<name>.bak backup present: delete it once the edit is confirmeda rollback file is left over
reserved: … and engine API: <path>reserved names and the path to the engine documentation

The command exits with code 1 if an enabled extension is skipped or the check failed, and with code 0 otherwise.

A loads line proves that the file loads and what it registers. Whether the tool's execute or the hook works correctly shows only in a real call.

How to turn it on​

An extension is picked up at start. What to do after a change:

ChangeWhat to do
A new extensionRestart the agent in the same project directory with explyt -c: it continues the last session
The code of an extension that already loads/reload in the running session
A tool or flag nameRestart with explyt -c, not /reload: /reload doesn't run the check
Disabling or enabling an extensionRestart with explyt -c

If an extension is skipped at start, the terminal shows a warning with the reason and a hint to run explyt extensions check. A load that doesn't fit into the 5-second check also skips the extension: such an extension would slow down every start.

Editing, rolling back and disabling​

Before editing an existing extension, copy it to <name>.bak (guard.ts.bak or a jira.bak/ directory). If <name>.bak already exists, don't overwrite it: it holds the last confirmed version. A name ending in .bak is never loaded.

Then make the edit, run the check and turn the change on as described in the table above. Once the result is confirmed, delete the .bak. If it doesn't work, put the .bak back in place of the extension and turn it on the same way. If the check reports a forgotten <name>.bak, decide whether the last edit works and delete the copy or restore it. The agent does the same when it edits an extension at your request.

To turn off an extension without deleting it, add its name to extensions.disabled in ~/.explyt/settings.json and restart the agent. The name is the file name, for example guard.ts, or the directory name, for example jira:

{
"extensions": {
"disabled": ["guard.ts", "jira"]
}
}

You can also turn off an extension by renaming it to a name ending in .off. The setting works only at the global level: a project settings.json can't disable an extension. See Settings.

If the engine still didn't load the extension​

If the engine didn't load an extension that passed the check, the agent restarts once without user extensions and names the problem file.

  • A missing dependency (Cannot find module): run npm install in the extension directory, then run the check. You don't need to edit the file: the next start checks it again.
  • Any other error: the file stays skipped until its content changes. Fix the file and run the check.

Compatibility​

Extension compatibility is not guaranteed across updates of the agent or its engine. An extension that broke after an update is skipped with the reason: fix it and run the check.