Skip to content

Building Plugins

oxide-code (ox) keeps its Rust core (ox-core) minimal and exposes every major agent surface to out-of-process plugins. Plugins communicate with the host over stdio using newline-delimited JSON-RPC 2.0 (NDJSON), so you can write them in Rust, Python, TypeScript, Go, or any language that reads stdin and writes stdout.

See Plugin Protocol for the full wire specification and JSON schemas.

  • Zero language lock-in: Each plugin is a standalone executable spawned by the host over stdio NDJSON, with no Rust crate dependency on ox-core internals.
  • One protocol for every surface: A single plugin process can provide tools, slash commands, lifecycle hooks, system prompt sections, attachment converters, compaction, and contextual hints.
  • Declarative configuration: Users configure plugins under [[plugins]] in config.toml, passing custom env variables and an arbitrary config object that ox forwards in initialize.
  • Safe defaults and graceful lifecycle: The host inherits plugin stderr for diagnostics, enforces per-request timeouts (timeout_ms), sends shutdown on exit, and terminates the child process on exit.

Register a plugin executable in config.toml under [[plugins]]:

[[plugins]]
name = "my-plugin"
command = ["/path/to/my-plugin", "--stdio"]
timeout_ms = 30000
env = { MY_PLUGIN_MODE = "strict" }
config = { retries = 3 }

After spawning the process, ox sends initialize with protocol_version, config, and state_db_path. Your plugin responds with a PluginManifest declaring the capabilities it provides.

Declare tools with JSON Schema input_schema entries in PluginManifest.tools. When the model invokes a plugin tool, the host sends tool/call with name and arguments and returns { content, is_error } to the model.

Declare slash commands in PluginManifest.commands (with optional default_keybinding) or serve them dynamically via command/list.

  • Use command/invoke to receive the raw argument string alongside runtime context (state_db_path, session_id, cwd, model, and provider) and return { content, description, mode }, where mode is "markdown", "system", or "prompt".
  • Plugins can override the built-in /stats command by advertising a command named stats. The host injects OX_STATE_DB into the plugin environment and passes state_db_path in initialize and command/invoke, allowing a custom /stats plugin to query $XDG_STATE_HOME/ox/state.db directly.

Set "compaction": true in PluginManifest to handle automatic and manual (/compact) conversation compaction via compaction/compact. The host sends the older messages, optional previous_summary, user focus, hook_guidance from PreCompact hooks, trigger, and active model. If a plugin declines or returns an error, ox falls back automatically to its built-in LLM summarizer.

Subscribe to lifecycle events in PluginManifest.hooks with optional matcher and on_error fields. The host delivers hook/invoke with the same HookInput payload used by command hooks, letting your plugin inspect, block, or rewrite tool inputs.

Inject domain-specific instructions into the system prompt by returning static prompt_sections in PluginManifest or implementing prompt/sections to compute sections dynamically for the current working directory (cwd).

Advertise supported MIME types or wildcard patterns (such as "application/pdf" or "video/*") in PluginManifest.attachment_converters. When a model does not accept an attachment’s media type or size natively, the host calls attachment/convert with either inline data_base64 or a local file path, and your plugin returns wire-neutral ContentBlock items such as extracted text or rendered images.

Surface lightweight, contextual tips in the TUI hint bar either statically through PluginManifest.hints or dynamically during a request with the host/emit_hint callback. To keep the interface uncluttered, ox enforces anti-abuse guardrails on plugin hints:

  • Namespacing: Hint IDs are namespaced as <plugin_name>:<id> so plugins cannot collide with built-in or third-party hints.
  • Sanitization: Hint text is sanitized before display.
  • Priority clamping: Plugin hint priorities are clamped to the allowed plugin range.
  • Rate-limiting: Per-hint show caps, cooldowns, and minimum intervals from [tui.hints] apply automatically.

While handling an in-flight request, a plugin can send JSON-RPC requests or notifications back to the host on stdout. See Plugin-to-Host Callbacks for parameter and result fields:

Method Purpose
host/log Emit structured diagnostics (level, message, optional target)
host/ask_permission Prompt the user through the host permission gate before sensitive work
host/invoke_tool Call another registered tool through the host
host/complete Request a one-shot LLM completion from the configured provider
host/emit_hint Emit a dynamic contextual hint to the TUI hint bar

The workspace ships three official out-of-process plugins under plugins/:

  • ox-plugin-mcp: Bridges stdio and Streamable HTTP MCP servers as plugin tools.
  • ox-plugin-stats: Overrides /stats by querying the SQLite state database and advertising a contextual TUI hint.
  • ox-plugin-compaction: Implements compaction/compact using the host/complete callback.
  • Plugin Protocol: Complete NDJSON-RPC 2.0 request, response, and callback schemas.
  • MCP Plugin: Configuring ox-plugin-mcp for stdio and Streamable HTTP MCP servers.
  • Compaction: Automatic and manual compaction, preservation, and session boundaries.
  • Hooks: Lifecycle hook events, matchers, and error policies.
  • Configuration: Layering config.toml and bundling plugins in package_roots.