Repository navigation
Plugins
A plugin runs managed code inside Kodo. Use it for anything that is not language intelligence: panels, commands, menus, previews, status indicators, integrations with external tools.
Shipped examples: HelloWorld and TemplatePlugin in Kodo-Extension-Template.
If you are adding syntax, completions, diagnostics, or navigation, you want a language extension, not a plugin. Keep parsing out of plugins.
public interface IKodoPlugin
{
void OnLoad(MainWindow window, LoadedExtension extension);
void OnUnload();
void RegisterCommands(KodoPluginCommandRegistry commands);
}| Member | When it runs | Notes |
|---|---|---|
OnLoad |
Once per plugin instance, after Kodo loads the assembly | Runs on the UI thread. window is the live MainWindow. |
RegisterCommands |
Immediately after that instance's OnLoad
|
Optional; runs on the UI thread. Override it to add commands to Ctrl+Shift+P. Kodo removes registrations automatically when the plugin unloads. (If an assembly has several plugin classes, each instance gets its own OnLoad โ RegisterCommands pair in turn.) |
OnUnload |
Before the plugin is removed, replaced, or reloaded | No arguments. Must be safe to call even if OnLoad failed partway. |
RegisterCommands has a default no-op implementation, so existing plugins do not need to add it.
Kodo finds your plugin by reflection. The class must be:
- not
abstract - implement
Kodo.IKodoPlugin - instantiable with a public parameterless constructor (
Activator.CreateInstanceneeds one)
The type itself does not need to be public - Kodo filters on IsAbstract and the interface
only, so an internal plugin class works fine. (The constructor does need to be public, because Kodo
instantiates via Activator.CreateInstance.)
Every matching class in the assembly is instantiated. One DLL may contain several plugins. Note: a class without a usable parameterless constructor throws during instantiation and aborts loading the whole assembly - already-created instances are unloaded and the failure is recorded in the Extensions error list. Keep every discovered class constructible, or hide helpers from discovery (abstract, or don't implement the interface).
OnUnload receives no arguments because the plugin is expected to have kept hold of whatever it
created. Store your controls, handlers, timers, and subscriptions in fields.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<AssemblyName>MyPlugin</AssemblyName>
<RootNamespace>MyPlugin</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<!--
Match Kodo's Avalonia version exactly (check Kodo/Source/Kodo.csproj), and use
ExcludeAssets="runtime" so Avalonia is not copied into your output. Kodo already has
Avalonia loaded, so a second copy inside the .kox is a version conflict.
-->
<PackageReference Include="Avalonia" Version="12.1.5" ExcludeAssets="runtime" />
</ItemGroup>
<ItemGroup>
<Reference Include="Kodo">
<HintPath>..\..\Kodo\Kodo\Source\bin\Debug\net10.0\Kodo.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
</Project>| Setting | Why it matters |
|---|---|
net10.0 |
Must match Kodo exactly. A different TFM will not load. |
Private=false |
Stops a stale copy of Kodo.dll being copied into your output and shipped in the package. |
EnableDynamicLoading |
Correct SDK defaults for a library loaded at runtime. |
Avalonia version |
Must match the version in Kodo/Source/Kodo.csproj. Kodo upgrades this, and an older Avalonia can fail to load. |
ExcludeAssets="runtime" |
Keeps Avalonia out of your output. Without it, dotnet build copies ~4.5 MB of Avalonia DLLs into the folder you are about to zip, and Kodo ends up loading a second, conflicting copy. |
Without ExcludeAssets="runtime", a PackageReference to Avalonia copies the whole Avalonia set
into your build output. The output looks correct, so the mistake is easy to miss, and the packaged
plugin then carries a duplicate UI framework. Verified: with it set, the output is just your
assembly plus its .deps.json.
Build Kodo first so the reference resolves:
dotnet build Kodo/Source/Kodo.csprojAdjust HintPath to your checkout layout. The path is relative to your .csproj.
Ship any dependencies of your plugin alongside it. Kodo resolves sibling assemblies by exact
filename from the plugin folder only (no subfolder or runtimes/ search, and .deps.json is
never read - it is inert). Kodo's own assemblies resolve from the host; third-party framework
dependencies such as Avalonia must match Kodo's versions (see above).
using System;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Kodo;
using Kodo.Models;
namespace MyPlugin;
public sealed class HelloPlugin : IKodoPlugin
{
private Button? _button;
public void OnLoad(MainWindow window, LoadedExtension extension)
{
_button = new Button { Content = "Hello from MyPlugin" };
_button.Click += OnClick;
// Add a class alongside Content for styling hooks.
_button.Classes.Add("activity");
window.FindControl<Panel>("ActivityBarPanel")?.Children.Add(_button);
}
public void RegisterCommands(KodoPluginCommandRegistry commands)
{
commands.Register(
id: "hello.greet",
title: "Run Hello Plugin Greeting",
execute: () =>
{
if (_button is not null)
OnClick(_button, new RoutedEventArgs());
return Task.CompletedTask;
},
category: "Greeting",
keywords: "hello greeting sample",
detail: "Runs the plugin's greeting action");
}
private void OnClick(object? sender, RoutedEventArgs e)
{
// Do work here. Keep it fast; this is the UI thread.
}
public void OnUnload()
{
if (_button is null) return;
_button.Click -= OnClick;
if (_button.Parent is Panel panel) panel.Children.Remove(_button);
_button = null;
}
}Commands appear in the command palette's > mode under Plugin (or your category); the
extension name sorts results but is not a visible group header. The registry also supports an
optional canExecute predicate, display details, fuzzy-search keywords, a keepPaletteOpen
flag, and a shortcut badge (display only; it does not bind a key). Register throws on an empty
Id/Title, a null Execute, or a duplicate Id within the same registry (the same Id in
different extensions is allowed). Register returns an IDisposable for commands you want to
remove early; all remaining commands are removed automatically before OnUnload runs. Keep
command handlers fast and return a Task for asynchronous work.
{
"id": "hello-plugin",
"version": "1.0.0",
"name": "Hello Plugin",
"type": "plugin",
"author": "Your Name",
"description": "Adds a small greeting command.",
"plugin": "MyPlugin.dll"
}plugin must name the assembly inside the package. Kodo first looks for that exact filename
(case-insensitively, anywhere in the archive), then falls back to a recursive search, so a
nested or differently-cased copy still loads. Loading is driven by the plugin field being
present, not by type: plugin - a package of any type that names an assembly will load it.
A wrong/missing name means nothing loads; failures are recorded in the Extensions page error
list (not shown as a dialog).
- Kodo extracts every
*.dllfrom the.koxinto%LocalAppData%\Kodo\PluginCache\. On non-Windows it also extracts*.soand*.dyliband marks them executable, so a plugin can carry a native dependency. - It creates an
AssemblyLoadContextwithisCollectible: true. - The main assembly is loaded from a shadow copy - the bytes are read into memory and loaded from a stream, so the file on disk is never locked and can be replaced while Kodo runs.
- Sibling assemblies are resolved from the plugin folder by exact filename (no subfolder search), also shadow-copied.
- Every
IKodoPluginimplementation in the assembly is constructed,OnLoadis called, and thenRegisterCommandsis called (per instance, in turn). Kodo filters onIsAbstractand the interface only - it does not require the type to bepublic, so aninternalplugin class works. There is no "pick one entry point" mechanism, so every implementation in the assembly runs. A plugin whose extensionidis exactlygit-source-controlis silently excluded from plugin loading entirely. - On unload, Kodo removes each instance's registered commands, calls
OnUnload, and then unloads the context.
Consequences worth designing around:
- Because files are shadow-copied, you can rebuild and reinstall without fighting file locks.
Because the context is collectible, a clean unload is possible - if your
OnUnloadreleases your references. A plugin that roots itself through a static event or a running timer will not actually be collected. - An unpacked plugin folder is used in place rather than extracted (the assembly is still shadow-copied on load). Note: a LangRules assembly from the same folder is not shadow-copied - it loads from its real path, keeping the file locked.
Kodo decides whether to reload a plugin by comparing the effective version - the maximum of
the manifest version and any version parsed from the source filename (e.g. v1.2.0 in
MyPlugin-v1.2.0.kox) - as a case-sensitive string, not semver. If it matches the loaded plugin,
it is left alone. Changing only the plugin filename with the same version does not reload either.
So rebuilding your DLL is not enough. To see a change, bump version in manifest.json. Without
that, the new build sits on disk ignored and the old code keeps running, which reads exactly like
"my change had no effect".
A collectible context also means this does not need a restart, including for LangRules assemblies.
Plugins cannot write to Kodo's log. KodoDiagnostics declares public methods, but the class
itself is internal, so it is unreachable from a plugin assembly. What you have:
| Option | Reaches |
|---|---|
Console.WriteLine |
The terminal Kodo was launched from. What Kodo's own plugin loader uses. |
Debug.WriteLine |
An attached debugger only. |
Console output is invisible when Kodo is launched from Explorer, a file manager, or an IDE without a
terminal. Load failures are recorded in the Extensions page error list (and on the console), not
shown as dialogs - the loader uses Console.WriteLine, not Kodo's verbose log, so verbose logging
in settings does not capture them. Plan for a deployed plugin being close to undebuggable, and
prefer surfacing problems in your own UI over relying on diagnostics.
A language package can carry a plugin for host integration - extra buttons, panels, or commands -
without giving up the language engine. Name the assembly in languagePlugin:
{
"id": "mylang-kodo-extension",
"type": "language",
"extensions": [".myl"],
"plugin": "LangRules.dll",
"languagePlugin": "MyLangUi.dll"
}languagePlugin uses the identical IKodoPlugin lifecycle. The distinction is organizational:
plugin is the assembly Kodo treats as the package's primary code, languagePlugin is an extra
plugin shipped alongside a language. See
plugin vs languagePlugin.
Notes:
- The
pluginassembly is also tried as a LangRules provider - a plugin DLL containing a staticLangRulesclass or anILangRulesProvideris dual-loaded as both. -
languagePlugin: "TagAutoClose.dll"(case-insensitive) is intercepted: the external DLL is never loaded; Kodo substitutes its built-in replacement instead.
Do not block the UI thread. OnLoad and every event handler you own run on it. Use
async/await for I/O and Task.Run for CPU work, and marshal back with
Dispatcher.UIThread. A plugin that blocks the thread freezes the whole editor.
Always pair creation with teardown. If OnLoad adds a control, subscribes a handler, or starts a
timer, OnUnload must undo all of it. Otherwise reloading the extension duplicates UI or leaks a
running background task.
Be defensive at the boundaries. Find controls with FindControl<T>(...) and handle null -
the UI may change, or the control may not exist in the page you expected. Never assume a control
named in this guide is present forever.
Do not silently overwrite user data. If your plugin writes files, write somewhere the user chose, tell them what you are doing, and never clobber unrelated content.
Validate external input. File paths, command-line output, and network responses are all untrusted.
Do not put language intelligence in a plugin. Parsing belongs in a language engine so it is testable and does not fight the editor's own analysis.
hello-plugin/
โโโ manifest.json
โโโ MyPlugin.dll
โโโ AnyDependency.dll ship what you need (resolved by exact filename, root only)
โโโ icon.png optional
โโโ LICENSE.txt recommended
Compress-Archive -Path .\hello-plugin\* -DestinationPath .\hello-plugin-1.0.0.zip
Rename-Item .\hello-plugin-1.0.0.zip .\hello-plugin-1.0.0.koxNever include Kodo.dll in the package. Kodo provides it, and shipping a copy causes assembly
conflicts.
To submit to the marketplace, add the .kox to Extensions/ and an entry to
Indexs/PluginsIndex.json in Kodo-Extensions. See
Kodo file format#submitting-to-the-marketplace.
- Build Kodo, then build your plugin in
Release. - Confirm the output DLL name - the manifest must match it exactly.
- Copy the folder (or
.kox) into%LocalAppData%\Kodo\Extensions\. - Start Kodo and confirm the plugin loaded.
- Exercise the feature.
- Reload the extension and confirm the UI did not duplicate. This is the single most common bug, and it only shows up here.
- Restart Kodo and confirm nothing is left running - no orphaned processes, no growing memory.
Load failures appear in the Extensions page error list (and on the console); there is no dialog. Kodo's verbose logging setting does not capture plugin loader output.
| Symptom | Check |
|---|---|
| Plugin is listed but does nothing |
type is plugin; plugin matches the DLL filename exactly; the assembly is at the package root |
| Nothing loads at all | the type is non-abstract, implements IKodoPlugin, and has a public parameterless constructor (public on the type is not required) |
TypeLoadException or missing-type errors |
TargetFramework is not net10.0; a dependency DLL is missing from the package |
| Reloading duplicates UI |
OnUnload did not remove the controls or unsubscribe the handlers it added |
| Memory grows on reload | something is rooted - a static event subscription, a running timer, or an unobserved task |
| The editor freezes | blocking work on the UI thread in OnLoad or a handler |
FindControl returns null |
the control name changed, or the page is not currently realised |
- Extension development - which kind of extension to build
- Kodo file format - manifest fields, packaging, marketplace
-
Language extensions - the
languagePluginfield in context
Kodo is licensed under the GNU GPL-v3.0. Extension developers: see the EXTENSIONS_LICENSE in the main repository.