Plugins
A plugin is a package you install per project that adds capabilities to Polytoken sessions. A plugin can provide tools, hooks, configuration, read-only resources, and revisioned surface events for external consumers. Polytoken verifies every package against your trust settings and asks you to approve the capabilities before the plugin runs. See Plugin surfaces for the surface event contract and client recovery flow.
Installing a plugin
Section titled “Installing a plugin”A plugin ships as one file named <name>.pt-plugin. polytoken plugin-dev install places the file in the project’s trusted plugin directory:
~/.config/polytoken/projects/<project-key>/plugins/<name>.pt-pluginThe <project-key> component comes from the project’s canonical absolute path, so each project has its own package directory. If you set $XDG_CONFIG_HOME, replace ~/.config with that directory. The remaining path stays the same on every platform.
When a session starts in the project, and whenever you run /reload, Polytoken scans the package directory, verifies each package against your trust settings, and compares each package with its recorded approval. A package that fails any step does not run, and one bad package does not block other packages in the directory. By default, Polytoken stores the approval record in the project’s .polytoken/plugins/approvals.json file. Plugin capability approval prompts include extension_context.plugin_package_digest, the verified package’s full lowercase 64-character framed digest; ordinary extensions omit it. For an isolated daemon or development fleet, set POLYTOKEN_PLUGIN_APPROVALS_DIR to an absolute directory; approvals then live at <that-directory>/<canonical-project-key>/approvals.json. The configured directory may be created on the first approval, but must be absolute and resolve without a symlinked project-key directory. A bad override fails plugin approval closed and never falls back to the project-local file. Leave the variable unset for the unchanged default. With a valid override, authenticated GET /plugins includes approval_path_fingerprint: a SHA-256 fingerprint of the resolved root, not its filesystem path. Local fleet provisioning checks this value before granting approval.
Use polytoken plugin-dev install instead of copying a package by hand. The command validates the package name and derives the project directory. Installing the exact same package bytes again is a no-op. Any byte difference, including adding or removing a signature, requires --force to replace the installed package.
Install or remove the stock TypeScript authoring plugin
Section titled “Install or remove the stock TypeScript authoring plugin”The developing-plugins stock plugin provides tools for inspecting and scaffolding TypeScript plugin projects, checking local build tools, and running the existing build, pack, and verify commands. The source lives in js/stock-plugins/developing-plugins/. A source directory does not enable a plugin. Build and verify the package, then install it explicitly for each project:
bazel build //js/stock-plugins/developing-plugins:developing_pluginspolytoken plugin-dev verify bazel-bin/js/stock-plugins/developing-plugins/developing-plugins.pt-pluginpolytoken plugin-dev install bazel-bin/js/stock-plugins/developing-plugins/developing-plugins.pt-plugin --project /path/to/projectThe package requests read_files, write_files, and shell. On first load, approve those capabilities only if you trust the package. File operations use project-rooted paths, but shell approval grants process execution with the host’s shell privileges. Shell approval does not sandbox filesystem access, commands, or child processes.
To turn off the stock authoring plugin for one project, remove its package file from the project’s trusted plugin directory. Find the project key with polytoken plugin list --project /path/to/project; the default package path is ~/.config/polytoken/projects/<project-key>/plugins/developing-plugins.pt-plugin. Replace ~/.config with your $XDG_CONFIG_HOME value when you set that variable.
rm ~/.config/polytoken/projects/<project-key>/plugins/developing-plugins.pt-pluginRun /reload in an existing session to remove the plugin’s tools and resources from that session. A new session also starts without the removed package. Other projects keep their own installation.
The stock plugin exposes plugin__developing-plugins__inspect, plugin__developing-plugins__scaffold, plugin__developing-plugins__doctor, plugin__developing-plugins__build, plugin__developing-plugins__pack, and plugin__developing-plugins__verify. The TypeScript plugin walkthrough gives each tool’s JSON arguments and a scaffold-to-verify example.
The repository layout looks like this:
plugin-project/├── package.json├── src/index.ts├── src/index.d.ts├── polytoken.plugin.json└── resources/ └── skills/example-helper/SKILL.mdUse the private js/ workspace for Polytoken’s SDK package and the Extism JavaScript PDK. The SDK provides JSON envelope helpers, typed capability calls, hook output helpers, and declaration types. Your bundle must export one function for every declared tool and one function for every declared hook. The interface file passed to the bundle step must declare those exports in the main module and declare the extism:host imports used by the SDK.
polytoken.plugin.json controls the package projection:
name,version, anddescriptionbecome the package identity manifest.capabilitiescontrols the host functions that the plugin may request.toolsdeclares the tool names, descriptions, and input schemas.config_schemavalidates values underplugins.<name>.lifecycle.persist_across_clearcontrols whether Polytoken retains plugin state across/clear.- Files under
resources/skills/,resources/facets/,resources/subagents/, andresources/templates/become read-only plugin resources.
The plugin-dev command group supports the local authoring loop:
polytoken plugin-dev doctorpolytoken plugin-dev build --project ./plugin-projectpolytoken plugin-dev pack --project ./plugin-project --out ./example.pt-pluginpolytoken plugin-dev sign ./example.pt-plugin --out ./example.signed.pt-pluginpolytoken plugin-dev verify ./example.signed.pt-pluginpolytoken plugin-dev install ./example.signed.pt-plugin --project ./my-projectpolytoken plugin-dev add skill example-helper --project ./plugin-projectdoctor reports whether the required build tools are available and lists cosign separately as an advisory for signing. build creates the bundle, pack creates the .pt-plugin, sign contacts public Sigstore services through the author’s keyless cosign installation, verify performs an offline package preflight and verifies present signatures, install copies a package into the trusted per-project directory, and add scaffolds a resource. Every build-tool invocation fails with a named tool error when a required tool is missing. The command group never installs or downloads tools.
For a local unsigned development package, set plugin_trust.allow_unsigned_local = true in the global configuration, install the package into the project’s plugin directory, and approve the requested capabilities in the session. Keep unsigned-local trust for development. Signed packages use the signature trust policy.
Package format
Section titled “Package format”A .pt-plugin file is a compressed archive with a fixed set of entries:
manifest.jsoncarries the plugin identity: name, version, and description. The name must match the package filename, written as either<name>.pt-pluginor<name>.signed.pt-plugin; Polytoken normalizes both spellings on install.bundle.wasmcontains the WebAssembly module. Polytoken compiles the module for each session and grants only the capabilities you approve.- An optional signature bundle. Polytoken verifies a present signature as described under Signature trust. A package without a signature counts as unsigned.
Polytoken rejects archives with duplicate or unexpected entries, invalid declarations, or a mismatch between declared capabilities and the module’s imports. Run polytoken plugin list to inspect package warnings.
What a plugin provides
Section titled “What a plugin provides”Tools. Approved plugin tools appear beside built-in tools, and the model can call them like any other tool. Plugin tool names include the plugin name, so tools with the same local name do not collide.
Hooks. A plugin can export hooks for session events such as startup. Polytoken calls plugin hooks using the same event model as configured hooks. A hook on a blocking event can veto the action. Other hook events run as side effects.
Emitting conversation cards
Section titled “Emitting conversation cards”A plugin can call emit_card to show a Markdown conversation card to the client. The card identifies the plugin and renders the Markdown as a user-visible conversation item. Polytoken never sends card Markdown to the model, so card content cannot add prompt context or instructions.
The emit_card payload contains markdown and durable:
durable: truestores the card in the session history. The card appears again when you reattach to the session. Polytoken broadcasts the card before it confirms the history append, so an append failure returns an error to the plugin even though a connected client may already have seen a card that disappears after refresh.durable: falsesends the card to connected clients without storing it in session history. Polytoken treats delivery as best effort. SSE saturation can drop a client-only card, and a disconnected client cannot recover it later.
Every card lands in the main conversation, regardless of which turn invokes the plugin. When a plugin tool runs inside a subagent turn, the card appears in the main conversation after the subagent tool result arrives, never in the subagent transcript.
Polytoken applies the same 64 KiB serialized-payload cap as other message-emission calls. The cap covers the JSON object that wraps the Markdown, not just the Markdown string. The effective Markdown maximum is therefore slightly smaller than 64 KiB because the JSON wrapper consumes part of the cap.
Cards reuse the existing emit_message capability. Add emit_message to the plugin manifest and request approval for that capability. A plugin does not need a separate card capability.
Resources. A plugin can pack read-only files such as prompt fragments or reference documents. Reference a resource with plugin+<name>://<path> from templates, @ references, and facet configuration. For example, plugin+example://skills/example-helper/SKILL.md identifies the example skill resource.
Configuration. A plugin can declare a schema for its settings. Put values under plugins.<name> in your configuration file. Polytoken validates the values against the plugin schema before loading the plugin. See Configuration for the plugins block.
Lifecycle. A plugin declares whether it survives /clear. A persistent plugin keeps its running state across a context clear. A nonpersistent plugin starts a fresh instance after the clear.
Approval flow
Section titled “Approval flow”The first time Polytoken loads a plugin without a matching approval, Polytoken pauses and asks you to approve the plugin’s capabilities. The prompt names the plugin, version, provenance, and requested capabilities. The plugin does not run until you answer.
Polytoken stores the answer in .polytoken/plugins/approvals.json in the project. Polytoken asks again when the package bytes, identity, capabilities, lifecycle declaration, or signer changes. Editing plugin configuration does not trigger re-approval.
Signature trust
Section titled “Signature trust”Signed plugins use Sigstore keyless signatures. Run polytoken plugin-dev sign <file> with the author’s cosign installation to contact public Fulcio/OIDC and Rekor services and embed a proof-bearing sigstore.bundle.json. The signer proves an identity through a short-lived certificate, and the signature enters a public transparency log. Polytoken verifies the certificate chain, log record, signing time, and exact package bytes. Run polytoken plugin-dev verify <file> to perform the same package preflight and signature verification offline before installation.
Set plugin_trust in the global configuration file to choose which signatures Polytoken accepts:
plugin_trust.trusted_publisherspins a signer to a plugin name. Each entry names the plugin, identity provider, and exact signer identity.plugin_trust.allow_unsigned_local, off by default, accepts unsigned packages only from the local per-project plugin directory. A present but invalid signature always fails verification.
Run polytoken plugin-dev verify <file> --require-signature when an unsigned package must fail the preflight. A successful signed verification prints the signer identity and canonical issuer. See Configuration for the full plugin_trust key reference.
Checking plugin state
Section titled “Checking plugin state”Two CLI commands cover the plugin lifecycle:
polytoken plugin listprints every plugin discovered for a project without contacting a daemon. The output includes name, version, package digest, provenance, and approval state. Use--project <path>to inspect another project.polytoken plugin statusattaches to a running session and prints the live plugin snapshot, including version, state, tool count, and resource counts. Pass a session ID to target a specific session.
The complete flag reference appears on the CLI reference page.