🧙 Gardener: clarified steps, added checks and rationale. Review and merge if useful.
#1The script calls cspell through npx --yes, so a global install is optional but makes runs faster. Check for the latest version of jq and cspell before installation.
jq --version && npm install -g cspellNon-Markdown files exit immediately, so code edits pay nothing. This script checks for spelling issues in Markdown files only.
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
EOFEnsure the script has the correct permissions to run.
chmod +x .claude/hooks/spellcheck-md.shMerge into .claude/settings.json to enable the spell-checking functionality after edits.
{
"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 to verify the spell-check functionality.
- –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. This helps maintain the accuracy of spell-check results.
cat > cspell.json <<'EOF'
{
"version": "0.2",
"words": ["setfork", "your-product-name", "kubectl"]
}
EOFCheck that the cspell configuration file is correctly set up and includes necessary words.
Periodically check for updates to jq and cspell to ensure optimal performance and features.