Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(cli): a kitty graphics query never names a harness (#1565)

lingrd21bb381910e4
diff --git a/cli/e2e/harness/daemon.ts b/cli/e2e/harness/daemon.ts
index d5a8173e5..f56a7f286 100644
--- a/cli/e2e/harness/daemon.ts
+++ b/cli/e2e/harness/daemon.ts
@@ -56,6 +56,8 @@ export interface EngineConfig {
updateAvailable?: string
/** Ask whether to trust a folder the engine's own config has no answer for, as the real CLIs do. */
trustPrompt?: boolean
+ /** Send Claude Code's kitty graphics query on start, then set this title [titleAfterMs] later (fakeEngine.mjs). */
+ graphicsQuery?: { title: string; titleAfterMs: number }
}
export interface DaemonOptions {
@@ -92,6 +94,8 @@ export interface DaemonOptions {
port?: number
/** The fake engines ask whether to trust a folder their config has no answer for (fakeEngine.mjs). */
trustPrompt?: boolean
+ /** The fake engines send Claude Code's kitty graphics query on start, then set a title (fakeEngine.mjs). */
+ graphicsQuery?: { title: string; titleAfterMs: number }
}
async function freePort(): Promise<number> {
@@ -248,6 +252,7 @@ export class IsolatedDaemon {
...(options.submissionGate ? { submissionGate: true } : {}),
root, hookLog: join(own, 'fake-engine-hooks.log'),
...(options.trustPrompt ? { trustPrompt: true } : {}),
+ ...(options.graphicsQuery ? { graphicsQuery: options.graphicsQuery } : {}),
}
const engine = pathToFileURL(join(here, 'fakeEngine.mjs')).href
for (const name of ['claude', 'codex']) {
diff --git a/cli/e2e/harness/fakeEngine.mjs b/cli/e2e/harness/fakeEngine.mjs
index 37dd9f2b5..83a0475e7 100644
--- a/cli/e2e/harness/fakeEngine.mjs
+++ b/cli/e2e/harness/fakeEngine.mjs
@@ -367,6 +367,14 @@ export async function run(engine, config = {}, { native = false } = {}) {
process.stdout.write('\x1b[H\x1b[2J')
}
}
+ // `graphicsQuery`: Claude Code asks the terminal for kitty graphics, an APC string, when it believes it is not inside
+ // tmux, as a guest's harness on a shared machine does (its helper starts the engine with `env -i`, so no TMUX). tmux
+ // takes any APC string as the pane's title. Later it sets its title as usual (OSC 0, `title`).
+ if (config.graphicsQuery) {
+ process.stdout.write('\x1b_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\')
+ const titled = setTimeout(() => process.stdout.write(`\x1b]0;✳ ${config.graphicsQuery.title}\x07`), config.graphicsQuery.titleAfterMs)
+ titled.unref?.()
+ }
let transcript = engine === 'claude'
? join(projectsDir, cwd.replace(/[^a-zA-Z0-9]/g, '-'), `${sessionId}.jsonl`)
: resumed && !fork && config.rolloutFor?.[resumed]
diff --git a/cli/e2e/paneTitles.e2e.ts b/cli/e2e/paneTitles.e2e.ts
new file mode 100644
index 000000000..f6251dde5
--- /dev/null
+++ b/cli/e2e/paneTitles.e2e.ts
@@ -0,0 +1,43 @@
+/**
+ * A harness named by its terminal's title, on the real daemon: the title its engine sets (OSC 0) renames it, and a
+ * kitty graphics query, which tmux also takes as the pane's title, never does. A guest's Claude Code on a shared Mac
+ * was named "Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA" (2026-10-22): its helper starts the engine with `env -i`, so it has no
+ * TMUX and asks the terminal for graphics.
+ */
+import { mkdirSync } from 'node:fs'
+import { join } from 'node:path'
+import { afterEach, describe, expect, it, onTestFailed } from 'vitest'
+import { LocalClient } from './harness/client.js'
+import { IsolatedDaemon, until } from './harness/daemon.js'
+
+const QUERY = 'Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA'
+
+describe('a harness named by its terminal title', () => {
+ let daemon: IsolatedDaemon | undefined
+ afterEach(async () => { await daemon?.close(); daemon = undefined })
+
+ it('keeps its name through a kitty graphics query, and takes the title its engine sets', async () => {
+ const d = await IsolatedDaemon.create({ graphicsQuery: { title: 'Fix the login test', titleAfterMs: 25_000 } })
+ daemon = d
+ onTestFailed(() => { console.log(`---- daemon log\n${d.log().split('\n').slice(-120).join('\n')}`) })
+ await d.start()
+ const client = await LocalClient.connect(d)
+ const cwd = join(d.projectsDir, 'titles')
+ mkdirSync(cwd, { recursive: true })
+ const created = await client.request('agent_create', { engine: 'claude', cwd, bypassPermission: true }, 90_000)
+ expect(created.error, JSON.stringify(created)).toBeUndefined()
+ const id: string = created.agent.id
+ const row = async () => ((await client.request<{ agents: Array<Record<string, any>> }>('agents_list', { includeStopped: true }, 30_000))
+ .agents).find((agent) => agent.id === id)
+ // The query reached tmux as the pane's title, as on the shared Mac.
+ await until('the graphics query as the pane title', async () =>
+ (await d.tmux.run('list-panes', '-a', '-F', '#{pane_title}')).split('\n').includes(QUERY) || null, 20_000, 250)
+ // Two title syncs (every 5 s) while it is the title: it never names the harness.
+ await new Promise((resolve) => setTimeout(resolve, 11_000))
+ expect((await d.tmux.run('list-panes', '-a', '-F', '#{pane_title}')).split('\n')).toContain(QUERY)
+ expect((await row())?.name).not.toBe(QUERY)
+ // The title its engine sets still names it: the sync ran all along, and reads titles.
+ await until('the engine\'s title as the name', async () => (await row())?.name === 'Fix the login test' || null, 45_000, 500)
+ client.close()
+ }, 150_000)
+})
diff --git a/cli/src/lib/registry.spec.ts b/cli/src/lib/registry.spec.ts
index a2c5dab2e..62948bc8f 100644
--- a/cli/src/lib/registry.spec.ts
+++ b/cli/src/lib/registry.spec.ts
@@ -78,6 +78,33 @@ describe('registry remote display names', () => {
delete process.env.CURSOR_HOME
})
+ // tmux takes an APC string as a pane's title, and Claude Code's kitty graphics query named a guest's harness
+ // "Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA" (2026-10-22). tmux.ts no longer reads one as a title; one a registry already
+ // stored is not a name either.
+ it('never names a harness with a kitty graphics query, one stored before included', async () => {
+ const query = 'Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA'
+ const transcriptPath = join(dataDir, 'session-1.jsonl')
+ writeFileSync(transcriptPath, '{}\n')
+ let { registry, projectDisplayName, titleDisplayName } = await loadRegistryModule()
+ expect(titleDisplayName(query)).toBeNull()
+ expect(titleDisplayName('✳ Fix the login test')).toBe('Fix the login test')
+ registry.load()
+ const registered = registerProcess(registry, { launcherId: 'h1', sessionId: 'session-1', transcriptPath, tmuxPane: '%1', cwd: '/tmp/demo' })
+ const named = projectDisplayName(registered!.entry)
+ registry.updateTitle('session-1', query)
+ expect(projectDisplayName(registry.bySession('session-1')!)).toBe(named)
+ // Written by a daemon before the fix.
+ const file = join(dataDir, 'registry.json')
+ const rows = JSON.parse(readFileSync(file, 'utf-8')) as Array<Record<string, unknown>>
+ rows[0].title = query
+ writeFileSync(file, JSON.stringify(rows))
+ ;({ registry, projectDisplayName } = await loadRegistryModule())
+ registry.load()
+ expect(projectDisplayName(registry.bySession('session-1')!)).toBe(named)
+ registry.updateTitle('session-1', '✳ Fix the login test')
+ expect(projectDisplayName(registry.bySession('session-1')!)).toBe('Fix the login test')
+ })
+
it('persists renamed display names independently from session removal', async () => {
const transcriptPath = join(dataDir, 'session-1.jsonl')
writeFileSync(transcriptPath, '{}\n')
diff --git a/cli/src/lib/registry.ts b/cli/src/lib/registry.ts
index 767ee77dc..b05877f08 100644
--- a/cli/src/lib/registry.ts
+++ b/cli/src/lib/registry.ts
@@ -59,6 +59,7 @@ import { mergeTerminalRuntimes, primaryRuntime, processIdentityKey, sameProcessI
import type { HookTerminalHint, ProcessIdentity, TerminalRuntimeRef } from './terminalTypes.js'
import { externalReservations, externalResumePending, externalResumeIds, parseExternalResume, type ExternalResumeIntent } from './externalResume.js'
import type { StartedBy } from './agentAttribution.js'
+import { isKittyGraphicsCommand } from './terminalTitle.js'
export type { ProcessIdentity } from './terminalTypes.js'
@@ -2989,6 +2990,8 @@ function defaultProjectDisplayName(s: RegisteredSession): string {
* its network, and a pane keeps the name it was made under.
*/
export function titleDisplayName(title: string | null | undefined): string | null {
+ // (A graphics query tmux took as a pane title, one a registry stored before tmux.ts stopped reading it included.)
+ if (title && isKittyGraphicsCommand(title)) return null
const cleaned = title
?.trim()
.replace(/^[\s\p{Mark}\p{Punctuation}\p{Symbol}]+/u, '')
diff --git a/cli/src/lib/terminalTitle.ts b/cli/src/lib/terminalTitle.ts
new file mode 100644
index 000000000..9d29e46ef
--- /dev/null
+++ b/cli/src/lib/terminalTitle.ts
@@ -0,0 +1,12 @@
+/**
+ * A kitty graphics command: `G`, then comma-separated one-letter keys with values, then `;` and its payload. tmux
+ * takes any APC string (ESC _ … ESC \) as the pane's title, and Claude Code sends this query when it thinks it is not
+ * inside tmux, as a guest's harness does: the guest helper starts the engine with `env -i`, so it has no TMUX. That
+ * harness was named "Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA" (seen on a shared Mac, tmux 3.7c, 2026-10-22). It is never a
+ * title: tmux.ts does not read one, and registry.ts does not name a harness with one it stored before.
+ */
+const KITTY_GRAPHICS = /^G[a-zA-Z]=[^,;\s]*(?:,[a-zA-Z]=[^,;\s]*)*(?:;[A-Za-z0-9+/=]*)?$/
+
+export function isKittyGraphicsCommand(text: string): boolean {
+ return KITTY_GRAPHICS.test(text.trim())
+}
diff --git a/cli/src/lib/tmux.spec.ts b/cli/src/lib/tmux.spec.ts
index 4b071a946..63399f380 100644
--- a/cli/src/lib/tmux.spec.ts
+++ b/cli/src/lib/tmux.spec.ts
@@ -5,6 +5,7 @@ import { describe, expect, it, vi } from 'vitest'
import { PROCESS_ENGINES } from '../engines/types.js'
import type { AgentCommandOwnershipSnapshot } from './engineBin.js'
import {
+ cleanPaneTitle,
isNoTmuxServerError,
LOAD_BUFFER_TIMEOUT_MS,
pasteRawIntoTmux,
@@ -815,3 +816,29 @@ if [ "$1" = "load-buffer" ]; then exec sleep 30; fi
}
}, 20_000)
})
+
+describe('cleanPaneTitle', () => {
+ // tmux sets a pane's title from any APC string (ESC _ … ESC \), and a graphics query is one: Claude Code asks the
+ // terminal for kitty graphics when it thinks it is outside tmux, as a guest's harness does (its helper starts the
+ // engine with `env -i`, so no TMUX). The query became that harness's name (measured on tmux 3.7c, 2026-10-22).
+ it('drops a kitty graphics command, which is never a title', () => {
+ expect(cleanPaneTitle('Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA')).toBeNull()
+ expect(cleanPaneTitle('Ga=d')).toBeNull()
+ expect(cleanPaneTitle('Gi=1,a=T,f=100;iVBORw0KGgo=')).toBeNull()
+ // A transfer's later chunks, an empty payload, and the query as tmux keeps it with spaces around it.
+ expect(cleanPaneTitle('Gm=1;AAAA')).toBeNull()
+ expect(cleanPaneTitle('Gq=2,a=q;')).toBeNull()
+ expect(cleanPaneTitle(' Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA ')).toBeNull()
+ })
+ it('keeps the titles engines set, those beginning with G too', () => {
+ expect(cleanPaneTitle('✳ Fix the login test')).toBe('Fix the login test')
+ expect(cleanPaneTitle('Gemini: review the PR')).toBe('Gemini: review the PR')
+ expect(cleanPaneTitle('Go build')).toBe('Go build')
+ expect(cleanPaneTitle('G=1 is the answer')).toBe('G=1 is the answer')
+ expect(cleanPaneTitle('Ga=1 wins')).toBe('Ga=1 wins')
+ expect(cleanPaneTitle('Gx=1; then build')).toBe('Gx=1; then build')
+ // Nothing else changes: an empty title is still none, and a long one is still cut at 80.
+ expect(cleanPaneTitle(' ')).toBeNull()
+ expect(cleanPaneTitle('x'.repeat(100))).toBe('x'.repeat(80))
+ })
+})
diff --git a/cli/src/lib/tmux.ts b/cli/src/lib/tmux.ts
index 68d913607..336e8433c 100644
--- a/cli/src/lib/tmux.ts
+++ b/cli/src/lib/tmux.ts
@@ -14,13 +14,16 @@ import { tmuxFeatures, type TmuxFeatures } from './tmuxVersion.js'
import { processIdentityOf } from './terminalRuntime.js'
import type { TerminalPaneInfo, TerminalPaneRead, TerminalPaneState } from './terminalTypes.js'
import { processRows, type ProcessRow } from './processTable.js'
+import { isKittyGraphicsCommand } from './terminalTitle.js'
export { captureTmuxPane, tmuxCaptureArgs } from './tmuxCapture.js'
// Every tmux and `ps` call here: a held event loop must not turn a timeout into an empty answer
// (patientExec.ts).
const run = patientExec(execFile)
-function cleanPaneTitle(title: string): string | null {
+/** A pane's title as a harness name, or none: a kitty graphics query tmux took as a title is none (terminalTitle.ts). */
+export function cleanPaneTitle(title: string): string | null {
+ if (isKittyGraphicsCommand(title)) return null
const cleaned = title
.trim()
.replace(/^[\s"'`*✳✱✲✴✶✷✸✹✺✻✼✽✾✿❃❉❋•·.-]+/, '')