Plugin Architecture in AI Coding Tools: How Everything-as-a-Plugin Works

    This article breaks down the plugin-based architecture of intelligent coding tools, where model adapters, tool execution, session logging, the agent loop, filesystem access, subprocesses, and sandbox policies all exist as plugins assembled through a configuration tree. It explains the role of the dependency injection container, how to build and debug a first plugin, the difference between compile-time and runtime configuration, the build pipeline, source versus build-output startup paths, workspace protocols, publishing and installation, configuration profiles, and the module resolution chain. Readers will learn a practical mental model for extending capabilities and troubleshooting loading issues layer by layer.

    1. Why “Everything Is a Plugin” Is the First Key to Understanding These Tools

    The core design principle of plugin-based intelligent coding tools (referred to as “these tools” below) is that there is no “privileged kernel” that requires patching to modify. Model adaptation, tool invocation, session logs, the agent main loop, filesystem access, subprocess execution, sandbox and approval policies—all exist as plugins and are composed into the final runtime through a configuration tree.

    Where beginners most often go wrong is this: packages with names containing “base” or “core” are usually not low-level libraries called via import, but rather a “composition manifest.” In a typical composition package, the package description file declares a custom composition marker field and ships with a configuration patch file that inserts dozens of plugin rows into an empty configuration tree. An excerpt:

    1. # Configuration patch of a composition package (illustrative)
    2. insert:
    3. - timer / hmr # timers and hot reload
    4. - llm / llm-adapter # model capability + specific model adapter
    5. - session # session event log and in-memory store
    6. - agent / agent-loop # agent interface + default main loop
    7. - tools / system-prompt# tool registry + prompt assembly
    8. - subprocess / shell # subprocess and command execution
    9. - sandbox / approval # sandbox and approval policies
    10. - fs / tool-fs # file access capability and policy
    11. - settings / credentials # user settings and credentials
    12. - subagent / workflow # subagents and workflows
    13. - web / tool-web # retrieval and fetching capability

    Making the “foundation” a plugin brings three direct benefits. First, replacement cost is extremely low: swapping the model adapter requires no changes to the main loop. Second, capabilities are trimmable: headless scenarios can omit UI-related plugins. Third, policies are pluggable: approval and sandbox implementations can be replaced with stricter ones without touching business code. Once you understand this, everything that follows falls into place.

    2. The Foundation: Dependency Injection Container and Vendored Source

    These tools are typically built on a lightweight dependency injection and lifecycle container. The container handles three things: service registration and resolution, loading plugins in dependency order, and pluggable hooks (an event bus). So that plugin developers can jump directly to reading the container implementation, engineering practice often vendors the container source into the repository, paired with source maps, so breakpoints, call stacks, and type definitions all land on the real implementation.

    A common misconception needs clearing up: the container is not “the whole framework.” It only solves assembly and lifecycle; concrete capabilities still come from plugins. So when troubleshooting, the first step is always to confirm “which plugin is responsible for this,” not to dig through container code.

    3. Your First Plugin: Start by Fixing an Editor Error

    The best path into plugin development is fixing a real, small problem. A typical flow:

    1. Create a package description file under the plugin directory, declaring the name, entry point, and the container types it depends on;
    2. In the entry exports, declare the services the plugin needs (dependency injection) and the services it provides;
    3. Register commands, event listeners, or tools in lifecycle hooks;
    4. Mount the plugin onto the configuration tree via a local debug configuration, and observe load order and errors.

    Illustrative code:

    1. export const inject = ['tools', 'session'];
    2. export function apply(ctx) {
    3. ctx.on('session/start', (s) => { /* log or validate */ });
    4. ctx.tools.register({ name: 'demo', run: async () => ({ ok: true }) });
    5. }

    The key to debugging is understanding the two error types the container throws: “service not satisfied” and “circular dependency.” The former means the required service is not provided by any plugin; the latter means the assembly order forms a cycle and responsibilities need to be split.

    4. Configuration Clarified: What Compile Options Actually Control

    Beginners often conflate compile configuration with runtime configuration. Three layers must be distinguished:

    • Compile layer: target syntax version, module output format, strict mode, declaration output;
    • Type layer: type roots, path mapping, project references;
    • Runtime layer: module resolution algorithm, package export fields, conditional exports.

    The compile layer determines “whether type checking passes”; the runtime layer determines “whether files can be found at load time.” When the two disagree, you get the classic problem of “compiles fine but fails at runtime with module not found.”

    5. The Build System: What Happens Behind a Single Build Command

    A single build command typically chains these steps: clean the output directory, compile subpackages in dependency topological order, generate type declarations, produce a distributable directory, and finally validate the output. The key point is topological order: dependencies must be built first, otherwise missing type declarations cause downstream failures.

    Engineering recommendations: give each subpackage its own output directory and declaration files; enforce strict mode uniformly in the root configuration; make “output validation” the last step of the build so problems are not deferred to runtime.

    6. Two Startup Paths: Source Startup and Output Startup

    • Source startup: load directly from the source entry, with source maps and hot reload, suitable for development and debugging;
    • Output startup: load the built directory, with resolution going through package export fields, suitable for verifying the release form.

    The resolution rules differ between the two paths, which is the root cause of “works locally but not after installation.” The recommended practice is to run a full smoke test through the output path before release.

    7. Workspace Mechanism: Two Ways to Declare Local Dependencies

    Multi-package repositories typically use the workspace protocol to declare internal dependencies; the build system and installer replace them with local links, avoiding duplicate downloads and version drift. Key points:

    • Use the workspace protocol uniformly for internal dependencies; the tooling replaces it with the real version number at publish time;
    • The linking method must match the startup path: symlinks work well under the source path but may expose export field problems under the output path;
    • After changing an internal package, rebuild; otherwise downstream consumers get stale output.

    8. Publishing and Installation: From Local Plugin to Installable Package

    Recommended publishing flow: version number and changelog, an output directory allowlist, type checking before packaging, and installing into a clean environment to verify after packaging. On the installation side, plugins should be loadable from three sources—local directory, archive, or repository address—and written into the corresponding location in the configuration tree after loading.

    9. Configuration Profiles: The Role of the User-Level Directory

    The user-level directory typically has a “configuration profile” concept, where each profile is an independent configuration tree and plugin set. Its value lies in isolation: the default profile is for daily use, while an experimental profile validates new plugins without cross-contamination. Switching profiles switches the entire capability composition—this is how “composition over inheritance” is realized in these tools.

    10. The Full Module Resolution Chain

    The decision order for a single load can be summarized as: entry fields and conditional exports → package export maps → file extension completion → directory index → path mapping → link resolution. A missing link at any stage shows up as “module not found.” Verifying layer by layer in this order when troubleshooting is far more efficient than blindly changing configuration.

    11. Mental Model and Best Practices

    Compress the whole system into one sentence: the container handles assembly, plugins provide capabilities, composition packages provide the manifest, profiles provide isolation, and resolution rules run throughout. Practical recommendations: read the composition package’s configuration patch before starting; validate through the output path before release; treat the approval and sandbox plugins as the security boundary; write a minimal smoke test for every plugin. With this model in hand, whether extending tool capabilities or troubleshooting loading issues, you can quickly locate the right layer.