anthropics / anthropics/claude-code

[BUG] Missing syntax highlighting in /diff on Windows and extensionless files (with fix)

Open
#94,313 0 comments 0 reactions 0 assignees View on GitHub
area:tui bug platform:windows
Dominant language
Python
Stars
145k
Forks
23.1k
PR merge metrics
PR metrics pending

Description

### Preflight Checklist

- [x] I have searched [existing issues](https://github.com/anthropics/claude-code/issues?q=is%3Aissue%20state%3Aopen%20label%3Abug) and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code

### What's Wrong?

In `mods/diff`, the `` component relies solely on the engine inferring the syntax highlighting language from `path` (``). This causes syntax highlighting in diff views to fail or render as plain text in several common scenarios:

1. **Windows Paths**: On Windows, file paths passed with backslashes (`\`) are not parsed correctly by POSIX-based extension extractors in the engine, resulting in missing syntax highlighting for hunks.
2. **Canonical Extensionless Files**: Files such as `Dockerfile`, `Makefile`, `Gemfile`, `Rakefile`, `CMakeLists.txt`, `.bashrc`, `.gitignore` have no file extension, so standard extension lookup yields no language.
3. **Shebang Scripts**: Scripts without extensions containing a Shebang (e.g., `#!/usr/bin/env python3`, `#!/usr/bin/env node`, `#!/bin/bash`) are not inspected for language hints.
4. **Git Rename Notations**: Diffs with rename formats (`old.ts -> new.ts` or diff-stat `{old => new}`) pass raw rename strings as paths, breaking extension inference.

### What Should Happen?

- Paths should be normalized across platforms (`\` converted to `/`, invisible/control characters stripped, and rename targets extracted).
- The mod should resolve canonical language aliases and pass explicit `language={language}` to `` (supported by `CodeProps` in `mods/types/claude-code.d.ts`).

### Ready-made Fix & Unit Tests

I have implemented and verified a clean fix with full unit tests in my fork:
- **Commit:** [fabiooliveir/claude-code@4fb5f0a](https://github.com/fabiooliveir/claude-code/commit/4fb5f0a)
- **Changes include:**
1. `sanitizePath` (`mods/diff/hooks/views/layout/sanitize-path/`): Normalizes Windows backslashes, git renames, and control chars.
2. `languageOf` (`mods/diff/hooks/views/detail/language-of/`): Resolves language aliases for common extensions, compound extensions (`.d.ts`), canonical filenames (`Dockerfile`, `Makefile`, etc.), and shebangs.
3. `` integration in `detail-view.tsx` and `draw-window.tsx` passing both `path` and `language`.
4. Unit tests in `sanitize-path.test.ts`, `language-of.test.ts`, and updated `detail-view.test.ts`.
5. Typecheck passes cleanly: `tsc -p mods/tsconfig.json --noEmit` (0 errors).

Feel free to cherry-pick this commit or adapt it as needed!

### Claude Code Version

2.1.263

### Platform

Windows (PowerShell / Windows Terminal)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in mods/diff/hooks/views/layout/sanitize-path/ and mods/diff/hooks/views/detail/language-of/, then inspect detail-view.tsx and draw-window.tsx for Code integration. Run sanitize-path.test.ts, language-of.test.ts, the updated detail-view.test.ts, and tsc -p mods/tsconfig.json --noEmit. Done means normalized paths and explicit language detection work for the listed cases with tests and typecheck passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.