DSH Quality
Beginner
3 min read

Understanding the Plugin Lifecycle

Understanding the Plugin Lifecycle — Learn how to build beginner dsh plugins.

Last updated: 2026-08-26

The lifecycle you need to know

A dsh plugin goes through a well-defined lifecycle: initialization, activation, runtime, and shutdown. Understanding this helps you write plugins that clean up after themselves.

Initialization

ts
export function apply(ctx, config) {
  // 1. Register capabilities
  ctx.commands.register('my-cmd', { ... });
  ctx.tools.register({ ... });

  // 2. Set up cleanup
  ctx.onShutdown(() => {
    cleanupResources();
  });

  // 3. Return nothing — the lifecycle is managed by dsh
}

Activation and deactivation

Plugins activate when the profile starts and deactivate when it stops. The onShutdown hook is your chance to close connections, release locks, and clean temp files.

State management

Keep plugin state in ctx properties, not global variables. This makes your plugin testable and profile-isolated.