Skip to content

Add Claude Code hooks for the repo's never-do rules - #45

Merged
solcott merged 1 commit into
mainfrom
chore/claude-hooks
Sep 30, 2026
Merged

solcott merged 1 commit into
mainfrom
chore/claude-hooks

Conversation

@solcott

@solcott solcott commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Summary

This repo's "never do X" rules were written down but nothing enforced them. These project hooks, in .claude/settings.json with scripts under .claude/hooks/, enforce them for every Claude Code session in the repo.

Hook When Does
pre-tool-guard.sh before Bash / Edit / Write Denies git add -A / --all / . (it sweeps up Xcode xcuserdata/), a force push without --force-with-lease, edits under build/ (Apollo generated code), and hand edits to kotlin-js-store/*.lock
pre-commit-ktfmt.sh before git commit Only when Kotlin is staged: runs ktfmtCheck, plus build-logic's check when build-logic files are staged. Blocks the commit with the ktfmtFormat command to run, instead of failing in CI
post-edit-check.sh after Edit / Write Rejects a vector drawable containing ?attr/ or @android:, which builds clean and crashes at runtime. Reminds that styles.css duplicates WebSkin's page colour

.gitignore now un-ignores .claude/hooks/.

Known limitation: the git add check matches the text anywhere in a command, so echo git add -A is also blocked. It's harmless, and the check stays a simple regex.

Test plan

  • Ran each script by hand on real and made-up paths. Every blocked case above was denied. Explicit-path git add, --force-with-lease, ordinary pushes and normal edits were allowed.
  • The drawable check flagged a planted ?attr/ and passed a clean drawable.
  • Checked the hook is live in a session: echo git add -A was denied.
  • The commit hook exits in about 0.3s with no Kotlin staged.
  • The first commit with staged Kotlin exercises the Gradle half of pre-commit-ktfmt.sh.

🤖 Generated with Claude Code

Project hooks in .claude/settings.json, backed by scripts in
.claude/hooks/ (now un-ignored):

- pre-tool-guard.sh (PreToolUse): denies `git add -A`/`--all`/`.`,
  a force push without --force-with-lease, edits under build/
  (Apollo generated code), and hand edits to the npm lockfiles.
- pre-commit-ktfmt.sh (PreToolUse on `git commit`): when Kotlin is
  staged, runs ktfmtCheck (and build-logic's) and blocks the commit
  with the ktfmtFormat command to run.
- post-edit-check.sh (PostToolUse): rejects vector drawables with
  ?attr/ or @android: references, which crash at runtime, and reminds
  that styles.css duplicates WebSkin's page colour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@solcott
solcott merged commit 2f13b8a into main Sep 30, 2026
1 check passed
@solcott
solcott deleted the chore/claude-hooks branch September 30, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant