PostToolUse hook that flags two review hazards as Claude writes files: edits to generated or vendored artifacts (lockfiles, minified bundles, source maps, dist/build output, snapshots, protobuf output) and oversized diffs that change more lines than a configurable threshold versus the committed version.
Runs after every Write, Edit, and MultiEdit and inspects only the edited file path and its line-change count., Stays read-only and uses git diff --numstat to count changed lines; it never edits, stages, or commits anything., Advisory by design and always exits 0, so it never blocks a write even when it flags a large or generated diff., The line threshold defaults to 500 and is configurable through the GENERATED_DIFF_LINE_THRESHOLD environment variable.
Privacy notes
Reads only the edited file path from the tool input and the git numstat for that path; it does not read or transmit file contents., Prints the file path and a changed-line count to local hook stderr; it makes no network calls and writes no logs., The file path shown in output may reveal local directory structure in your terminal.
Author
jony376
Submitted by
jony376
Claim status
unclaimed
Last verified
2026-06-04
Decision playbook
Review trust signals before you adopt
Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.
Compare context
Selected
0
Current score
78
Baseline
—
Delta
No baseline selected
No major trust-signal divergence detected in the current selection.
Source and provenance checks
Complete
Confirm ownership and provenance before trusting install instructions.
Source link availableRequired
Open the canonical repository and verify ownership.
Done
Source provenance statusRequired
Marked as source-backed.
Done
Metadata reviewed
Registry metadata indicates a reviewed listing.
Done
Safety and privacy checks
Complete
Validate risk disclosures before installation or API wiring.
Safety notes presentRequired
Review the listed safety guidance before running commands.
Done
Privacy notes presentRequired
Review data handling notes before connecting accounts or secrets.
Done
Trust level risk gateRequired
Trust level does not block evaluation.
Done
Package and install checks
Needs review
Check package metadata and artifact integrity signals.
Install payload available
Install or copy payload is available for review.
Done
Package verification flag
No package verification flag provided.
Pending
Checksum metadata
No checksum provided for downloaded artifact.
Pending
Compare-driven decision checks
Needs review
Use compare context to validate trade-offs before adoption.
Compare tray has multiple entries
Add at least one more entry to compare trust differences.
Current risk score 16/100. Use staged verification before broader rollout.
Risk 16
Pre-adoption checks
Validate source and review signals before any execution.
Confirm source provenanceRequired
Source URL/provenance metadata is present.
Done
Confirm metadata review state
Listing has review metadata.
Done
Verify install payload
Install/config payload exists and can be inspected.
Done
Security checks
Confirm safety, privacy, and package integrity signals.
Review safety notesRequired
Safety notes are present.
Done
Review privacy notesRequired
Privacy notes are present.
Done
Verify package integrity metadata
No package verification/checksum metadata.
Pending
Rollout
Adopt in controlled steps based on the selected plan.
Run in isolated sandbox firstRequired
Use a constrained sandbox and observe behavior across multiple tasks.
Pending
Roll out graduallyRequired
Roll out to a small cohort before wider usage.
Pending
Set monitoring and fallback
Define rollback path and monitor errors after adoption.
Pending
Evidence readiness
Evidence readiness matrix · balanced
Required evidence gates are covered (5/6 signals complete).
Risk 15
Source provenance
Present
Source repository/provenance is listed.
Required in this preset
Metadata review
Present
Review metadata is present.
Required in this preset
Safety notes
Present
Safety notes are present.
Required in this preset
Privacy notes
Present
Privacy notes are present.
Optional in this preset
Package integrity
Missing
Package integrity metadata is missing.
Optional in this preset
Install payload
Present
Install payload is available.
Required in this preset
Required evidence gates are covered for this preset.
Decision timeline
Decision timeline · balanced
5/6 steps complete with no blocking gaps for this preset.
Risk 14
triage
Confirm source provenanceRequired
Source/provenance metadata is available.
Done
triage
Check metadata review statusRequired
Review metadata is available.
Done
verify
Review safety notesRequired
Safety notes are available.
Done
verify
Review privacy notes
Privacy notes are available.
Done
verify
Validate package integrity metadata
Package integrity metadata is missing.
Pending
rollout
Verify install payload and commandsRequired
Install payload is available.
Done
No required blockers for this timeline preset.
Prerequisite readiness
Prerequisite readiness
3 prerequisites to line up before setup.
0/3 ready
Install & runtime1General2
Safety & privacy surface
Safety & privacy surface
4 safety and 3 privacy notes across 3 risk areas. Review closely: network access.
3 areas
SafetyLocal filesRuns after every Write, Edit, and MultiEdit and inspects only the edited file path and its line-change count.
SafetyGeneralStays read-only and uses git diff --numstat to count changed lines; it never edits, stages, or commits anything.
SafetyGeneralAdvisory by design and always exits 0, so it never blocks a write even when it flags a large or generated diff.
SafetyGeneralThe line threshold defaults to 500 and is configurable through the GENERATED_DIFF_LINE_THRESHOLD environment variable.
PrivacyLocal filesReads only the edited file path from the tool input and the git numstat for that path; it does not read or transmit file contents.
PrivacyNetwork accessPrints the file path and a changed-line count to local hook stderr; it makes no network calls and writes no logs.
PrivacyLocal filesThe file path shown in output may reveal local directory structure in your terminal.
Safety notes
Runs after every Write, Edit, and MultiEdit and inspects only the edited file path and its line-change count.
Stays read-only and uses git diff --numstat to count changed lines; it never edits, stages, or commits anything.
Advisory by design and always exits 0, so it never blocks a write even when it flags a large or generated diff.
The line threshold defaults to 500 and is configurable through the GENERATED_DIFF_LINE_THRESHOLD environment variable.
Privacy notes
Reads only the edited file path from the tool input and the git numstat for that path; it does not read or transmit file contents.
Prints the file path and a changed-line count to local hook stderr; it makes no network calls and writes no logs.
The file path shown in output may reveal local directory structure in your terminal.
Prerequisites
Claude Code CLI with hooks enabled.
bash and jq on PATH; the hook fails open and stays silent when jq is missing.
git is optional - the diff-size check runs only inside a git work tree with a committed baseline; the generated-path check works without git.
Schema details
Install type
cli
Troubleshooting
No
Source repository stats
Scope
Source repo
Runtime and command metadata
Trigger
PostToolUse
Script language
bash
Script body
#!/usr/bin/env bash
set -u
# Claude Code PostToolUse hook. Flags two review hazards after a write/edit:
# (1) the target is a generated or vendored artifact, and (2) the diff versus
# the committed version exceeds a line threshold. Advisory only - it always
# exits 0 and never blocks - and fails open if jq is unavailable.
command -v jq >/dev/null 2>&1 || exit 0
INPUT=$(cat)
FILE=$(printf '%s' "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
[ -z "$FILE" ] && exit 0
LINE_THRESHOLD=${GENERATED_DIFF_LINE_THRESHOLD:-500}
# 1) Generated / vendored artifact paths that are usually regenerated, not
# hand-edited (mirrors common linguist-generated / linguist-vendored sets).
case "$FILE" in
*package-lock.json|*pnpm-lock.yaml|*yarn.lock|*.min.js|*.min.css|*.map|*/dist/*|*/build/*|*/out/*|*/vendor/*|*.snap|*/__snapshots__/*|*.generated.*|*_pb2.py|*.pb.go)
echo "Generated artifact - $FILE looks generated or vendored; prefer regenerating it or marking it linguist-generated in .gitattributes instead of hand-editing." >&2
;;
esac
# 2) Oversized diff against the committed version (only when git-tracked).
if command -v git >/dev/null 2>&1 && git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
changed=$(git diff --numstat HEAD -- "$FILE" 2>/dev/null | awk '{sum += $1 + $2} END {print sum + 0}')
case "$changed" in
''|*[!0-9]*) changed=0 ;;
esac
if [ "$changed" -ge "$LINE_THRESHOLD" ]; then
echo "Large diff - $FILE changes $changed lines vs HEAD (threshold $LINE_THRESHOLD); consider splitting into smaller, reviewable commits." >&2
fi
fi
exit 0
Flags two distinct review hazards the moment Claude writes a file: edits to generated or vendored artifacts, and oversized diffs against the committed version.
Generated-path detection mirrors common linguist-generated / linguist-vendored sets — lockfiles, minified bundles, source maps, dist//build//out//vendor/ trees, snapshots, and protobuf output.
Diff-size detection counts added + removed lines versus HEAD and warns past a configurable threshold (GENERATED_DIFF_LINE_THRESHOLD, default 500).
Advisory only — it always exits 0, so it surfaces churn without blocking the edit.
Fails open and reads no file contents; only the path and line counts are inspected.
How it works
On PostToolUse, the hook reads the edited file path from the tool input. It matches that path against a set of generated/vendored patterns and, when inside a git work tree, runs git diff --numstat HEAD -- <file> to total the changed lines. Either signal prints an advisory message to stderr; neither blocks the write.
Use cases
Keep a regenerated package-lock.json or minified bundle from being hand-edited or buried in a review.
Catch an accidental 2,000-line change that should have been several focused commits.
Nudge contributors to mark generated paths linguist-generated so diffs collapse in review.
Installation
Create the hooks directory: mkdir -p .claude/hooks
Create the hook file: touch .claude/hooks/large-generated-diff-detector.sh
Paste the script body into that file and make it executable: chmod +x .claude/hooks/large-generated-diff-detector.sh
Add the configuration below to .claude/settings.json (project) or ~/.claude/settings.json (user).
Requirements
Claude Code CLI with hooks enabled
bash and jq
git (optional; required only for the diff-size check)
GENERATED_DIFF_LINE_THRESHOLD — changed-line count (added + removed) above which a diff is flagged. Defaults to 500.
Limitations
The generated-path list covers common ecosystems; extend the case patterns for your stack (for example Go *.pb.go, Python *_pb2.py, or framework-specific build dirs).
The diff-size check needs a committed baseline; brand-new untracked files are reported only by the generated-path check.
Show that Large Generated Diff Detector - Claude Code Hook is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.
[](https://heyclau.de/entry/hooks/large-generated-diff-detector)
How it compares
Large Generated Diff Detector - Claude Code Hook side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.
2 trust signals differ across this comparison (Source provenance, Submitter).
PostToolUse hook that flags two review hazards as Claude writes files: edits to generated or vendored artifacts (lockfiles, minified bundles, source maps, dist/build output, snapshots, protobuf output) and oversized diffs that change more lines than a configurable threshold versus the committed version.
PostToolUse hook that compares a just-edited OpenAPI or JSON Schema document against the version committed in git and warns about backward-incompatible drift — removed OpenAPI paths and removed required properties — so breaking API changes are surfaced before they ship. Advisory only; it never blocks the edit.
Detects unused CSS selectors when stylesheets are modified to keep CSS lean using PurgeCSS, PostCSS, and content analysis. This hook runs on CSS/SCSS file write/edit operations and analyzes stylesheets to identify unused selectors, generate optimized output, and report before/after size metrics.
✓Runs after every Write, Edit, and MultiEdit and inspects only the edited file path and its line-change count.
Stays read-only and uses git diff --numstat to count changed lines; it never edits, stages, or commits anything.
Advisory by design and always exits 0, so it never blocks a write even when it flags a large or generated diff.
The line threshold defaults to 500 and is configurable through the GENERATED_DIFF_LINE_THRESHOLD environment variable.
✓Read-only advisory hook; it does not block writes unless you wrap it with strict exit handling.
Does not substitute for npm audit, OSV scans, or CI dependency review.
✓Runs after every Write, Edit, and MultiEdit and only inspects JSON files that declare openapi, swagger, a $schema key, or paths.
Stays read-only and runs git show to read the committed version; it never edits, stages, or commits anything.
Advisory by design and always exits 0, so it never blocks a write even when drift is detected.
Uses key-set comparison heuristics for removed paths and required fields, so it catches common breaking changes but is not a full OpenAPI diff.
✓Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.
Privacy notes
✓Reads only the edited file path from the tool input and the git numstat for that path; it does not read or transmit file contents.
Prints the file path and a changed-line count to local hook stderr; it makes no network calls and writes no logs.
The file path shown in output may reveal local directory structure in your terminal.
✓Lockfile paths and registry hostnames are printed locally to stderr for the active session.
✓Reads the edited schema file and its committed HEAD version from the local repository only.
Prints removed path and required-field names to local hook stderr; it makes no network calls and writes no logs.
Path and field names shown in output may reveal internal API surface in your terminal.
✓Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.
Prerequisites
Claude Code CLI with hooks enabled.
bash and jq on PATH; the hook fails open and stays silent when jq is missing.
git is optional - the diff-size check runs only inside a git work tree with a committed baseline; the generated-path check works without git.
jq available when reviewing npm package-lock.json resolved URLs.
Team policy for allowed npm registries and lockfile update requirements.
Claude Code CLI with hooks enabled.
git, jq, and bash on PATH; the hook fails open and stays silent when git or jq is missing.
The schema file must be tracked in git so a committed baseline exists to diff against.