[BUG] Syntax highlighting loses multi-line string state — docstring continuation lines render as code
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code
What's Wrong?
When Claude Code renders a code diff (Edit/Write preview) or code block in the CLI containing a multi-line triple-quoted Python string (e.g. a docstring), only the first line is colored as a string. Every subsequent line of the same string is highlighted as if it were code — words like and/in/for/not/is, numbers, and punctuation inside the prose all pick up keyword/identifier/operator colors.
The highlighter appears to be stateless across line boundaries: it re-tokenizes each line independently and doesn't remember that a previous line opened a """ string that is still unterminated, so the "inside a string" state is lost after the first newline.
What Should Happen?
All lines of a multi-line string literal — from the opening """ through the closing """ — should be colored uniformly as a string, matching how the first line renders (and how editors / bat / pygments render it).
Steps to Reproduce
- Have Claude display or diff a Python file with a function that has a multi-line docstring, e.g.:
def average(values):
"""Return the mean of a sequence of numbers.
The values are summed and then divided by the count. If the
sequence is empty this returns None rather than raising, so
callers can treat 0 items and 1 item the same way.
"""
return sum(values) / len(values) if values else None
- Observe the rendered output in the terminal.
- The opening line (
"""Return the mean of a sequence of numbers.) is correctly string-colored; docstring lines 2–4 are colored as code — words likeand,If,is,None, and the numbers0/1take on keyword/number colors instead of string color.
Expected vs Actual
- Expected: the whole docstring block is one uniform string color.
- Actual: only the opening line is string-colored; continuation lines fall back to code highlighting.
Environment
- Claude Code CLI (latest)
- OS: Linux 6.17
- Not terminal-specific — reproduces in both:
- GNOME Terminal 3.52.0 (VTE 0.76.0),
VTE_VERSION=7600 - PyCharm Community 2026.1 integrated terminal (JediTerm), build
PY-261.24374.152 TERM=xterm-256color,COLORTERMunset
Additional Notes
Because it reproduces in both a native VTE terminal and JetBrains' JediTerm, this is Claude Code's highlighter losing lexer state across newlines, not an emulator quirk. Likely affects any language whose literals span lines: Python """/''', JS/TS template literals, C/CSS block comments /* … */, HTML comments. A fix would need the tokenizer to thread lexer state from one line into the next rather than highlighting each line in isolation.
Claude Model
Opus
Is this a regression?
I don't know