anthropics / anthropics/claude-plugins-official

security-guidance 2.0.6: PostToolUse/Bash registers the SAME hook command 5 times, spawning 5 identical Python processes per Bash call

Offen Anfängerfreundlich
#4,894 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
36.3k
Forks
4.1k
Ø Merge
2 T. 14 Std.
Gemergte PRs (30 T.)
539

Beschreibung

## Summary

In `plugins/security-guidance/hooks/hooks.json`, the `PostToolUse` matcher group for `Bash` contains **five entries whose `command` strings are byte-identical**. Every `Bash` tool call therefore runs the same `security_reminder_hook.py` five times, producing five identical reminders' worth of work for one reminder's output.

The other four registrations in the file (`SessionStart`, `UserPromptSubmit`, `PostToolUse` for `Edit|Write|MultiEdit|NotebookEdit`, `Stop`) each have exactly one entry, which is what makes the `Bash` group look like an editing accident rather than intent.

## Evidence

Against `plugins/security-guidance/hooks/hooks.json` at repo HEAD (plugin version 2.0.6), counting entries per matcher group and hashing each command string:

```
EVENT PostToolUse -> 2 matcher group(s)
[0] matcher="Edit|Write|MultiEdit|NotebookEdit" hooks=1
cmd sha1: bc4f760175f9
[1] matcher="Bash" hooks=5
cmd sha1: bc4f760175f9
cmd sha1: bc4f760175f9
cmd sha1: bc4f760175f9
cmd sha1: bc4f760175f9
cmd sha1: bc4f760175f9
```

All five hashes are equal, and equal to the single `Edit|Write` entry, so the five are not variants that differ by argument or matcher.

## Why it costs more than 5x a cheap script

Each invocation is a three-stage chain, not a single process:

1. `bash` spawn,
2. `sg-python.sh`, which probes candidate interpreters with `-c ""` (`python3`, then `python`, then `py -3`),
3. cold CPython start for a 2,325-line script.

So the multiplier lands on interpreter startup and interpreter probing, which is the expensive part. It is worst on Windows + Git Bash, where the shim exists precisely because `python3` resolves to the Microsoft Store stub and has to fail a probe before falling through.

`PostToolUse` blocks the agent loop on every tool call, so this is per-Bash-call latency, not background cost.

## Suggested fix

Reduce the `Bash` group to a single hook entry. If the five entries were meant to be distinct checks that were later consolidated into one script, the duplicates are now dead weight; if they were meant to differ by matcher, the matchers were lost.

## Environment

- security-guidance 2.0.6 (also confirmed at repo HEAD, not just the local cache)
- Windows 11, Git Bash, Claude Code 2.1.222
- Found while auditing hook timings across 200 sessions; `PostToolUse` hooks in that window averaged 1.0s with a 6.6s worst case.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Open plugins/security-guidance/hooks/hooks.json and inspect the PostToolUse group whose matcher is Bash. Compare its five command entries with the other matcher groups, remove the duplicate registrations so Bash has one entry, and verify that the file contains one command for that matcher.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
bash, python
Bereich
devtools, performance
Issue-Typ
Bug
Schwierigkeit
1/5
Geschätzter Aufwand
Unter einer Stunde
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
88/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.