M31A has several extension points that are easy to confuse because they can all be shipped inside the same directory. This page separates their roles and describes the loading order.
The primary implementation is packages/cli/src/config/extension-manager.ts, with runtime activation in packages/core/src/utils/extensionLoader.ts.
The five extension points
| Mechanism | What it contributes | How the agent uses it |
|---|---|---|
| Extension | A distributable package containing any of the other assets, plus metadata and optional settings. | Loaded at startup; activates its contents. |
| Skill | Instructions in a SKILL.md file with YAML front matter. | Name and description are shown to the model; full body loads via activate_skill. |
| MCP server | External tools, resources, and prompts over stdio or HTTP. | Tools appear with a server-name prefix; resources via list_mcp_resources and read_mcp_resource. |
| Hook | A command or runtime action at a lifecycle event. | Receives JSON on stdin, returns JSON on stdout; can modify or block calls. |
| Slash command | A reusable prompt template in a .toml file. | Invoked by the user, not chosen by the model. |
An extension is therefore a packaging unit, not a single mechanism. A minimal extension is just a directory with m31a-extension.json.
1. Extension anatomy
The config file m31a-extension.json is typed by ExtensionConfig in packages/cli/src/config/extension.ts. Its fields include:
| Field | Meaning |
|---|---|
name, version | Required identity. |
mcpServers | Named MCP server definitions. |
contextFileName | Additional context file name or names. |
excludeTools | Tools hidden from discovery. |
settings | User-configurable values exposed to the extension. |
themes | Custom theme definitions registered at startup. |
plan.directory | Relative directory for plan artifacts. |
migratedTo | Source migration target for updates. |
Recognized subdirectories include commands/ (TOML commands), skills/ (skill directories), agents/, hooks/hooks.json, and policies/*.toml. Paths in config and hooks can be hydrated with variables such as ${extensionPath}, ${workspacePath}, and ${/} (the platform separator).
2. Loading order
ExtensionManager.loadExtensions() runs during CLI configuration:
- If
admin.extensions.enabledisfalse, no extensions load. - Installed extensions are discovered in the user extensions directory.
- Each config is validated; duplicate names are an error.
- Security filters apply:
security.blockGitExtensionsandsecurity.allowedExtensionscan reject a source. - Extension settings are hydrated from user and workspace scopes; workspace values win.
- Themes are registered early.
- Each extension is started: MCP servers connect,
excludeToolsrefreshes the tool registry, policy rules and safety checkers are added, and context files become visible to memory discovery. - Skills and agents are loaded from their directories.
Hook definitions are read from hooks/hooks.json only when hooksConfig.enabled is true. Extension policy files are loaded at tier 2, and extension ALLOW or YOLO rules are discarded.
experimental.extensionReloading enables enable, disable, and reload without restarting the CLI. Without it, changes require a new process.
3. Scopes and enablement
Settings scopes are user, workspace, system, and admin; they merge per-key using the strategies documented in Configuration. Extension enablement is tracked separately in extension-enablement.json inside the user extensions directory:
{
"my-extension": {
"overrides": ["/home/me/secret-repo/*", "!/home/me/secret-repo"]
}
}Overrides are path rules; the last matching rule wins, and ! disables. An extension is enabled by default when no rule matches. The -e/--extensions flag overrides the stored configuration for one invocation; -e none disables all extensions. CLI enable/disable accept user and workspace scopes.
extensions.disabled in settings provides another blocklist, while admin.extensions can restrict installation and use organization-wide.
4. Skills in detail
A skill is a directory whose SKILL.md has name and description front matter. The body contains the procedure and is loaded only after activation. Discovery precedence is built-in, extensions, user, workspace; later scopes override earlier ones by name. Workspace skills are skipped when the folder is not trusted.
m31a skills list [--all]
m31a skills link <path>
m31a skills enable <name>
m31a skills disable <name> [--scope]
m31a skills install <source> [--scope] [--path]
m31a skills uninstall <name> [--scope]In the TUI use /skills list|link|disable|enable|reload. skills.enabled defaults to true; skills.disabled lists names to skip, and admin.skills can restrict them further. See Skills.
5. MCP servers in detail
Servers can be declared in settings under mcpServers or contributed by an extension. The connection object supports stdio (command, args, cwd, env), SSE (url), streamable HTTP (url with type: "http"), and WebSocket (tcp) transports, plus timeout, headers, trust, and tool filters.
{
"mcpServers": {
"tools": {
"command": "node",
"args": ["./server.js"],
"timeout": 30000
}
},
"mcp": {"allowed": ["tools"], "excluded": []}
}McpClientManager in packages/core/src/tools/mcp-client-manager.ts owns the lifecycle. Tool names are prefixed with the server name, and admin settings can allowlist or require servers. OAuth tokens are stored locally. See MCP.
6. Hooks in detail
Hooks are configured in settings under hooksConfig (global controls) and hooks (per-event arrays), or inside an extension's hooks/hooks.json. Command hooks receive a JSON event on stdin and return JSON on stdout; the supported events are listed in Hooks.
TrustedHooksManager tracks command hooks per project in trusted_hooks.json; untrusted hooks are surfaced before they run. Hook commands execute with the privileges of the M31A process, so review extension hooks like executable code.
7. Slash commands in detail
FileCommandLoader in packages/cli/src/services/FileCommandLoader.ts recursively scans .toml files in user, project, and extension command directories. Commands load in the order user, project, extensions (alphabetically). User and project commands use last-wins conflict resolution; extension commands are renamed when they collide.
prompt = """
Summarize findings for `{{args}}`.
Results:
!{grep -r {{args}} .}
"""The command name comes from the file path relative to the commands directory. is the user's argument text and !{...} runs a shell fragment.
8. Interaction with trust and policy
- Project memory and commands are only loaded from trusted folders.
- Extension policies can deny or require confirmation but cannot allow.
- Hooks run before policy evaluation for tools and before the model request for
BeforeModel; they are not a substitute for the policy engine. - MCP servers can contribute arbitrary tool schemas, so server allowlists and admin constraints matter.
Next steps
- Build each piece in the tutorials: custom skill, custom hook, custom MCP server, and custom extension.
- Read Policy evaluation for precedence.