Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

on-stop.sh: byte-level truncation splits multibyte UTF-8, Stop hook fails Claude Code JSON validation

Abierto Apto para principiantes
#70 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
bash
Área
cli, devtools

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de warpdotdev/claude-code-warp

Todos los issues de warpdotdev/claude-code-warp

Issues similares

Más issues de Shell/Bash

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.