Skip to content

Line continuations (backslash-newline) leave a stray literal backslash in annotations #14

Description

@aholten

Problem

Backslash-newline line continuations aren't parsed properly. The hook's whitespace collapse (main() in scripts/annotate-pre.sh) replaces the newline with a space but leaves the preceding continuation backslash in place, so the annotation shows a stray \:

command sent:   echo hello \
                world && ls

annotation:     💬 echo hello \ world ✅ && 📋 ls
expected:       💬 echo hello world ✅ && 📋 ls

Repro

printf '{"tool_name":"Bash","tool_input":{"command":"echo hello \\\nworld && ls"}}' \
  | bash scripts/annotate-pre.sh
# systemMessage contains "echo hello \ world" — stray backslash

Cause

main() collapses \n\r\t to spaces after unescaping, turning \ + newline into \ + space. Downstream, _render_segment's walk then treats that \ as a backslash-escape pair, which also swallows the word boundary for chunking purposes.

Suggested fix

Strip continuation sequences before the general whitespace collapse:

command="${command//\$'\n'/ }"   # backslash-newline → single space

plus a segmentation test (parser: section) asserting echo hello \<newline>world renders with no \ in the plain text. The pre-consolidation parser had exactly this behavior ("backslash continuation joins lines" in the old test suite).

Found during review of #13; deferred from that PR.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions