Back to Hooks

Britfix

PostToolUse

Converts American English to British English in Claude Code output, with context-awareness for code files

localizationbritishspellingtext

Hook Script

#!/bin/bash
# Britfix - Convert American English to British English
# Context-aware: skips code identifiers and strings

FILE_PATH="$1"

# Skip binary files and certain extensions
if [[ "$FILE_PATH" =~ .(png|jpg|gif|ico|woff|ttf|eot)$ ]]; then
  exit 0
fi

# Only process text files (markdown, txt, etc.)
if [[ ! "$FILE_PATH" =~ .(md|txt|rst|adoc)$ ]]; then
  exit 0
fi

# Common American to British spelling conversions
declare -A conversions=(
  ["color"]="colour"
  ["favorite"]="favourite"
  ["honor"]="honour"
  ["behavior"]="behaviour"
  ["neighbor"]="neighbour"
  ["organize"]="organise"
  ["realize"]="realise"
  ["analyze"]="analyse"
  ["customize"]="customise"
  ["optimize"]="optimise"
  ["center"]="centre"
  ["theater"]="theatre"
  ["meter"]="metre"
  ["fiber"]="fibre"
  ["defense"]="defence"
  ["offense"]="offence"
  ["license"]="licence"
  ["practice"]="practise"
)

# Apply conversions to the file
for american in "${!conversions[@]}"; do
  british="${conversions[$american]}"
  sed -i "s/\b$american\b/$british/g" "$FILE_PATH"
  # Also handle capitalized versions
  sed -i "s/\b${american^}\b/${british^}/g" "$FILE_PATH"
done

echo "Britfix: Converted spellings in $FILE_PATH"

Settings Configuration

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "command": "./hooks/britfix.sh"
      }
    ]
  }
}

How to use

  1. Create a hooks directory in your project: mkdir hooks
  2. Save the hook script as hooks/britfix.sh
  3. Make it executable: chmod +x hooks/britfix.sh
  4. Add the configuration to your Claude Code settings
  5. Restart Claude Code to apply changes