Skip to content

Add an advisory agent hook reviewing the files a push adds - #2387

Merged
Flix6x merged 1 commit into
mainfrom
chore/agent-push-file-review
Aug 4, 2026
Merged

Add an advisory agent hook reviewing the files a push adds#2387
Flix6x merged 1 commit into
mainfrom
chore/agent-push-file-review

Conversation

@Flix6x

@Flix6x Flix6x commented Aug 4, 2026

Copy link
Copy Markdown
Member

Description

A file can enter a branch without anyone deciding it should. This has happened twice recently:

Both were additions. Modified files are nearly always deliberate; a brand-new file nobody mentioned is the one worth a second look.

  • .claude/hooks/push_file_review.py — lists what a push adds relative to the merge-base, and names the ones that look unintended
  • Wired in .claude/settings.json as a PreToolUse hook on git push, next to the existing test-reminder.sh

What it flags

Dotfiles, .orig/.rej/.bak/.swp debris, scratch-looking names (local, scratch, probe, debug, tmp), build and runtime artifacts, and anything outside flexmeasures/, documentation/, tests/, .github/, .claude/.

Everything added is listed regardless; the flagged subset just gets called out.

Two deliberate choices

Advisory, exits 0. It cannot know intent — it can only ask whether an addition was meant. That is a question an agent can answer by looking, and a blocking gate cannot. Same reasoning as #2386.

It prints which base it used. The base is the tracked upstream when there is one, else origin/main. Getting that wrong makes the added-file list either noisy or empty, and a stacked branch's base changes when its parent merges — #2289's went from feat/chp to main mid-flight. Printing it makes a wrong guess visible rather than silent.

How to test

Proven capable of failing (per #2384). Against a synthetic commit adding .git-exclude, scratch/local_probe.py and a legitimate module:

This push adds 5 file(s), compared against origin/main:
    .claude/hooks/push-file-review.sh
    .claude/hooks/push_file_review.py
    .git-exclude
    flexmeasures/data/models/planning/legit_module.py
    scratch/local_probe.py

Worth confirming you meant to add these:
    .git-exclude — a dotfile
    scratch/local_probe.py — a scratch-looking name

It flags the two junk files, and leaves the legitimate module and its own files alone. With only a legitimate addition, it lists it and flags nothing.

Limits

It can ask "did you mean to add this?" but not "does this belong in this commit" — it would have caught .git-exclude cleanly, and the scheduling_problem.py case only partially.

Related items

A file can enter a branch without anyone deciding it should. It has happened
twice recently: .git-exclude reached #2289 through a merge and survived until
review, and a `git add -A` swept scheduling_problem.py into a commit that
imported nothing from it.

Both were additions. Modified files are nearly always deliberate; a brand-new
file nobody mentioned is the one worth a second look. So the hook lists what a
push adds relative to the merge-base, and names the ones that look unintended:
dotfiles, .orig/.rej/.bak debris, scratch-looking names, build artifacts, and
anything outside the usual directories.

Advisory, exits 0. It cannot know intent -- it can only ask whether the
addition was meant, which is a question an agent can answer and a gate cannot.

The base is the tracked upstream when there is one, else origin/main, and it
prints which base it used, so a wrong guess is visible rather than silent.
That matters here: a stacked branch's base changes when its parent merges.

Self-tested both directions. Against a synthetic commit adding .git-exclude,
scratch/local_probe.py and a legitimate module, it flags the first two and
leaves the module and its own files alone; with only a legitimate addition it
lists it and flags nothing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X2jLjsQzwztDc7Nxz1ozmQ
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x Flix6x self-assigned this Aug 4, 2026
@Flix6x Flix6x added the AI Infra label Aug 4, 2026
@Flix6x Flix6x added this to the 1.0.0 milestone Aug 4, 2026
@Flix6x
Flix6x merged commit 34af65d into main Aug 4, 2026
13 checks passed
@Flix6x
Flix6x deleted the chore/agent-push-file-review branch August 4, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant