on-stop.sh: byte-level truncation splits multibyte UTF-8, Stop hook fails Claude Code JSON validation
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
Línea de trabajo
Empieza en scripts/on-stop.sh, en la truncación de QUERY y RESPONSE, y luego comprueba legacy/on-stop.sh para ver si usa el mismo patrón. Ejecuta la reproducción proporcionada de la división en los límites y el hook completo con los locales C y UTF-8. La tarea está terminada cuando el texto multibyte sigue siendo UTF-8 válido y Claude Code acepta el JSON emitido.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
scripts/on-stop.sh (plugin v2.1.0) truncates the extracted query/response with bash substring expansion:
QUERY="${QUERY:0:197}..."
RESPONSE="${RESPONSE:0:197}..."
Bash slices by byte, not codepoint, when the hook runs without a UTF-8 locale (Claude Code hook subprocesses commonly inherit C/POSIX). When position 197 lands inside a multibyte character - em-dashes, arrows, box-drawing characters like ⎿ that Claude Code transcripts are full of - the truncated string ends with an invalid UTF-8 fragment. That fragment goes through jq --arg into the notification payload, and Claude Code rejects the hook's stdout:
Ran 6 stop hooks
⎿ Stop hook error: JSON validation failed
It is intermittent by nature: it only fires when byte 197 happens to split a character, so it looks flaky and is painful to attribute (Claude Code does not say which hook failed - see anthropics/claude-code#21992 for that class).
Reproduce
# 1. Craft a transcript whose last user message has a 3-byte char straddling byte 197
python3 - <<'EOF'
import json
q = 'a'*195 + '⎿ tail of the question' # U+23BF = 3 bytes; bytes 196-198
lines = [
{'type':'user','message':{'content': q}},
{'type':'assistant','message':{'content':[{'type':'text','text': 'b'*195 + '— long response text'}]}},
]
open('/tmp/repro-transcript.jsonl','w').write('\n'.join(json.dumps(l) for l in lines))
EOF
# 2. Demonstrate the corruption the hook's truncation produces under a C locale
Q=$(jq -rs '[.[] | select(.type=="user")] | last | .message.content' /tmp/repro-transcript.jsonl)
LC_ALL=C bash -c 'Q="'"$Q"'"; printf "%s" "${Q:0:197}"' | python3 -c '
import sys
sys.stdin.buffer.read().decode("utf-8")' # -> UnicodeDecodeError: invalid continuation byte
Running the full on-stop.sh against such a transcript with LC_ALL=C (and TERM_PROGRAM=WarpTerminal + a structured-notifications-capable Warp env) emits a payload containing the broken fragment, which fails Claude Code's stop-hook stdout schema validation.
Fix
Truncate codepoint-safely. jq is already a hard dependency of the script, so the smallest change is:
# Truncate for notification display (codepoint-safe; bash ${VAR:0:N} slices
# by byte under non-UTF-8 locales and can split a multibyte character).
if [ -n "$QUERY" ] && [ ${#QUERY} -gt 200 ]; then
QUERY="$(printf '%s' "$QUERY" | jq -Rrs '.[0:197] + "..."')"
fi
if [ -n "$RESPONSE" ] && [ ${#RESPONSE} -gt 200 ]; then
RESPONSE="$(printf '%s' "$RESPONSE" | jq -Rrs '.[0:197] + "..."')"
fi
Verified locally (patched plugin cache): valid JSON output across repeated runs under both UTF-8 and C locales, including the crafted boundary-splitting transcript above; the per-turn "JSON validation failed" error disappeared.
An equivalent guard likely belongs in legacy/on-stop.sh too if it shares the truncation idiom.
Environment
- claude-code-warp plugin 2.1.0 (marketplace install)
- Claude Code 2.1.197, macOS (darwin 25.5.0), bash 3.2 shebang path
- Related-but-distinct: #63 (CRLF), #67 (notification spam) - same script, different bugs
- Lenguaje dominante
- Shell
- Estrellas
- 234
- Forks
- 60
- Merge medio
- 2 d 8 h
- PR fusionados (30 d)
- 2
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de warpdotdev/claude-code-warp
-
on-stop.sh slurps the entire transcript with jq -s every turn — ~1 GB RSS on long sessions, triggered a host OOMPosiblemente ocupada @GeiserX la tomó hace 15 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
warpdotdev/claude-code-warp#63 · 2 comentarios ·
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
warpdotdev/claude-code-warp#61 · 6 comentarios · 5 reacciones ·
Todos los issues de warpdotdev/claude-code-warp
Issues similares
-
Screensaver picked up transparency setting from GhosttyPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Link Checker ReportAbiertoautomated issue report
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
a2aproject/A2A#2387 ·
Los mantenedores suelen responder en 4 días
-
Request: add Vibe TyperAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
curriculum documentation quality
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
githubnext/gh-aw-workshop#4965 ·
Los mantenedores suelen responder en 1 día
-
[feat] help flags for zi and zAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
ajeetdsouza/zoxide#1350 ·
Los mantenedores suelen responder en 2 días