prettier-markdown-hook
Automatically format markdown files with prettier when Claude stops responding, with configurable organization and path exclusions
Installation
Open Claude Code and run this command:
/plugin install prettier-markdown-hook@claude-code-plugins-plus
Use --global to install for all projects, or --project for current project only.
What It Does
This Claude Code plugin provides a Stop hook that automatically formats markdown files in your workspace using prettier. It runs asynchronously in the background after every conversation, ensuring consistent markdown formatting without interrupting your workflow.
Features
- ✅ Zero-Config Default: Works immediately after installation with sensible defaults
- ✅ Organization Exclusions: Skip formatting for specific GitHub organizations (e.g., company repos)
- ✅ Path Exclusions: Exclude specific directories or file patterns
- ✅ AI Commit Messages: Optional AI-generated commit messages (opt-in)
- ✅ Fire-and-Forget: Async execution (<10ms hook exit time)
- ✅ XDG Compliant: Cross-platform default paths
- ✅ Comprehensive Logging: All operations logged for debugging
How It Works
- Stop Hook: Triggers after Claude finishes responding
- Workspace Check: Verifies you're in a git workspace
- Exclusion Check: Skips excluded organizations/paths
- Format Files: Runs prettier on modified markdown files
- Auto Commit: Creates a conventional commit (optional AI message)
- Background Execution: All processing happens asynchronously
Components
How It Works
Automatic Formatting (Default)
No action required! The hook runs automatically after every conversation:
- You interact with Claude
- Claude finishes responding (Stop event)
- Hook executes in background
- Markdown files formatted
- Changes committed (if any modifications)
Monitoring Hook Execution
Check log file:
tail -20 ~/.local/state/prettier-hook/format-markdown.log
tail -f ~/.local/state/prettier-hook/format-markdown.log
grep -i error ~/.local/state/prettier-hook/format-markdown.log
Example log output:
[2025-11-15 18:30:42] Starting prettier markdown formatting
[2025-11-15 18:30:42] Workspace: /Users/terry/projects/my-app
[2025-11-15 18:30:42] Remote: git@github.com:myuser/my-app.git
[2025-11-15 18:30:42] Exclusion check: NOT excluded (no matching org)
[2025-11-15 18:30:43] Found 5 modified markdown files
[2025-11-15 18:30:45] Formatted 5 files successfully
[2025-11-15 18:30:46] Created commit: style: format markdown files with prettier
[2025-11-15 18:30:46] Prettier formatting completed successfully
Disabling the Hook
Temporary disable (per workspace):
cd /path/to/workspace
/plugin disable prettier-markdown-hook
Permanent uninstall:
/plugin uninstall prettier-markdown-hook
Manual Formatting (Alternative)
While the plugin uses the Stop hook (automatic), you can manually run the script:
~/.claude/plugins/prettier-markdown-hook/scripts/format-markdown.sh
export PATH="$PATH:~/.claude/plugins/prettier-markdown-hook/scripts"
format-markdown.sh
FAQ
Symptom: No formatting happens after Claude stops
Diagnosis:
prettier --version
jq --version
git --version
/plugin list | grep prettier
cat ~/.claude/plugins/prettier-markdown-hook/hooks/hooks.json
Solutions:
- Missing dependencies: Install prettier, jq, git
- Plugin not enabled: Run
/plugin enable prettier-markdown-hook - Not in git workspace: Hook only runs in git repositories
Symptom: Hook runs but files remain unformatted
Diagnosis:
tail -50 ~/.local/state/prettier-hook/format-markdown.log
grep -i "excluded" ~/.local/state/prettier-hook/format-markdown.log
git status
Solutions:
- Workspace excluded: Check
excludeOrgsin config - No modified files: Hook only formats files with uncommitted changes
- Prettier errors: Check log for prettier syntax errors
Symptom: Files formatted in organization that should be excluded
Diagnosis:
cat ~/.prettierrc-hook.json
git remote -v
Solutions:
- Case mismatch: Organization names are case-sensitive
- ✅ Correct:
"Eon-Labs"(capital E, L, hyphen) - ❌ Wrong:
"eonlabs","eon-labs","EonLabs"
- Config not loaded: Verify JSON syntax with
jq empty ~/.prettierrc-hook.json
- Wrong remote format: Hook checks
github.com/pattern/
Symptom: Permission denied errors in log
Solutions:
chmod +x ~/.claude/plugins/prettier-markdown-hook/scripts/format-markdown.sh
mkdir -p ~/.local/state/prettier-hook
chmod 755 ~/.local/state/prettier-hook
Symptom: Hook times out before completing
Solutions:
- Increase timeout in
hooks/hooks.json:
{
"hooks": [
{
"timeout": 60000 // 60 seconds (default: 30000)
}
]
}
- Reduce workspace size: Exclude large directories in
.prettierrc-hook.json
Symptom: Commit messages remain generic even with env var set
Diagnosis:
echo $PRETTIER_ENABLE_AI_COMMITS
which claude
claude --version
Solutions:
- Env var not set: Add to shell profile (~/.zshrc, ~/.bashrc)
- Claude CLI not installed: Install claude CLI tool
- Claude CLI not in PATH: Add to PATH or use full path