Skip to content

Plugin Lifecycle

Under development

The formal plugin lifecycle is being defined by the core team. This page describes the current working model as implemented for TokenPilot.

Every plugin on the LightMem2 platform follows a lifecycle managed by the core runtime. Understanding this lifecycle helps you reason about when your plugin code runs and what state is available.

Lifecycle States

text
                    ┌──────────┐
                    │   None   │  Plugin not present on disk
                    └────┬─────┘
                         │ install
                    ┌────▼─────┐
                    │ Installed│  Plugin downloaded/config written
                    └────┬─────┘
                         │ enable
                    ┌────▼─────┐
                    │  Enabled  │  Plugin loaded, hooks registered
                    └────┬─────┘
                    ┌────┴─────┐
                    │           │
               ┌────▼─────┐     │
               │  Running  │     │  Active during a session
               └────┬─────┘     │
                    │           │
                    └────┬─────┘
                         │ disable / uninstall
                    ┌────▼─────┐
                    │ Disabled  │  Plugin unloaded
                    └──────────┘

Lifecycle Hooks

Each transition calls a plugin hook. Plugins implement the hooks they need:

HookCalled WhenTypical Use
onInstallPlugin is first installedSet up config, register with host
onEnablePlugin is enabledInitialize state, start listeners
onSessionStartA new agent session beginsReset per-session state
onMessageA message is about to be sent to the modelModify context, apply policies
onToolResultA tool returns a resultTrim output, extract signals
onSessionEndA session endsPersist state, finalize metrics
onDisablePlugin is disabledStop listeners, release resources
onUninstallPlugin is removedClean up config, restore backups

TokenPilot implementation

TokenPilot's current implementation hooks into the host's event system via the adapter. The hook names above describe the logical lifecycle; the actual implementation uses host-specific mechanisms (OpenClaw plugin slots, Codex hooks, Claude Code MCP + SessionStart).

Plugin Conflict and Ordering

Under development

Rules for plugin execution order, conflict detection, and dependency resolution will be defined by the core team before additional plugins are released.

Currently, with only TokenPilot as the single official plugin, execution order is not a concern. When multiple plugins are active:

  • Each plugin declares its execution phase (e.g., pre-context, context-transform, post-response)
  • Plugins in the same phase run in declared priority order
  • The runtime detects conflicting data access and warns or errors at install time

Next

Released under the MIT License.