OpenCode plugin that automatically formats .NET files (C#, F#, VB) using dotnet format whenever OpenCode edits them.
- Automatically runs
dotnet format style --severity infoon every edited .NET file - Walks up the directory tree to find the nearest solution or project file (
.slnx,.sln,.csproj,.fsproj,.vbproj) - Scopes formatting to the edited file only using
--include, so it runs fast - Supports all .NET file types:
.cs,.vb,.fs,.fsi,.fsx,.fsscript - Gracefully disables itself when
dotnetis not available on PATH
- OpenCode
- .NET SDK installed with
dotneton your PATH - An
.editorconfigin your project for formatting rules (recommended)
Add the plugin to your OpenCode config file:
Global (~/.config/opencode/opencode.json):
{
"plugin": ["@workedbeforepush/opencode-dotnet-format"]
}Project-level (opencode.json):
{
"plugin": ["@workedbeforepush/opencode-dotnet-format"]
}OpenCode installs npm plugins automatically at startup.
Copy src/index.ts to one of the plugin directories:
- Global:
~/.config/opencode/plugins/dotnet-format.ts - Project-level:
.opencode/plugins/dotnet-format.ts
Files placed in these directories are loaded automatically at startup.
file.edited event fires
|
v
Is the file extension .cs / .vb / .fs / .fsi / .fsx / .fsscript?
|
yes
|
v
Walk parent directories for *.slnx / *.sln / *.csproj / *.fsproj / *.vbproj
|
found
|
v
dotnet format style <project-file> --include <relative-path> --severity info
|
v
Log result (success or warning)
- OpenCode fires a
file.editedevent whenever a file is written. - The plugin checks if the file has a .NET extension.
- Starting from the file's directory, it walks up the tree looking for the nearest project or solution file in priority order:
.slnx>.sln>.csproj>.fsproj>.vbproj. - It runs
dotnet format stylescoped to that single file using--include. - Formatting rules come from your
.editorconfig— the plugin does not impose any rules of its own.
This plugin has no configuration options. It uses whatever rules your .editorconfig and analyzer settings define.
To control which style rules apply and at what severity, configure them in your .editorconfig:
[*.cs]
# Enforce var usage
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
# Namespace declarations
csharp_style_namespace_declarations = file_scoped:warning
# Using directives
dotnet_sort_system_directives_first = trueSee the .NET code style rule options documentation for all available settings.
Enable debug logging to see plugin output:
opencode --log-level DEBUGLook for log lines with service opencode-dotnet-format:
opencode-dotnet-format info dotnet-format plugin loaded
opencode-dotnet-format info Formatting: dotnet format style MyProject.sln --include src/MyFile.cs --severity info
If the plugin does not load:
- Verify
dotnet --versionworks in your terminal - Check that the plugin is listed in your config or placed in the plugins directory
- Ensure you are running OpenCode v1.4.0 or later
# Install dependencies
bun install
# Type check
bun run typecheck
# Build
bun run buildMIT