Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore(studio): add PostToolUse hook to auto-format and lint studio files (#44350)

Alaister Young48e0b0c5592f
diff --git a/.claude/scripts/format_and_lint.sh b/.claude/scripts/format_and_lint.sh
new file mode 100755
index 00000000000..8969b4da89e
--- /dev/null
+++ b/.claude/scripts/format_and_lint.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# PostToolUse hook: format and lint apps/studio/ files after Write or Edit.
+# Receives hook JSON on stdin from Claude Code.
+
+set -euo pipefail
+
+# Extract the file path from stdin JSON.
+# Falls back to .tool_response.filePath for Write tool compat.
+file_path=$(jq -r '.tool_input.file_path // .tool_response.filePath' 2>/dev/null)
+
+if [[ -z "$file_path" || "$file_path" == "null" ]]; then
+ exit 0
+fi
+
+# Only run for files under apps/studio/
+case "$file_path" in
+ *apps/studio/*)
+ cd "$CLAUDE_PROJECT_DIR"
+ pnpm exec prettier --config prettier.config.mjs --write "$file_path"
+
+ # ESLint only for JS/TS files
+ case "$file_path" in
+ *.ts|*.tsx|*.js|*.jsx)
+ pnpm --filter=studio exec eslint --fix "$file_path"
+ ;;
+ esac
+ ;;
+esac
diff --git a/.claude/settings.json b/.claude/settings.json
index 502fd54dc4b..3ffd1f88913 100644
--- a/.claude/settings.json
+++ b/.claude/settings.json
@@ -10,6 +10,18 @@
}
]
}
+ ],
+ "PostToolUse": [
+ {
+ "matcher": "Write|Edit",
+ "hooks": [
+ {
+ "type": "command",
+ "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/scripts/format_and_lint.sh",
+ "statusMessage": "Formatting & linting..."
+ }
+ ]
+ }
]
}
}