diff options
| author | mhegazy <mhegazy@users.noreply.github.com> | 2026-10-27 20:11:58 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-10-27 20:11:58 +0000 |
| commit | 70ef2c2ed7001343cc954bb6ea8060d9475639bb (patch) | |
| tree | 514ebc9e3681418fec3b6dbc1c959a8fbbd29f95 /plugins/security-guidance/hooks/_base.py | |
| parent | f8c5e7a1dcb71b10cb74586224b5401f3de5db28 (diff) | |
security-guidance: stop starting the packaged Python alias on every hookmhegazy/sg-launcher-alias-real-path
On Windows with the Python Install Manager, python, python3 and py are
packaged aliases under ...\Microsoft\WindowsApps, and each start of one
makes Windows run an App Installer update check for the package. The
launcher started the chosen alias twice per hook (probe, then the hook),
on every Edit, prompt and Stop. See anthropics/claude-code#98929.
When the name that answers is such an alias and its interpreter is a
regular python*.exe elsewhere, the launcher now checks that interpreter
once (same version, reads the hook script when started by itself), runs
the hook with it, and keeps its path in the state folder for a day.
Later hooks start it directly: one process, none through the alias.
The remembered path is used only while PATH and the hook folder are
unchanged and the file is still there. A hook that fails on it empties
the entry so the next hook searches again. Not used while VIRTUAL_ENV is
set. Other systems, regular installs and Microsoft Store Python are
unchanged.
Hooks report launcher_direct (1 remembered, 2 just checked) as the last
metric key on rows they already send.
Diffstat (limited to 'plugins/security-guidance/hooks/_base.py')
| -rw-r--r-- | plugins/security-guidance/hooks/_base.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/plugins/security-guidance/hooks/_base.py b/plugins/security-guidance/hooks/_base.py index 28b189a4..c265b959 100644 --- a/plugins/security-guidance/hooks/_base.py +++ b/plugins/security-guidance/hooks/_base.py @@ -378,6 +378,16 @@ def launcher_probe_metrics(): return {"launcher_probe_ms": min(total, cap), "launcher_probe_max_ms": min(slowest, cap)} +def launcher_direct_metric(): + """`launcher_direct` when sg-python.sh ran this hook with the interpreter + behind a packaged Windows alias instead of the alias: 1 from the path it + remembered (one process for the hook), 2 when it had just worked that + path out. Read once, like the probe timings. + """ + how = os.environ.pop("SG_LAUNCHER_DIRECT", "") + return {"launcher_direct": int(how)} if how in ("1", "2") else {} + + def _usage_metrics(): """Snapshot the accumulator as metric keys. Returns {} when no API calls AND no HTTP errors were made so skip-path emits don't burn key budget. |
