Bug
/codex:review (both foreground and background) fails with a JSONL parse error when the Codex CLI outputs terminal escape sequences (bracketed paste mode) that corrupt the JSON stream.
Error
Failed to parse codex app-server JSONL: Unexpected token '', "[?2004h" is not valid JSON
Reproduction
- Authenticate with
codex login
- Have a working tree with staged/unstaged changes
- Run
/codex:review from Claude Code (either foreground or background mode)
- The companion script (
codex-companion.mjs) attempts to parse the Codex CLI stdout as JSONL
- Terminal escape sequence
[?2004h (bracketed paste mode) is included in the output, breaking JSON parsing
Both foreground and background execution produce the same error:
# Foreground
node "codex-companion.mjs" review
# → Failed to parse codex app-server JSONL: Unexpected token '', "[?2004h" is not valid JSON
# Background (via Claude Code Bash tool with run_in_background: true)
node "codex-companion.mjs" review
# → Same error
Root Cause
[?2004h is the ANSI escape sequence for enabling bracketed paste mode, typically emitted by shells (bash/zsh) during initialization. When the Codex CLI spawns a subprocess or the shell environment leaks these escape codes into stdout, the JSONL parser in the companion script receives non-JSON data and fails.
This likely happens because:
- The user's shell profile (
.zshrc / .bashrc) emits escape sequences on startup
- The Codex CLI subprocess inherits the terminal settings and outputs control sequences
- The companion script does not strip ANSI escape sequences before parsing JSONL lines
Suggested Fix
Strip ANSI escape sequences from the Codex CLI output before attempting JSONL parsing. For example:
// Before parsing each line as JSON
const ansiRegex = /\x1b\[[0-9;]*[a-zA-Z]|\x1b\][^\x07]*\x07/g;
const cleanLine = rawLine.replace(ansiRegex, '').trim();
if (!cleanLine) continue; // skip empty lines after stripping
const parsed = JSON.parse(cleanLine);
Environment
- macOS 15.5 (Darwin 24.6.0)
- Claude Code (CLI)
- Node.js (via Claude Code Bash tool)
- Shell: zsh
- codex-plugin-cc: latest
- Codex CLI: authenticated and working (
codex login successful)
Additional Context
Bug
/codex:review(both foreground and background) fails with a JSONL parse error when the Codex CLI outputs terminal escape sequences (bracketed paste mode) that corrupt the JSON stream.Error
Reproduction
codex login/codex:reviewfrom Claude Code (either foreground or background mode)codex-companion.mjs) attempts to parse the Codex CLI stdout as JSONL[?2004h(bracketed paste mode) is included in the output, breaking JSON parsingBoth foreground and background execution produce the same error:
Root Cause
[?2004his the ANSI escape sequence for enabling bracketed paste mode, typically emitted by shells (bash/zsh) during initialization. When the Codex CLI spawns a subprocess or the shell environment leaks these escape codes into stdout, the JSONL parser in the companion script receives non-JSON data and fails.This likely happens because:
.zshrc/.bashrc) emits escape sequences on startupSuggested Fix
Strip ANSI escape sequences from the Codex CLI output before attempting JSONL parsing. For example:
Environment
codex loginsuccessful)Additional Context
Starting Codex Review.and then immediately fails, suggesting the error occurs during the initial JSONL handshake with the Codex app-server.