openai / openai/codex-plugin-cc
Review fails with JSONL parse error: bracketed paste mode escape sequence in output ([?2004h)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 33.3k
- Forks
- 2.3k
- PR merge metrics
- No merged PRs in 30d
Description
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:reviewfrom 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 loginsuccessful)
Additional Context
- Other review-related issues (#3 sandbox variant, #14 EISDIR, #18 bwrap) are unrelated — this is a pure output parsing issue.
- The review job log shows
Starting Codex Review.and then immediately fails, suggesting the error occurs during the initial JSONL handshake with the Codex app-server.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in codex-companion.mjs at the JSONL parsing of Codex CLI stdout, and reproduce the failure with node "codex-companion.mjs" review in foreground and background modes. Verify that terminal escape sequences no longer cause parsing errors and that the review reaches its normal output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100