loopx icon indicating copy to clipboard operation
loopx copied to clipboard

[Bug]: Claude Code adapter entry points crash or lose their status text on a non-UTF-8 host

Open JasonBuildAI opened this issue 1 month ago • 1 comments

Preflight

  • [x] I searched existing issues and discussions for this behavior.
  • [x] This report is not an unpatched security vulnerability.
  • [x] The report and attachments contain no credentials or private/internal material.

Issue origin

Observed or reproduced in a real environment

LoopX version or commit

5c62c5c03 (loopx 1.3.1)

Host or runtime surface

Claude Code

LoopX area

Host or runtime integration

Problem

The shipped Claude Code adapter's own entry points never pin their stdio to UTF-8, so on a host whose locale codec is not UTF-8 (cp936/GBK on zh-CN Windows) they fail to render their own status text. Both render characters the cp936 codec cannot encode: ▸ ▶ ⏸ ⚠ ✓.

The two shipped surfaces:

  • loopx/claude_goal_mode/statusline/goal_status.py - the optional --harden statusline, wired by loopx/claude_goal_mode/scripts/install.py as python3 ".../statusline/goal_status.py".
  • loopx/claude_goal_mode/scripts/goalmode_cmd.py - the /loopx slash command; loopx/claude_goal_mode/commands/loopx.md runs python3 ".../scripts/goalmode_cmd.py" $ARGUMENTS.

Neither goes through loopx.entrypoint.main, the only place that pins the process's own stdio to UTF-8 (added by #6119), so both keep the host locale codec.

Effect for a zh-CN Windows user with the adapter installed:

  • /loopx status aborts with UnicodeEncodeError after printing only its first ASCII lines, so the user gets a traceback instead of the goal state.
  • the optional statusline loses its state/next/progress segment and collapses to the bare [loopx <goal_id>] fallback, because its broad except swallows the encode failure.

Same defect class as #6116 / #6119 (shipped CLI stdio, merged), #4941 (file text I/O) and #4155 (subprocess decode). #6119 scoped itself to loopx.entrypoint and left child entry points out.

Minimal reproduction

On a host whose locale codec is not UTF-8 (Windows zh-CN cp936, or any host with PYTHONIOENCODING=gbk PYTHONUTF8=0):

  1. Create a goal-mode-armed project: a .loopx/registry.json with one goal, plus a .claude/loop.md whose first line is <!-- loopx:armed {"goal_id": "g-demo", "agent_id": "cc"} -->.
  2. From that project directory, run python3 <repo>/loopx/claude_goal_mode/scripts/goalmode_cmd.py status.
  3. Also run echo '{"cwd": "<project>"}' | python3 <repo>/loopx/claude_goal_mode/statusline/goal_status.py.

Expected behavior

Both print their status text, including the goal-state glyphs, and exit 0, regardless of the host locale codec.

Actual behavior

/loopx status exits 1 after printing only the goal/agent/objective lines:

  File ".../loopx/claude_goal_mode/scripts/goalmode_cmd.py", line 173, in print_status
    print(f"state     : {state}")
UnicodeEncodeError: 'gbk' codec can't encode character '\u25b6' in position 12: illegal multibyte sequence

The statusline prints [loopx g-demo] instead of [loopx g-demo · ▶ 1✓/2▸ · next: …].

Sanitized diagnostics

python -c "import sys; print(sys.stdout.encoding, sys.flags.utf8_mode)"
gbk 0
# PYTHONIOENCODING / PYTHONUTF8 unset

Setting PYTHONIOENCODING=utf-8 makes both work, which confirms the entry points' own stdio codec is the cause.

Additional context

Same defect class as #4941, #4155, #6116 / #6119. A fix that pins these two adapter entry points' stdio through the same owner as #6119 will follow as a pull request.

JasonBuildAI avatar Oct 10 '26 19:10 JasonBuildAI

This defect is already covered by the open PR #6166, which pins the same Claude Code entry points (scripts/goalmode_cmd.py, statusline/goal_status.py) and additionally the PreToolUse gate's stdin. I am not proposing a second implementation; keeping this report open as the public problem record, since #6166 does not link an issue. Close this when #6166 merges.

JasonBuildAI avatar Oct 10 '26 19:10 JasonBuildAI