Introduction
Bunli’s plugin system provides a powerful way to extend CLI functionality with a type-safe, hook-based architecture. Plugins can:- Modify configuration during initialization
- Register new commands dynamically
- Inject context and behavior before/after command execution
- Maintain typed shared state across the CLI lifecycle
- Add middleware to the command pipeline
Architecture
The plugin system is built around four core lifecycle hooks:Lifecycle Order
setup- Called during CLI initialization, can modify config and register commandsconfigResolved- Called after configuration is finalized (config is now immutable)beforeCommand- Called before each command executionafterCommand- Called after each command execution, receives result or error
Official Plugins
Bunli ships with four official plugins:AI Detection
Detect AI coding assistants from environment variables
Completions
Generate shell completion scripts (bash, zsh, fish)
Config Merger
Load and merge configuration from multiple sources
MCP Integration
Create CLI commands from Model Context Protocol tool schemas
Plugin Capabilities
Configuration Modification
Plugins can modify CLI configuration during thesetup hook:
Command Registration
Dynamically register commands:Type-Safe Store
Share typed state across the CLI lifecycle:Middleware
Add middleware to the command pipeline:Use Cases
Authentication
Metrics & Telemetry
Feature Flags
Environment Detection
Plugin Composition
Compose multiple plugins into one:- Merges all plugin stores
- Runs all hooks in sequence
- Combines behavior from multiple plugins
Next Steps
Creating Plugins
Learn how to create custom plugins
Plugin Hooks
Deep dive into lifecycle hooks
Plugin Store
Master type-safe shared state
Official Plugins
Explore official plugin implementations