Skip to content

git: guard this repo's commits against a stray work identity - #17

Merged
krishna-bala merged 1 commit into
mainfrom
claude/pre-commit-single-user-fflahi
Aug 14, 2026
Merged

krishna-bala merged 1 commit into
mainfrom
claude/pre-commit-single-user-fflahi

Conversation

@krishna-bala

Copy link
Copy Markdown
Owner

Adds pre-commit, pre-merge-commit, and pre-push hooks under git/hooks/ that refuse any committer address outside a hard-coded two-address allowlist: krishna0bala@proton.me and noreply@anthropic.com (the identity Claude Code web sessions commit under, so those keep working). The goal is to keep a work identity from ever committing to or pushing this repo.

Design

  • Repo-local only. ./install runs git config core.hooksPath git/hooks in this clone (a relative core.hooksPath resolves against the repo root, verified from subdirectories too). No global config is touched and no other repo on the machine is affected.
  • Committer, not author. The committer is whoever is running git right now — the identity that leaks — while the author is provenance worth preserving when amending or rebasing someone else's work. This also keeps the hooks quiet when replaying outside commits: cherry-pick/rebase re-stamp the committer while keeping the original author.
  • pre-push backstop. Catches commits that never saw pre-commit (rebase, cherry-pick, --no-verify, commits predating the hooks) by scanning exactly the commits the push would add (git log <tips> --not --remotes). Branch deletions push no commits and are skipped.
  • Closed allowlist. Deliberately hard-coded in identity-guard.sh with no config escape hatch; the repo is public, so nothing private should ever be written there. Matching is case-insensitive.

All of this is local, best-effort protection: --no-verify and git -c core.hooksPath= bypass it by design. Enforcement that cannot be bypassed has to live on the remote.

Testing

Exercised in a sandboxed clone: work identity blocked at commit, amend, and merge; both allowed identities pass (case-insensitively, from subdirectories too); a --no-verify-smuggled work commit is blocked at push and passes after --amend --reset-author; branch deletion pushes pass; an unrelated repo on the same machine is unaffected. The hooks are also active in the clone that produced this PR and ran on its own commit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRUvdR8pcw238epFLCc7X9


Generated by Claude Code

Adds pre-commit, pre-merge-commit, and pre-push hooks that refuse any
committer address outside a hard-coded two-address allowlist: the personal
identity and the one Claude Code web sessions commit under. ./install wires
them up by pointing this clone's core.hooksPath at git/hooks (a relative
path resolves against the repo root), so the guard is repo-local -- no other
repo on the machine is affected.

The check is on the committer, not the author: the committer is whoever is
running git right now, which is the identity that leaks, while the author is
provenance worth preserving when amending or rebasing someone else's work.

pre-push is a backstop for commits that never saw pre-commit -- rebase,
cherry-pick, --no-verify, or predating the hooks. All of it is bypassable by
design; enforcement that cannot be bypassed has to live on the remote.
@krishna-bala
krishna-bala merged commit b52ed2f into main Aug 14, 2026
2 checks passed
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.

2 participants