fix(tui): agent colors swap when changing default_agent config #9242

Open
opened 2026-02-16 18:11:59 -05:00 by yindo · 1 comment
Owner

Originally created by @bengoism on GitHub (Feb 13, 2026).

Originally assigned to: @rekram1-node on GitHub.

Bug

When setting default_agent: "plan" in opencode config, the TUI swaps the colors for build and plan agents. Build becomes purple and plan becomes blue, when it should always be blue for build and purple for plan.

Root cause

Agent colors in the TUI are assigned by index position in the sorted agent list, not by agent name. The list() function sorts agents so the default agent comes first:

sortBy([(x) => (cfg.default_agent ? x.name === cfg.default_agent : x.name === "build"), "desc"])

The color palette is then applied by index:

const colors = [theme.secondary, theme.accent, theme.success, ...]
return colors[index % colors.length]

So when default_agent changes, the sort order changes, and colors swap.

Fix

The color field and theme key lookup already exist on agents but are unused by the built-in agents. Pinning explicit color values on build and plan fixes the issue with a two-line change:

diff --git a/packages/opencode/src/agent/agent.ts b/packages/opencode/src/agent/agent.ts
index e338559be..5b5f1597c 100644
--- a/packages/opencode/src/agent/agent.ts
+++ b/packages/opencode/src/agent/agent.ts
@@ -78,6 +78,7 @@ export namespace Agent {
         name: "build",
         description: "The default agent. Executes tools based on configured permissions.",
         options: {},
+        color: "secondary",
         permission: PermissionNext.merge(
           defaults,
           PermissionNext.fromConfig({
@@ -93,6 +94,7 @@ export namespace Agent {
         name: "plan",
         description: "Plan mode. Disallows all edit tools.",
         options: {},
+        color: "accent",
         permission: PermissionNext.merge(
           defaults,
           PermissionNext.fromConfig({

User config overrides still work since the merge logic uses value.color ?? item.color.

Originally created by @bengoism on GitHub (Feb 13, 2026). Originally assigned to: @rekram1-node on GitHub. ## Bug When setting `default_agent: "plan"` in opencode config, the TUI swaps the colors for build and plan agents. Build becomes purple and plan becomes blue, when it should always be blue for build and purple for plan. ## Root cause Agent colors in the TUI are assigned by **index position** in the sorted agent list, not by agent name. The `list()` function sorts agents so the default agent comes first: ```ts sortBy([(x) => (cfg.default_agent ? x.name === cfg.default_agent : x.name === "build"), "desc"]) ``` The color palette is then applied by index: ```ts const colors = [theme.secondary, theme.accent, theme.success, ...] return colors[index % colors.length] ``` So when `default_agent` changes, the sort order changes, and colors swap. ## Fix The `color` field and theme key lookup already exist on agents but are unused by the built-in agents. Pinning explicit `color` values on `build` and `plan` fixes the issue with a two-line change: ```diff diff --git a/packages/opencode/src/agent/agent.ts b/packages/opencode/src/agent/agent.ts index e338559be..5b5f1597c 100644 --- a/packages/opencode/src/agent/agent.ts +++ b/packages/opencode/src/agent/agent.ts @@ -78,6 +78,7 @@ export namespace Agent { name: "build", description: "The default agent. Executes tools based on configured permissions.", options: {}, + color: "secondary", permission: PermissionNext.merge( defaults, PermissionNext.fromConfig({ @@ -93,6 +94,7 @@ export namespace Agent { name: "plan", description: "Plan mode. Disallows all edit tools.", options: {}, + color: "accent", permission: PermissionNext.merge( defaults, PermissionNext.fromConfig({ ``` User config overrides still work since the merge logic uses `value.color ?? item.color`.
yindo added the opentui label 2026-02-16 18:11:59 -05:00
Author
Owner

@bengoism commented on GitHub (Feb 13, 2026):

I have tried locally. so should be safe to commit the suggestion above. to reproduce the original issue try switching default_agent to plan in opencode cofig.

Image Image Image
@bengoism commented on GitHub (Feb 13, 2026): I have tried locally. so should be safe to commit the suggestion above. to reproduce the original issue try switching default_agent to plan in opencode cofig. <img width="991" height="825" alt="Image" src="https://github.com/user-attachments/assets/c1d983d7-9352-4e0b-88da-342351765f21" /> <img width="989" height="836" alt="Image" src="https://github.com/user-attachments/assets/4936f51a-890a-48b9-9dd9-f06698a0d9ba" /> <img width="988" height="837" alt="Image" src="https://github.com/user-attachments/assets/6ae32391-29c9-4802-b66a-94b44904dcc1" />
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9242