Spell-Check Markdown After Every Edit
Use when typos keep slipping into READMEs and docs. After each Markdown edit, the hook runs cspell and feeds any unknown words back to Claude, which corrects them immediately.
miki/spell-check-markdown-after-every-edit · v1
Use when typos keep slipping into READMEs and docs. After each Markdown edit, the hook runs cspell and feeds any unknown words back to Claude, which corrects them immediately.
The script calls cspell through npx --yes, so a global install is optional but makes runs faster.
jq --version && npm install -g cspellNon-Markdown files exit immediately, so code edits pay nothing.
mkdir -p .claude/hooks && cat > .claude/hooks/spellcheck-md.sh <<'EOF'
#!/bin/bash
INPUT=$(cat)
FILE=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
case "$FILE" in
*.md|*.mdx|*.markdown) ;;
*) exit 0 ;;
esac
ISSUES=$(npx --yes cspell lint --no-progress --no-summary "$FILE" 2>/dev/null)
if [ -n "$ISSUES" ]; then
echo "Possible spelling issues in $FILE:" >&2
echo "$ISSUES" | head -n 15 >&2
exit 2
fi
exit 0
EOFchmod +x .claude/hooks/spellcheck-md.shMerge into .claude/settings.json.
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/spellcheck-md.sh",
"timeout": 60
}
]
}
]
}
}Ask Claude to add a sentence containing 'recieve' to the README.
- The hook report lists the misspelling with file and line
- Claude fixes the typo in a follow-up edit without being asked
- Editing a .ts file triggers no spell-check
Silence false positives on product names and jargon by listing them in cspell.json at the repo root.
cat > cspell.json <<'EOF'
{
"version": "0.2",
"words": ["setfork", "your-product-name", "kubectl"]
}
EOF
