[TUI] Add bounded intraline highlighting to changed diff spans
I have traced this feature to codex-rs/tui/src/diff_render.rs and would be very happy to implement the feature using the approach described below. If this proposal aligns with the intended TUI design, would a maintainer be willing to invite a pull request in accordance with the repository's contribution policy?
What feature would you like to see?
Codex CLI's TUI currently distinguishes added and removed lines, but
it does not emphasize the specific words or expressions that changed
within a replaced line. Highlighting those intraline changes would
make small edits within long lines substantially easier to review.
The desired presentation is that of GitHub's diff viewer or tools
such as delta: retain the
existing background for the complete added or removed line, then use
a stronger background—or another emphasis style on terminals with
limited color support—only for the changed portions.
For example, in:
- The system achieved a score of 0.80 in the final test.
+ The system achieved a score of 0.85 in the final test.
The removed 0.80 and inserted 0.85 would receive stronger
emphasis, while the rest of each line would retain its normal
deletion or insertion styling.
This is the style of intraline highlighting shown in the delta
example originally referenced in #21540:
!Example of intraline diff highlighting
This would be particularly helpful for:
- Function calls where one argument changed or was added.
- Long configuration or source-code lines.
- Markdown, LaTeX, and prose-oriented files.
- Changes to numbers, identifiers, strings, and command arguments.
- Reviewing agent edits directly in the TUI without switching to
another diff viewer.
The feature should preserve Codex's existing syntax highlighting,
line numbers, wrapping behavior, and full-line addition/deletion
styling. It should also degrade gracefully on ANSI-16 terminals,
where bold or underline could provide intraline emphasis without
introducing overpowering background colors.
This proposal follows the same general request as #21540 and #3090.
Both were closed because they did not receive enough upvotes, rather
than because the behavior or implementation was determined to be
undesirable. This issue provides an updated and more narrowly scoped
proposal, together with an offer to implement it if invited.
Proposed scope
For an initial implementation:
- Apply intraline highlighting automatically to replacement blocks
in unified diffs.
- Keep deleted and inserted versions on separate lines, as they are
today.
- Support word- or token-level matching, including Unicode text.
- Handle replacement blocks containing unequal numbers of deleted
and inserted lines.
- Avoid emphasizing an entire unrelated line as an intraline change;
the existing full-line styling is sufficient in that case.
- Preserve syntax foreground colors when applying stronger
intraline backgrounds.
- Preserve intraline styles when long lines wrap.
- Use bounded input sizes and a short computation deadline to prevent
large or pathological diffs from slowing TUI rendering.
- Avoid adding a configuration option or keyboard toggle in the
initial version.
Proposed implementation
The implementation could add a small private module undercodex-rs/tui/src/diff_render/ that scans each hunk for contiguous
deletion/insertion blocks and computes emphasized byte ranges for
those lines. The workspace already pins the Rustsimilar crate, whose
optional inline and Unicode functionality can refine adjacent line
replacements into intraline changes and supports a computation
deadline. The module would return ranges aligned with the original
hunk lines, keeping the diff algorithm separate from terminal styling
and avoiding a runtime dependency on the delta executable.
The existing renderer would merge those ranges with its
syntax-highlighted spans before passing them through the current
wrapping logic. Rich-color terminals could use a stronger theme-aware
insertion or deletion background for emphasized ranges, while ANSI-16
terminals could use bold or underline. Tests would cover simple
substitutions, inserted arguments, unequal line counts, unrelated
lines, Unicode boundaries, syntax-style composition, wrapped lines,
terminal color levels, and the size/deadline fallback.
2 Comments
I’ve been using Codex CLI since April 2026, and I believe this would be an excellent quality-of-life improvement.
Claude Code has supported intraline diff highlighting for quite some time, and it provides a very good experience by making small changes immediately visible. I’ve been hoping to see similar functionality in Codex CLI for about four months.
I’m very much looking forward to this feature and would be delighted to see it implemented. Thank you for revisiting this proposal!
Thank you @Augtons!
I will repeat, btw, that if invited by a maintainer, I will happily make a pull request implementing this feature, it's not that hard.