Plugin API

Clawdius supports a WASM-based plugin system with 26 hook types.

Overview

Plugins extend Clawdius's functionality by running custom logic in an isolated WASM runtime. This ensures plugins cannot compromise the host system.

Plugin Architecture

┌─────────────────────────┐
│    Clawdius Host         │
│  ┌───────────────────┐  │
│  │  Plugin Manager   │  │
│  │  ┌─────────────┐  │  │
│  │  │  WASM Runtime│  │  │
│  │  │  (Wasmtime)  │  │  │
│  │  └─────────────┘  │  │
│  └───────────────────┘  │
└─────────────────────────┘

Hook Types

Plugins can register handlers for 26 different lifecycle hooks:

CategoryHooks
Sessionsession_start, session_end, message_sent, message_received
Tooltool_before_execute, tool_after_execute, tool_error
LLMllm_before_request, llm_after_response, llm_error
Filefile_read, file_write, file_delete
Checkpointcheckpoint_created, checkpoint_restored
Gitgit_commit, git_push, git_checkout
Sandboxsandbox_enter, sandbox_exit, sandbox_violation
Configconfig_loaded, config_changed
Systemstartup, shutdown, error

Creating a Plugin

Plugins are WASM modules written in Rust (or any language that compiles to WASM):

#![allow(unused)]
fn main() {
// plugin/src/lib.rs
use clawdius_plugin_api::{register_hook, HookContext, HookResult};

#[register_hook("tool_after_execute")]
fn log_tool_usage(ctx: &HookContext) -> HookResult {
    println!("Tool {} executed in {}ms",
        ctx.params["tool"],
        ctx.params["duration_ms"]);
    HookResult::ok()
}
}

Plugin Configuration

Plugins are configured in .clawdius/config.toml or a separate plugins file:

[plugins]
load = ["./plugins/my-plugin.wasm"]

[plugins.hooks]
tool_after_execute = ["my-plugin"]

Plugin API Surface

Plugins receive a HookContext containing:

FieldTypeDescription
hook_name&strName of the triggered hook
paramsMap<String, Value>Hook-specific parameters
session_idOption<&str>Active session ID
config&ValueCurrent configuration

Plugins return a HookResult:

VariantDescription
ok()Allow the operation to proceed
block(reason)Block the operation
modify(data)Modify the operation's data

Security Model

  • Plugins run in WASM with capability-based permissions
  • No filesystem access unless explicitly granted
  • No network access unless explicitly granted
  • Fuel-based execution limits prevent infinite loops
  • Memory isolation prevents host memory corruption

Distribution

Plugins can be distributed as .wasm files and loaded from:

  • Local filesystem paths
  • The plugin marketplace (planned)
  • Remote URLs (with integrity verification)