Claude Code for Bat (Cat Alternative) — Guide
The Setup
You are using bat as a replacement for cat, a Rust-based command-line tool that provides syntax highlighting, Git integration, line numbers, and paging for file output. bat auto-detects file types and applies appropriate syntax highlighting, making code review and file inspection faster. Claude Code can display file contents, but it uses plain cat without highlighting or context.
What Claude Code Gets Wrong By Default
-
Uses
catfor file display. Claude runscat file.tsfor plain text output. bat provides syntax highlighting, line numbers, and Git change markers —bat file.tsgives much more readable output. -
Pipes through separate tools for highlighting. Claude chains
cat file.ts | pygmentizeor uses other colorizers. bat handles syntax highlighting natively for 100+ languages — no additional tools or pipes needed. -
Adds
--numberflag for line numbers. Claude runscat -n file.tsfor numbered lines. bat shows line numbers by default with--style=numbersand includes Git change indicators alongside. -
Ignores bat’s integration capabilities. Claude uses bat as a standalone viewer only. bat can be used as
MANPAGER,GIT_PAGER, and integrated with fzf, ripgrep, and other tools for enhanced output.
The CLAUDE.md Configuration
# Bat File Viewer
## Tools
- Viewer: bat (cat alternative with syntax highlighting)
- Features: syntax highlighting, line numbers, Git integration
- Paging: built-in paging with less
- Themes: customizable color themes
## Bat Rules
- View: bat file.ts (with syntax highlighting)
- Plain: bat --plain file.ts (no decorations)
- Language: bat -l json file (force language)
- Line range: bat --line-range 10:20 file.ts
- Diff: bat --diff file1.ts file2.ts
- Pager: bat --paging=never for piping
- Theme: bat --theme="Catppuccin Mocha"
## Conventions
- Use bat for all file viewing commands
- bat --plain for piping to other commands
- Set BAT_THEME in shell config for consistent theme
- Use bat as MANPAGER: export MANPAGER="bat -l man -p"
- Integration: rg --json | bat for highlighted ripgrep output
- Use bat --line-range for viewing specific sections
- bat --show-all for whitespace characters
Workflow Example
You want to set up bat as the default file viewer with project-specific configuration. Prompt Claude Code:
“Configure bat as the default pager for Git and man pages. Set the Catppuccin Mocha theme, enable Git integration, and create shell aliases for common bat operations. Also show how to use bat with ripgrep for highlighted search results.”
Claude Code should add export BAT_THEME="Catppuccin Mocha" to shell config, set export MANPAGER="sh -c 'col -bx | bat -l man -p'" and git config --global core.pager 'bat --paging=always', create aliases like alias preview='bat --line-range :50', and show the rg pattern --json | bat integration.
Common Pitfalls
-
Paging interfering with piping. Claude pipes bat output to other commands but the pager intercepts. Use
bat --paging=neverorbat -pwhen piping to other commands — the pager is for interactive viewing, not piping. -
Theme not matching terminal colors. Claude sets a bat theme that clashes with the terminal theme. Use
bat --list-themes | batto preview themes in your terminal and pick one that matches your color scheme. -
Missing language detection for stdin. Claude pipes content to bat without specifying the language:
curl url | bat. Without a file extension, bat cannot detect the language. Usecurl url | bat -l jsonto specify the language explicitly.