Skip to content

Bug: configuring clang-format, air or uv by name silently disables the formatter #46868

Closed

Description

@devYRPauli

Description

Configuring clang-format, air or uv in the formatter section silently turns that formatter off. The name works for disabled: true, but any other override kills it.

packages/opencode/src/format/index.ts:134 looks up the built-in with Formatter[name as keyof typeof Formatter], where name is the config key. That reads the module's export identifier, not the formatter's published name. Three built-ins differ between the two:

config key, as the docs publish it export identifier in format/formatter.ts
clang-format clang
air rlang
uv uvformat

For those three the lookup returns undefined. The next lines then build the entry from builtIn ?? { extensions: [] } and set enabled to async () => info.command ?? false. With no command in the config, enabled always returns false, and the built-in extensions are replaced by an empty list. The formatter is gone.

The published name is the right key. formatters is already keyed by item.name at index.ts:130, status() reports item.name, and docs/formatters.mdx lists clang-format, air and uv in its Built-in table. The docs also say "You can configure built-in formatters with options like environment or extensions", which is the case that breaks.

Steps to reproduce

  1. Put this in opencode.json:
{
  "$schema": "https://opencode.ai/config.json",
  "formatter": {
    "clang-format": {
      "environment": { "CLANG_FORMAT_STYLE": "file" }
    }
  }
}
  1. Run opencode and inspect the formatter status.

clang-format reports extensions: [] and enabled: false. Writing a .c file does not format it. Removing the clang-format block restores the formatter, so adding an override is what disables it.

The same happens with air and with uv. A correctly named built-in such as gofmt is not affected, because its export identifier and its name match.

Measured

Added to packages/opencode/test/format/format.test.ts on ef27925, with Formatter.clang pointed at a scratch extension and a command that appends C:

config: { formatter: { "clang-format": {} } }
file contents after Format.file()   expected "xC"   actual "x"

The command never runs. The same config for all three names makes status() return an empty extensions list for each, instead of the built-in list.

OpenCode version

Built from source at ef27925.

Operating System

macOS 26.6.2

Activity

  1. argszero commented on Sep 2, 2026

    @argszero
    Contributor

    Good catch and precise trace. One important scoping note for anyone picking this up: this bug exists on the legacy dev code path (packages/opencode/src/format/index.ts), but it is already resolved on the current v2 line, where the formatter layer was rewritten.

    On v2 (packages/core/src/formatter/builtins.ts), each built-in now carries its published name as Info.name — clang-format (const clang), air (const air), uv (const uv) — and the config merge in packages/core/src/config/plugin/formatter.ts resolves overrides by name, not by export identifier:

    const builtIn = builtIns.find((formatter) => formatter.name === name)

    So configuring { "formatter": { "clang-format": { "environment": { ... } } } } on v2 finds the built-in correctly and preserves its extensions/enabled. The same holds for air and uv.

    The dev-line lookup at packages/opencode/src/format/index.ts:134 (Formatter[name as keyof typeof Formatter]) is the one that breaks for clang-format / air / uv, exactly as you describe. If a fix is wanted on dev, the minimal change is to key the override lookup by each built-in's name property instead of its export identifier — matching the two disabled/remove paths that already use the config key — or to add the three alias mappings. The v2 rewrite shows the intended direction (resolve by item.name).

  2. devYRPauli commented on Sep 2, 2026

    @devYRPauli
    Author

    I cannot find that v2 code. Measured against dev at ef27925, which is the default branch.

    GET contents/packages/core/src/formatter/builtins.ts?ref=dev         404
    GET contents/packages/core/src/config/plugin/formatter.ts?ref=dev    404
    code search for "formatter.name === name" in this repo               0 hits
    

    packages/core/src/config/plugin/ exists, and holds agent.ts, command.ts, external.ts, provider.ts, reference.ts and skill.ts. It has no formatter.ts. The only formatter module under packages/core/src/config is formatter.ts at that level, which defines the schema and not the merge.

    If the rewrite lives on a branch, name it and I will read it there.

    The scoping point stands either way. #46869 keys the built-ins by Info.name and reads that map for the override lookup, which is the direction you describe.

  3. argszero commented on Sep 3, 2026

    @argszero
    Contributor

    The branch is v2 — the repository's active development branch per the AGENTS.md convention ("Base all new branches and worktrees on v2"). The GitHub default branch is dev, which is why the ref=dev lookups 404: the formatter rewrite lives on v2, not on dev.

    Paths on the v2 branch:

    • packages/core/src/formatter/builtins.ts — built-ins carry their published name as Info.name (clang-format, air, uv), and
    • packages/core/src/config/plugin/formatter.ts — the override merge resolves with builtIns.find((formatter) => formatter.name === name).

    So the v2 behavior matches what #46869 implements on the dev line (keying built-ins by Info.name). Recent v2-only merges confirm the workflow (e.g. #46866, #46864, #46857 all merged into v2 this week). Your #46869 is the right direction for dev; if the maintainers prefer to converge on v2, the fix is already inherent there and #46869 may only be needed for the legacy line.

  4. devYRPauli commented on Sep 3, 2026

    @devYRPauli
    Author

    Confirmed. My check was wrong about how to read the branch, not about the paths. GitHub code search indexes the default branch only, which is dev, so it returns nothing for v2. The git tree API at refs/heads/v2 shows both files: packages/core/src/formatter/builtins.ts and packages/core/src/config/plugin/formatter.ts.

    v2 resolves the override with builtIns.find((formatter) => formatter.name === name), so this bug is already fixed there. #46869 only helps the dev line.

    v2 is also where the work lands. Of the last 40 merged pull requests, 36 target v2 and 4 target dev. The v2 AGENTS.md says the default branch is v2 and that pull requests should target v2. The dev copy still names dev, which is why I read that one.

    One defect does carry over to v2. packages/core/src/tool/plugin/edit.ts compares input.oldString === input.newString on the raw input near the top. It converts both strings to the file's line ending about thirty lines below that check. So a CRLF file takes oldString spelled CRLF and newString spelled LF past the guard. After the conversion the two are equal. The edit then writes the file back unchanged and reports one replacement. That is what #46849 fixes on dev, and the same gap is in the new file.

    packages/opencode does not exist on v2, so #46860 is a dev line fix only.

  5. neriousy commented on Oct 19, 2026

    @neriousy
    Member

    This is fixed in v2, as confirmed above: formatter overrides are matched by their published names, so configuring clang-format, air, or uv preserves the built-in extensions and enablement unless explicitly overridden.

    To get v2, run npm i -g @opencode/cli@latest. If you still see this on v2, please open a new issue with the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions