Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix(terminal): let Claude Code follow the app theme instead of pinning it at spawn

Chaitanya Giri844f011a6029
diff --git a/src/main/hive.ts b/src/main/hive.ts
index 1493d249..7d05ad4d 100644
--- a/src/main/hive.ts
+++ b/src/main/hive.ts
@@ -1002,7 +1002,15 @@ export class HiveManager {
// Match the TUI's truecolor palette to the harness terminal theme —
// PER SESSION, so the user's global Claude theme (their own terminals
// outside the app) is never touched.
- ...(theme ? { theme } : {}),
+ //
+ // 'auto', not the literal light/dark. Pinning the value matched the theme at
+ // SPAWN and then ignored every change: Claude Code supports DEC 2031 theme
+ // notifications, but a pinned theme has nothing to reconsider, so flipping
+ // the app left a running agent painting its message blocks in the old
+ // palette (black highlight on a cream terminal). 'auto' is the value that
+ // listens. The terminal reports the current theme the moment the CLI enables
+ // 2031, so startup still matches without pinning anything.
+ ...(theme ? { theme: 'auto' } : {}),
// W3 — default skills/MCP bundle. Written into the PER-SESSION settings file
// only (never ~/.claude), so the user's own MCP servers are never clobbered;
// Claude merges this additively. Omitted entirely when empty so a settings
diff --git a/src/renderer/src/components/termColor.ts b/src/renderer/src/components/termColor.ts
index 9105c045..26a42e05 100644
--- a/src/renderer/src/components/termColor.ts
+++ b/src/renderer/src/components/termColor.ts
@@ -29,3 +29,18 @@ export function oscColorBody(rgb: [number, number, number]): string {
const wide = (v: number) => v.toString(16).padStart(2, '0').repeat(2);
return `rgb:${wide(rgb[0])}/${wide(rgb[1])}/${wide(rgb[2])}`;
}
+
+/**
+ * Is this background colour a dark one?
+ *
+ * Used to answer "which theme are we?" for a program that just enabled DEC 2031,
+ * where the only thing we hold is the palette itself. Rec. 601 luma, which is
+ * good enough for a light/dark split and does not need the full sRGB transfer
+ * curve.
+ */
+export function isDarkBackground(hex: string): boolean {
+ const rgb = parseHexColor(hex);
+ if (!rgb) return true; // unknown: assume dark, the safer default for a terminal
+ const [r, g, b] = rgb;
+ return (0.299 * r + 0.587 * g + 0.114 * b) < 128;
+}
diff --git a/src/renderer/src/components/terminalPool.ts b/src/renderer/src/components/terminalPool.ts
index 7046d6c2..64fcde59 100644
--- a/src/renderer/src/components/terminalPool.ts
+++ b/src/renderer/src/components/terminalPool.ts
@@ -81,7 +81,7 @@ export interface TerminalEntry {
const pool = new Map<string, TerminalEntry>();
-import { parseHexColor, oscColorBody } from './termColor';
+import { parseHexColor, oscColorBody, isDarkBackground } from './termColor';
type ThemeMap = Record<string, string>;
@@ -302,6 +302,12 @@ export function acquireTerminal(ptyId: string, theme?: ThemeMap, fontSize = 14):
term.parser.registerCsiHandler({ prefix: '?', final: 'h' }, (params) => {
if (params.includes(2031)) {
entry.themeNotify = true;
+ // The protocol expects the CURRENT theme the moment a program opts in, not
+ // only on the next change. Without this a CLI set to follow the terminal has
+ // nothing to go on at startup and falls back to its own default, which is
+ // how a light window ended up with black message highlights.
+ const bg = (term.options.theme as ThemeMap | undefined)?.background;
+ notifyThemeChange(ptyId, bg && !isDarkBackground(bg) ? 'light' : 'dark');
// Deliberately logged. Whether a TUI opts in is the difference between "the
// theme fix works" and "we are talking to something that is not listening",
// and that is not observable from the outside.
diff --git a/test/osc-color-reply.test.cjs b/test/osc-color-reply.test.cjs
index ee0c5284..4949be02 100644
--- a/test/osc-color-reply.test.cjs
+++ b/test/osc-color-reply.test.cjs
@@ -4,7 +4,7 @@ const test = require('node:test');
const assert = require('node:assert/strict');
const loadTs = require('./load-ts.cjs');
-const { parseHexColor, oscColorBody } =
+const { parseHexColor, oscColorBody, isDarkBackground } =
loadTs('src/renderer/src/components/termColor.ts');
// A TUI asks the terminal for its colours with OSC 10/11 and styles itself from
@@ -38,3 +38,23 @@ test('the reply widens each byte the way xterm does', () => {
assert.equal(oscColorBody(parseHexColor('#1a2b3c')), 'rgb:1a1a/2b2b/3c3c');
assert.equal(oscColorBody(parseHexColor('#000')), 'rgb:0000/0000/0000');
});
+
+// --- light/dark split for the DEC 2031 report ----------------------------
+// A program that enables 2031 expects the CURRENT theme immediately. All we hold
+// at that moment is the palette, so the answer is derived from its background.
+
+test('the app palettes classify correctly', () => {
+ assert.equal(isDarkBackground('#FCFAF0'), false, 'the cream light background');
+ assert.equal(isDarkBackground('#1A1A1F'), true, 'the ink dark background');
+});
+
+test('an unreadable background assumes dark', () => {
+ // Dark is the safer default for a terminal: a light-styled TUI on a dark
+ // background is unreadable, the reverse is merely ugly.
+ assert.equal(isDarkBackground('not a colour'), true);
+});
+
+test('the split sits where you would expect it', () => {
+ assert.equal(isDarkBackground('#000000'), true);
+ assert.equal(isDarkBackground('#ffffff'), false);
+});