Convert American spellings to British English. Originally created to fix the US spelling output from LLMs, but useful for anyone who needs British spellings in their documents and code.
- Multiple File Types: Text, markdown, LaTeX, HTML, JSON, and code files
- Smart Code Handling: Only converts comments and docstrings in code files, never string literals or identifiers
- Context-Aware: Preserves quoted text like
'colorScheme'in comments (API references) - Interactive Mode: Review and approve changes one by one
- Hook Integration: Automatically fix spellings when writing files
Requires uv and optionally just.
# Install dependencies
just sync
# or: uv sync
# Build standalone binary and install to ~/.local/bin
just build && just install# Process files
britfix --input file.txt
britfix --input "*.md" --recursive
# Process from stdin
echo "The color was analyzed" | britfix --quiet
# Output: The colour was analysed
# Interactive mode
britfix --input document.md --interactive
# Dry run
britfix --input "src/*.py" --dry-run--input: Input file(s) or pattern(s). If omitted, reads from stdin--interactive,-i: Interactive approval mode (strategy-aware — only suggests changes in regions the strategy considers safe, e.g. comments in code files, prose in markdown). JSON files fall back to non-interactive processing--dry-run: Preview changes without modifying files--no-backup: Skip backup creation--recursive: Process files recursively--quiet: Only output corrected text (for pipelines)
Different file types are handled by different strategies, configured in config.json:
| Strategy | Extensions | Behaviour |
|---|---|---|
| text | .txt |
Convert everything |
| markdown | .md, .markdown, .mdown, .mkd, .mdx |
Preserve code spans and code blocks |
| latex | .tex |
Skip LaTeX commands and math |
| html | .html, .htm, .xml |
Skip HTML tags and <style>/<script> content |
| css | .css, .scss, .sass, .less |
Only convert comments |
| json | .json |
Only convert string values |
| code | .py, .js, .ts, etc. |
Only convert comments and docstrings |
For code files, the tool intelligently handles context:
Converted (prose in comments/docstrings):
# The behavior is favorable -> # The behaviour is favourable
"""This optimizes the color.""" -> """This optimises the colour."""NOT converted (code and API references):
config.get('organization') # String literal - unchanged
payload = {'colorScheme': x} # Dict key - unchanged
# Use 'colorField' for the API # Quoted in comment - unchangedCreate a .britfixignore file to prevent specific words from being converted. This is useful for words like "dialog", "color", or "center" that are conventional American spellings in technical contexts.
# Global exceptions (all strategies)
dialog
# Wildcard — ignores 'dialog', 'dialogs', and any other dictionary
# entry starting with 'dialog'
dialog*
# Strategy-scoped exceptions (only apply to that file type)
code:color
code:center*
markdown:dialog
- One word per line,
#comments, blank lines skipped - Optional
strategy:prefix scopes the exception to that strategy only - A trailing
*acts as a prefix wildcard, ignoring the base word and all its inflected/compound forms in the dictionary (e.g.color*ignorescolor,colors,colored,colorful,colorize, etc.) - A bare
*entry is invalid and ignored; it does not match anything or act as "ignore everything" - Words use American (source) spelling (e.g.
colornotcolour) - Case-insensitive
Britfix walks up from the target file, stopping at the first .git boundary, the home directory, or the filesystem root (whichever is found first). It collects .britfixignore files from that boundary down to the file's directory, merging them additively.
A personal ignore file applies to all projects:
- Linux/macOS:
~/.config/britfix/ignore(or$XDG_CONFIG_HOME/britfix/ignoreif set) - Windows:
%APPDATA%\britfix\ignore
With this .britfixignore at your project root:
dialog*
code:color*
code:center
Running britfix on a Python file:
# The color is nice -> unchanged (code:color* exception)
# The dialogs work -> unchanged (global dialog* exception)
# The behavior is ok -> # The behaviour is ok (not excepted)Running britfix on a Markdown file:
The color is nice -> The colour is nice (color* is code-scoped, doesn't apply)
Open the dialog -> unchanged (global dialog* exception)
Open the dialogs -> unchanged (global dialog* wildcard covers inflected forms)
Edit config.json to customise file type handling:
{
"strategies": {
"code": {
"extensions": [".py", ".js", ".ts", ...]
}
}
}The britfix_hook.py script integrates with tools that support hooks to automatically fix spellings when files are written.
-
Install dependencies:
just sync -
Configure your tool to call the hook. Example for settings:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "/absolute/path/to/britfix/run-hook.sh",
"timeout": 10
}
]
}
]
}
}Enable logging by uncommenting in run-hook.sh:
export BRITFIX_LOG=/tmp/britfix.logThen watch: tail -f /tmp/britfix.log
just sync # Install dependencies
just test # Run tests
just test-hook # Test hook
just build # Build standalone binary
just clean # Remove build artefactsMIT