Skip to content

Commit 0040875

Browse files
Glucksbergclaude
andcommitted
fix(codex): de-duplicate session-start context and surface one-line summary
Codex's TUI flattens newlines when it surfaces SessionStart hook output and already echoes additionalContext back as its own "hook context" block. Emitting the full timeline again through systemMessage (shown as a "warning:" block) duplicated the wall of text into an unreadable single line. For the Codex platform, replace the full-timeline systemMessage with a compact one-line summary (obs/work/savings + live URL) that stays legible after Codex flattens it. The model still receives the full, properly formatted additionalContext, and the claude-code/gemini colored multi-line paths are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 00867a8 commit 0040875

1 file changed

Lines changed: 30 additions & 12 deletions

File tree

src/cli/handlers/context.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,40 @@ export const contextHandler: EventHandler = {
6060
: hint;
6161
}
6262

63-
let coloredTimeline = '';
63+
const platform = input.platform;
64+
const isCodex = platform === 'codex';
65+
66+
let systemMessage: string | undefined;
6467
if (showTerminalOutput) {
65-
const colorResult = await executeWithWorkerFallback<string>(colorApiPath, 'GET');
66-
if (!isWorkerFallback(colorResult) && typeof colorResult === 'string') {
67-
coloredTimeline = colorResult.trim();
68+
if (isCodex) {
69+
// Codex's TUI flattens newlines when it surfaces hook output AND already
70+
// echoes additionalContext back as its own "hook context" block. Re-sending
71+
// the full timeline through systemMessage just duplicates that wall of text
72+
// (shown as a "warning:" block) into an unreadable single line. Surface a
73+
// compact one-line summary that stays legible even after Codex flattens it;
74+
// the model still receives the full, properly formatted additionalContext.
75+
if (additionalContext) {
76+
const statsLine = additionalContext.match(/^Stats:\s*(.+)$/m)?.[1]?.trim();
77+
const summary = statsLine
78+
? `📋 claude-mem: ${statsLine}`
79+
: '📋 claude-mem: recent context loaded';
80+
systemMessage = `${summary} · http://localhost:${port}`;
81+
}
82+
} else {
83+
const colorResult = await executeWithWorkerFallback<string>(colorApiPath, 'GET');
84+
const coloredTimeline =
85+
!isWorkerFallback(colorResult) && typeof colorResult === 'string'
86+
? colorResult.trim()
87+
: '';
88+
const displayContent =
89+
coloredTimeline ||
90+
(platform === 'gemini-cli' || platform === 'gemini' ? additionalContext : '');
91+
systemMessage = displayContent
92+
? `${displayContent}\n\nView Observations Live @ http://localhost:${port}`
93+
: undefined;
6894
}
6995
}
7096

71-
const platform = input.platform;
72-
73-
const displayContent = coloredTimeline || (platform === 'gemini-cli' || platform === 'gemini' ? additionalContext : '');
74-
75-
const systemMessage = showTerminalOutput && displayContent
76-
? `${displayContent}\n\nView Observations Live @ http://localhost:${port}`
77-
: undefined;
78-
7997
return {
8098
hookSpecificOutput: {
8199
hookEventName: 'SessionStart',

0 commit comments

Comments
 (0)