summaryrefslogtreecommitdiff
path: root/plugins/security-guidance/hooks/security_reminder_hook.py
diff options
context:
space:
mode:
authorMohamed Hegazy <mhegazy@anthropic.com>2026-10-13 20:57:12 +0000
committerClaude <noreply@anthropic.com>2026-10-13 20:57:12 +0000
commit84f3cd05382d6c190fc0b09ca2cd2f4d5432e7f6 (patch)
treee39966a885fbb544eff5191f6bf351e8fff32837 /plugins/security-guidance/hooks/security_reminder_hook.py
parentf359d43b406057f1a8cdbc4ea93b827642c162e6 (diff)
security-guidance: keep the Stop review working when the changed paths do not fit one command
The Stop review passed every changed path to `git diff` as arguments. With enough of them (an unignored cache, a repo at $HOME) the OS refused to start git, the diff failed twice, and the turn's real edits were never reviewed. When the OS refuses the argument list, keep only the paths the review can use (reviewable source files) and send them in a few commands under the same time limit. A path list that fits one command is handled exactly as before. Skip review sets of more than 100,000 paths before any diff. Fixes #4824
Diffstat (limited to 'plugins/security-guidance/hooks/security_reminder_hook.py')
-rwxr-xr-xplugins/security-guidance/hooks/security_reminder_hook.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/plugins/security-guidance/hooks/security_reminder_hook.py b/plugins/security-guidance/hooks/security_reminder_hook.py
index e8df7a1c..6b885e64 100755
--- a/plugins/security-guidance/hooks/security_reminder_hook.py
+++ b/plugins/security-guidance/hooks/security_reminder_hook.py
@@ -189,6 +189,12 @@ MAX_STOP_HOOK_FIRINGS = int(os.environ.get("MAX_STOP_HOOK_FIRINGS", "3"))
# diff; unbounded diffs burn tokens and risk 400 on context length.
MAX_DIFF_FILES = int(os.environ.get("MAX_DIFF_FILES", "30"))
+# Changed paths past which the Stop review is skipped before any diff. A set
+# this large is a repo at $HOME or an unignored cache, not edits; no platform
+# takes that many paths in one git command, and only resolving them takes
+# seconds.
+MAX_REVIEW_SET_PATHS = int(os.environ.get("MAX_REVIEW_SET_PATHS", "100000"))
+
# Appended to all exit(2) guidance so the asyncRewake auto-turn doesn't
# cause the model to abandon the user's original request.
CONTINUATION_SUFFIX = (
@@ -2016,6 +2022,10 @@ def handle_stop_hook(input_data):
debug_log("Stop hook: empty review set")
_skip(9, touched_paths_count=len(touched_paths))
debug_log(f"Stop hook: review_set={len(review_paths)} base={diff_base[:12]} dirty_now={v2_metrics['dirty_now_count']} changed_since={v2_metrics['changed_since_count']}")
+ if len(review_paths) > MAX_REVIEW_SET_PATHS:
+ debug_log(f"Stop hook: pathological review set (more than "
+ f"{MAX_REVIEW_SET_PATHS} paths), skipping")
+ _skip(8)
# Run from repo_root so the toplevel-relative review_paths resolve.
# Diff CONTENT against the turn-start stash (baseline_sha) so the LLM
# sees only this-turn edits — diffing against HEAD includes the user's