Add Claude Code hook to auto-run rustfmt after edits

PostToolUse hook runs rustfmt on any .rs file after Edit/Write,
ensuring Claude-generated Rust code is always properly formatted.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Greg Shuflin
2026-03-03 23:18:22 -08:00
parent 00883f7a01
commit 68edc97e01
+15
View File
@@ -0,0 +1,15 @@
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "FILE=$(jq -r '.tool_input.file_path'); if [[ \"$FILE\" == *.rs ]]; then rustfmt \"$FILE\" 2>/dev/null; fi"
}
]
}
]
}
}