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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
A /compact typed into Claude Code opens no turn: the agent reads idle after it, not working until the next message (#858)
Deed40c02aa4bb2
diff --git a/cli/e2e/compaction.e2e.ts b/cli/e2e/compaction.e2e.tsindex 44da445be..17a5b07e4 100644--- a/cli/e2e/compaction.e2e.ts+++ b/cli/e2e/compaction.e2e.ts@@ -74,6 +74,26 @@ describe('compaction', () => {client.close()})+ it('claude: a /compact typed as Claude Code writes it opens no turn, and the agent reads idle after it', async () => {+ const d = await fresh()+ const client = await LocalClient.connect(d)+ const agent = await create(d, client, 'claude', 'compact-command')+ await turn(client, agent.id, 'before')+ const since = client.frames.length+ // Sent from the app, as a person types it. Claude Code 2.1.290 writes the command as a plain user line+ // before the compaction: taken as a prompt it opened a turn that nothing closed, and the agent read+ // working, then unknown, until the next message (found by daemon QA).+ client.send('message', { agentId: agent.id, content: '/compact' })+ await client.next((frame) => frame.type === 'context_compact' && frame.agentId === agent.id, 30_000, 'context_compact')+ await new Promise((resolve) => setTimeout(resolve, 2_000))+ expect(count(client, since, 'turn_started', agent.id)).toBe(0)+ await until('the agent to read idle', async () => (await row(client, agent.id))?.activity?.state === 'idle' || null, 15_000, 250)+ await turn(client, agent.id, 'after')+ expect(count(client, since, 'turn_started', agent.id)).toBe(1)+ expect(await users(client, agent.sessionId)).toEqual(['before', '/compact', 'after'])+ client.close()+ })+it.each(engines)('%s: a compaction in the middle of a turn: the turn ends once, and the next one is fresh', async (engine) => {const d = await fresh()const client = await LocalClient.connect(d)diff --git a/cli/e2e/harness/fakeEngine.mjs b/cli/e2e/harness/fakeEngine.mjsindex 7dee8e4c4..a3b742bb1 100644--- a/cli/e2e/harness/fakeEngine.mjs+++ b/cli/e2e/harness/fakeEngine.mjs@@ -20,7 +20,7 @@// the engine does and runs it only if allowed, `!flood <KiB>` prints that much to the terminal, in// numbered lines, the way a build log or a long diff does, `!clear` starts a new conversation in the// same pane as Claude Code's `/clear` and Codex's `/new` do, `!compact` compacts the conversation as-// `/compact` does (and Claude Code then announces the same session again), `!compactmid` compacts in the+// `/compact` does (a real `/compact` (Claude Code) is written exactly as Claude Code writes it, with no turn) (and Claude Code then announces the same session again), `!compactmid` compacts in the// middle of a turn as an automatic compaction does, `!version` answers with the version this// process is, `!goal` and `!goal done` (Codex) start and achieve a goal the way Codex 0.160 shows one// under its composer, `!browse` (Codex) leaves Codex browsing its transcript in its default fullscreen@@ -1011,6 +1011,19 @@ export async function run(engine, config = {}, { native = false } = {}) {if (engine === 'claude') await runHooks('SessionStart', { source: 'compact' })return}+ if (engine === 'claude' && /^\/compact(\s|$)/.test(prompt)) {+ // Claude Code's own /compact, written as 2.1.290 writes it (recorded by daemon QA): the command as a+ // plain user line, the compaction, a caveat and the command's tags, then its output. There is no+ // answer, no UserPromptSubmit and no turn of its own, and it announces the same session again.+ claude({ type: 'user', message: { role: 'user', content: prompt } })+ compact()+ claude({ type: 'user', isMeta: true, message: { role: 'user', content: '<local-command-caveat>Caveat: The messages below were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to.</local-command-caveat>' } })+ claude({ type: 'user', message: { role: 'user', content: '<command-name>/compact</command-name>\n <command-message>compact</command-message>\n <command-args></command-args>' } })+ claude({ type: 'user', message: { role: 'user', content: '<local-command-stdout>Compacted (ctrl+o to see full summary)</local-command-stdout>' } })+ say('(compacted)\r\n')+ await runHooks('SessionStart', { source: 'compact' })+ return+ }if (prompt === '!clear') {// The old conversation ends (its open turn first), a new id and transcript begin, and the engine// says both through its hooks, as the real CLIs do.diff --git a/cli/src/lib/normalize.test.ts b/cli/src/lib/normalize.test.tsindex c5a1a42fe..23b2a43f6 100644--- a/cli/src/lib/normalize.test.ts+++ b/cli/src/lib/normalize.test.ts@@ -330,3 +330,16 @@ describe('a message typed while Claude Code worked', () => {})})+describe('a built-in command Claude Code runs itself, typed plainly', () => {+ const user = (content: string) => line({ type: 'user', uuid: content, message: { role: 'user', content } })+ it.each(['/compact', '/compact keep the plan', '/model opus', '/Clear'])('%s opens no live turn', (prompt) => {+ const state = newTurnState()+ expect(lineToEvents(user(prompt), state)).toEqual([])+ expect(state.turnOpen).toBe(false)+ })+ it.each(['/goal ship it', '/review', '/compactor', 'run /compact later'])('%s is still a prompt', (prompt) => {+ const state = newTurnState()+ expect(lineToEvents(user(prompt), state)).toEqual([{ type: 'turn_started', payload: { userMessage: prompt } }])+ })+})+diff --git a/cli/src/lib/normalize.ts b/cli/src/lib/normalize.tsindex 44f7dbb3d..28a950d93 100644--- a/cli/src/lib/normalize.ts+++ b/cli/src/lib/normalize.ts@@ -135,6 +135,12 @@ const LOCAL_ONLY_COMMANDS = new Set(['upgrade', 'vim',])+/** A whole prompt that is one of LOCAL_ONLY_COMMANDS, typed plainly: `/compact`, `/model opus`. */+function isLocalOnlyCommandLine(text: string): boolean {+ const name = /^\/([A-Za-z][\w-]*)(?:\s|$)/.exec(text.trim())?.[1]+ return name !== undefined && LOCAL_ONLY_COMMANDS.has(name.toLowerCase())+}+/*** `<command-name>/goal</command-name>…<command-args>x</command-args>` → `/goal x`.*@@ -430,6 +436,11 @@ function isInterruptLine(msg: NormalizedMessage): boolean {function realUserText(msg: NormalizedMessage): string | null {const text = userTextRaw(msg)if (text === null || INTERRUPT_MARKER.test(text)) return null+ // Claude Code 2.1.290 also writes a built-in command it runs itself as a plain user line ("/compact"),+ // ahead of the tagged record `commandPromptText` already keeps out. Taken as a prompt, it opened a turn+ // nothing ever closed: after a /compact the agent read working, then unknown, until the next message+ // (found by daemon QA). The same list decides both forms.+ if (isLocalOnlyCommandLine(text)) return null// A `!command` line is not a prompt — skip it so the turn (and its recap) stays anchored to the last// real ask. Only when nothing but bash blocks remain: a message that also carries prose still counts.if (!stripBashModeBlocks(text)) return null