summaryrefslogtreecommitdiff
path: root/plugins
AgeCommit message (Collapse)Author
2026-10-19Merge remote-tracking branch 'origin/main' into mhegazy/sg-gateway-loginClaude
# Conflicts: # plugins/security-guidance/README.md # plugins/security-guidance/hooks/security_reminder_hook.py # plugins/security-guidance/tests/test_no_credentials_notice.py
2026-10-19Merge pull request #6755 from anthropics/mhegazy/sg-notebook-edit-patternsMohamed Hegazy
security-guidance: run pattern checks on NotebookEdit cells
2026-10-19security-guidance: run SDK bootstrap subprocesses from the state dirmhegazy/sg-bootstrap-spawn-cwdMohamed Hegazy
`python -c` and `python -m` put the working directory first on the import path, and hooks run in the user's repository. A repository file named claude_agent_sdk.py, venv.py or pip.py was imported in place of the real module by the SessionStart check and the venv build. Run those subprocesses from the plugin's state dir, and make state_dir() return an absolute path as its docstring says, so a relative override isn't resolved twice.
2026-10-19security-guidance: keep a turn's review when the gateway sign-in check gives ↵Mohamed Hegazy
no answer When `claude auth status` gives no usable answer, the Stop hook skipped the review and dropped the turn's changes, so they were never reviewed even once the check answered. They are now kept for the next Stop review, as for other transient skips. A gateway review that runs out of time is no longer tried again on Sonnet: what makes it do so (a rejected sign-in, an unreachable gateway) does not depend on the model, and the second attempt doubled the wait. The timeout's log line now says which API statuses the CLI retried, and includes the CLI's stderr. The new tests no longer share one state file across sessions when run inside a remote session.
2026-10-19security-guidance: review through Claude Code in a Claude apps gateway sign-inMohamed Hegazy
In a Claude Code session signed in to a Claude apps gateway with /login, Claude Code gives plugin hooks no credential, so the Stop, commit, push and agentic commit reviews were all skipped. When the plugin has no credential of its own, it now asks the user's installed claude (`claude auth status --json`) whether the session is signed in to a gateway. A yes or no is kept for the session; when the CLI gives no usable answer, the next hook asks again. If apiProvider is "gateway" and loggedIn is true, the reviews run through that same CLI, which restores the stored sign-in by itself, so no credential enters the plugin. A review the CLI cannot complete counts as a failed review, never a clean one. The reviews run even with CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC set, as they do on Bedrock and Vertex: the gateway docs suggest setting it, and the review goes through the gateway like the session's own requests. The CLI is found the way the agentic reviewer already finds it: SG_AGENTIC_CLI_PATH, CLAUDE_CODE_EXECPATH, then fixed install paths, with no PATH search, and it must be a full path. The reviews use Claude Code's opus and sonnet aliases, which resolve to the ids Claude Code itself uses on a gateway, and get the 120 s a direct review gets. Review rows set bit 4 of gateway_cfg, so this route's failure rate can be read apart from first-party reviews. Every Claude Code the plugin starts for a review, on any provider, now runs with SECURITY_GUIDANCE_DISABLE=1. If policy settings enable the plugin inside that CLI, its hooks there don't start reviews of their own. The weekly notice that the reviews are not running is no longer shown in a session signed in to a gateway, since the reviews do run there. The edit that would show it asks claude first, and the notice marker is written either way, so that edit waits for claude at most once a week. Sessions the gateway route cannot review still get the notice, unless, in the past week, an edit's check found a session signed in to a gateway. Their skipped reviews still report no_creds.
2026-10-19security-guidance: keep added lines past the cut, hold the diff timeoutMohamed Hegazy
A reviewable file past the per-file cap now keeps as much again of its added lines, so a rewritten large file still shows what is new, and its diff ends with a line saying it was cut. The read runs on a thread so the 30 s limit holds while a process git started keeps the pipe open; a read that breaks is an error instead of a short diff. SG_MAX_FILE_DIFF_BYTES of zero or less means the default. The parser and the reader share one test for which files are reviewed.
2026-10-19security-guidance: do not review against a baseline from another checkoutmhegazy/sg-stop-baseline-checkoutMohamed Hegazy
The turn baseline (stash SHA, HEAD, untracked snapshot) is kept per session, and the Stop review used it in whatever checkout the turn ended in. After the session entered another worktree, that worktree's older commits looked like commits made this turn and its files were diffed against the first checkout's, so code committed long before was reviewed and reported again (anthropics/claude-code#102567). The prompt hook now stores the repo root and the prompt time beside the baseline. When the Stop review runs in a different checkout it leaves the baseline out and uses what that checkout can say for itself: its own HEAD when the turn began (from its reflog) for the commit range, HEAD for file contents, and file times to leave out uncommitted files last written before the turn. A baseline taken after a finding records the checkout it was taken in. A prompt in a folder that is not a repo no longer replaces the untracked snapshot of the kept baseline with an empty one, which made every untracked file in the repo look new at the next Stop. Stop rows carry `bl_origin`: 0 same checkout, 1 another worktree, 2 another repository, 3 a folder that is gone, 4 no baseline; plus 10 or 20 when the baseline is an earlier turn's.
2026-10-19Merge branch 'mhegazy/sg-reviewer-managed-mcp' into mhegazy/sg-gateway-loginClaude
2026-10-19Merge remote-tracking branch 'origin/mhegazy/sg-no-credentials-notice' into ↵Claude
mhegazy/sg-gateway-login
2026-10-19security-guidance: run reviews on machines with a managed MCP configmhegazy/sg-reviewer-managed-mcpMohamed Hegazy
Since 2.0.14 the plugin starts the reviewing Claude Code with --strict-mcp-config. Claude Code exits at startup with that flag on a machine whose administrator delivers the MCP servers (managed-mcp.json), so the agentic commit review always fell back to the single-shot review, and reviews that only run through Claude Code (Bedrock, Vertex) failed. When the inner CLI refuses the flag, the plugin now starts it once more without it, and leaves it out for the rest of the hook process. Those starts deny every MCP tool (--disallowedTools "mcp__*") instead, so the reviewer still gets only its read tools. Review rows from such a process carry strict_mcp_off: 1.
2026-10-19security-guidance: count secret-named data files in the Stop review setmhegazy/sg-secret-named-telemetryMohamed Hegazy
Data files named like secrets.yml or client_secret.json are reviewed like any other file. The Stop hook now reports how many are in its review set, as a count only (secret_named_reviewed, emitted when nonzero), so the share of reviews that include one can be read from telemetry. No change to what is reviewed. Refs anthropics/claude-code#96276
2026-10-19security-guidance: rebuild an agent SDK install whose package directory was ↵Mohamed Hegazy
emptied The bootstrap called a venv healthy when `import claude_agent_sdk` succeeded. Python imports an empty directory as a namespace package, so an install that had lost its files passed, the reviewer's `from claude_agent_sdk import ...` failed on every commit, and the agentic review fell back until the venv was deleted by hand. The probe now also requires the package to have a __file__, for the venv and for the --target fallback. A venv that fails it takes the rebuild path that was already there. sdk_venv_emptied counts the sessions that found the venv in that state.
2026-10-19security-guidance: do not install the agent SDK for reviews that are offMohamed Hegazy
The SessionStart bootstrap and its PostToolUse rescue built a venv of a few hundred MB for the agent SDK whatever the environment said, including under SECURITY_GUIDANCE_DISABLE=1, and the rescue started the bootstrap again every five minutes on machines whose SDK lives in that venv (#5331). - Nothing is installed when the environment turns off every review that loads the SDK: the kill switch, ENABLE_CODE_SECURITY_REVIEW=0, or ENABLE_STOP_REVIEW=0 with ENABLE_COMMIT_REVIEW=0. Reported as sdk_bootstrap 10. A disabled plugin also no longer shows the "reviewer unavailable" notice on a Python below 3.10. - The rescue leaves a finished install under the state dir alone instead of starting the bootstrap for it every five minutes. - New counts on the bootstrap's metrics row, set only when true and only when the install exists: sdk_no_creds and sdk_no_git (the session cannot run the reviews the install serves), sdk_venv_py (the venv was built by another Python version than the one running the hooks, #5706). They size follow-up changes; no behaviour depends on them. With the reviews on, what is built and when is unchanged.
2026-10-19security-guidance: do not save review runs as session transcriptsMohamed Hegazy
The agentic commit reviewer and reviews on 3rd-party providers run an inner Claude Code through the Agent SDK, which saved each run as a session transcript holding the review prompt and diff. Start it with --no-session-persistence; SECURITY_GUIDANCE_PERSIST_SESSIONS=1 keeps the transcripts. An inner CLI that predates the flag is run again without it.
2026-10-19security-guidance: say when the LLM reviews can't runmhegazy/sg-no-credentials-noticeMohamed Hegazy
With no credentials in the hook's environment every Stop, commit and push review is skipped, and nothing told the user. That is the state of a signed-in session started with CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC, DISABLE_TELEMETRY or DO_NOT_TRACK set, where Claude Code does not pass the sign-in to plugin hooks. Show a notice on an edit in a git repo, at most once a week, naming the setting when one is set. Document where the reviews get credentials, and report no_creds on the skipped reviews.
2026-10-19security-guidance: report how Stop reviews relate to the session's own editsMohamed Hegazy
The Stop review takes its file list from git state, so it can cover files the session's edit tools never wrote. Add one count-only metric, review_scope, to Stop rows: whether the edit-tool paths lie inside the reviewed repo, how many reviewed files no edit tool wrote, and whether the turn-start snapshot was a real one. No change to what is reviewed. Refs #4524
2026-10-19security-guidance: find a rewritten file's earlier version from a repo ↵Mohamed Hegazy
subdirectory A full-file Write is checked against the file as it was at the start of the turn, so risky calls that were already there are not reported as new. The lookup passed git a path relative to the session directory, which git reads from the repo root, so it failed for any session started below the root, and on Windows for any path with a separator. Ask for ./<path> with forward slashes. Fixes #5684
2026-10-19security-guidance: report which pattern rules fired on every Stop rowMohamed Hegazy
The Stop sweep reported only which rules were still matching, and only on skipped-review rows. Add warn_fired_mask and put both masks on every Stop row, so each rule's fired and still-matching counts can be read. Keep a user rule apart from a built-in rule of the same name in the sweep.
2026-10-19security-guidance: report how long the launcher waits for interpreter probesMohamed Hegazy
sg-python.sh asks each candidate interpreter for its version before running a hook, and waits as long as that takes. Nothing recorded how long. The launcher now times each probe with bash builtins (no extra process) and passes the result to the hook, which reports two keys when the probes of one launch took a second or more together: - launcher_probe_ms: all probes of this launch - launcher_probe_max_ms: the slowest one The keys go last on a row, so they never displace an existing key. Measurement only: the launcher still waits for every probe and picks the same interpreter.
2026-10-19security-guidance: find Python releases newer than the launcher's listmhegazy/sg-launcher-newer-pythonMohamed Hegazy
sg-python.sh prefers the versioned names python3.13 to python3.10, then python3 / python / py -3 when they are 3.10 or newer. A machine whose `python3` is older (stock macOS: 3.9) and whose only newer interpreter is python3.14 ended up on 3.9, which cannot load the agent SDK, so the commit reviewer was off with no sign that an installed Python had been missed (#4907, #5024). - When none of the existing candidates is 3.10 or newer, try python3.14 to python3.19, oldest first, before settling for an older Python. - An interpreter that is picked today is still picked: the newer names are only reached where the launcher used to fall back to a Python below 3.10 or find none. Names not on PATH cost no process.
2026-10-19security-guidance: bump version to 2.0.15mhegazy/sg-bump-2.0.15Mohamed Hegazy
2026-10-19security-guidance: read the Stop review's git diff without holding it wholeMohamed Hegazy
The Stop review captured the whole diff of the turn before its per-file caps applied, so a turn that wrote large text files cost the hook several times their size in memory. The output is now read as it arrives: files the review drops keep only their header line, and one file's diff is cut at 4 MiB (SG_MAX_FILE_DIFF_BYTES). The git command is unchanged. Adds count-only metrics, nonzero only: diff_mb, diff_cut_files, diff_timeout.
2026-10-18security-guidance: keep secret renames out and report the right skip when ↵Mohamed Hegazy
paths do not fit one command When the changed paths are too long for one git command: - secret-shaped paths gone from the work tree go into every batch, so a rename away from such a name is still paired and its content stays out of the review - the batch size follows the system's own argument limit when it is lower - giving up is reported as skip 8 and a set with no source files as skip 7, instead of 6 (no changes) MAX_REVIEW_SET_PATHS counts only reviewable paths, read from the repo root, so an unignored dependency directory does not hide an edited source file.
2026-10-18Merge remote-tracking branch 'origin/main' into mhegazy/sg-stop-pathspecMohamed Hegazy
2026-10-17security-guidance: run pattern checks on NotebookEdit cellsmhegazy/sg-notebook-edit-patternsMohamed Hegazy
The edit hook is registered for NotebookEdit but read no content from it, so a cell edit never produced a pattern warning. Check the cell's new source, and check a saved notebook by its cell sources so JSON escapes no longer hide code from the rules. Refs #6718
2026-10-16security-guidance: skip an unusable security-patterns file on its ownmhegazy/sg-patterns-file-shapeMohamed Hegazy
A security-patterns file that parsed to a list or a scalar, was not UTF-8, or held a non-list patterns value raised inside the loader, and every user rule from every location was dropped with only a debug-log line. Each file is now read on its own: an unusable one is skipped and logged, and the rules from the other locations still load. Refs anthropics/claude-code#87627
2026-10-16security-guidance: keep Claude Code's own credential files out of reviewsmhegazy/sg-claude-code-credential-filesMohamed Hegazy
When the Claude Code config directory is a git repo, .credentials.json and .claude.json show up as changed files each time Claude Code rewrites them, and their contents (sign-in tokens, a saved API key, MCP server secrets) were sent to the Stop review. Treat both names as secret-shaped, like .netrc and .npmrc. Refs anthropics/claude-code#90010
2026-10-15Merge pull request #6380 from anthropics/mhegazy/sg-bump-2.0.12Mohamed Hegazy
security-guidance: bump version to 2.0.14
2026-10-15Merge pull request #6588 from anthropics/mhegazy/sg-inflight-reviewsMohamed Hegazy
security-guidance: do not review a commit twice while its first review is running
2026-10-15Merge pull request #6589 from anthropics/mhegazy/sg-review-cost-logMohamed Hegazy
security-guidance: log each review's token use and estimated cost
2026-10-15Merge pull request #6538 from ↵Mohamed Hegazy
anthropics/mhegazy/sg-launcher-unreadable-plugin-dir security-guidance: never run a hook with a Python that cannot read it
2026-10-15security-guidance: log each review's token use and estimated costmhegazy/sg-review-cost-logMohamed Hegazy
The plugin computed a review's usage but kept it only in its metrics. Each review now writes one line to the plugin's debug log with the kind of review, the Claude Code session, model, tokens and estimated cost.
2026-10-15security-guidance: do not review a commit twice while its first review is ↵mhegazy/sg-inflight-reviewsMohamed Hegazy
running A commit review records its commits only once it has a verdict. A push (or the next commit's reflog scan) that started before then reviewed the same diff again. A running review now holds a lock file per commit in the git dir; a push review waits for it and skips what it recorded, and the reflog scan leaves those commits to it.
2026-10-15Merge remote-tracking branch 'origin/main' into ↵mhegazy/sg-launcher-unreadable-plugin-dirClaude
mhegazy/sg-launcher-unreadable-plugin-dir # Conflicts: # plugins/security-guidance/hooks/security_reminder_hook.py
2026-10-15security-guidance: start fewer processes in the hook launcherMohamed Hegazy
sg-python.sh runs on every hook, and under Git Bash each command substitution is a new Windows process, whether or not the interpreter it probes exists (#6470). On a machine with only `python` it started 13 processes before the hook; it now starts 1. - Skip interpreter names that are not on PATH (a builtin lookup) before probing them. - The probe execs the interpreter in its subshell instead of forking again from it. - Remember the first Python below 3.10 seen in pass 2 instead of probing the same names a second time in pass 3. - Convert drive paths (/c/Users/...) to Windows form in-shell under Git Bash / MSYS2; mount points and Cygwin still go through cygpath. Interpreter order and the choice made are unchanged.
2026-10-15security-guidance: report launcher fallback and give-up as metricsMohamed Hegazy
Two count-only metrics, emitted only when nonzero, so the launcher change can be checked in the field: - launcher_fallback: the hook ran, but only because the launcher started the interpreter by its real path (the names on PATH could not read the plugin files). Added to the hook's and the SessionStart bootstrap's existing metrics. - launcher_unreadable: no interpreter could read the hook script. No Python runs in that case, so the launcher prints the metrics line itself before exiting 1.
2026-10-15security-guidance: never run a hook with a Python that cannot read itMohamed Hegazy
On Windows, python/python3/py can be packaged launcher aliases (Microsoft Store Python, Python Install Manager). Started through the alias, the interpreter answers `-c` but has a different view of %APPDATA% and cannot see a plugin staged there. sg-python.sh picked it, CPython failed with "can't open file ... [Errno 2]" and exit code 2, and exit 2 from the asyncRewake Stop hook was delivered to the model as review findings. The model's reply ran the Stop hook again, so the session looped without ever reviewing anything (#6251, #5781). The launcher's probe now also checks that the interpreter can read the hook script. When no name on PATH qualifies, it tries the other python3/python entries on PATH by full path and the real executable each alias reports. If nothing can read the script it says so and exits 1, so a launch failure is never reported as findings.
2026-10-15Merge pull request #6593 from anthropics/mhegazy/sg-reviewer-context-telemetryMohamed Hegazy
security-guidance: report commit reviewer context in review telemetry
2026-10-15Merge remote-tracking branch 'origin/main' into mhegazy/sg-no-credentials-noticeClaude
# Conflicts: # plugins/security-guidance/hooks/security_reminder_hook.py
2026-10-15Merge pull request #6625 from anthropics/mhegazy/sg-reviewer-read-only-toolsMohamed Hegazy
security-guidance: give the commit reviewer only read tools
2026-10-15Merge pull request #6590 from anthropics/mhegazy/sg-diff-prefix-configMohamed Hegazy
security-guidance: read diffs the same whatever the user's prefix settings
2026-10-15Merge pull request #6605 from anthropics/mhegazy/sg-state-file-saveMohamed Hegazy
security-guidance: keep the session state when a save is cut short
2026-10-15Merge pull request #6617 from anthropics/mhegazy/sg-skip-untracked-listingMohamed Hegazy
security-guidance: skip the untracked-file listing when the Stop review is off
2026-10-15Merge pull request #6616 from anthropics/mhegazy/sg-user-config-dirMohamed Hegazy
security-guidance: find user-level policy files under CLAUDE_CONFIG_DIR
2026-10-15Merge pull request #6540 from anthropics/mhegazy/sg-portable-hook-outputMohamed Hegazy
security-guidance: leave Claude Code only fields out of hook output on other hosts
2026-10-15Merge pull request #6618 from anthropics/mhegazy/sg-portable-session-startmhegazy/sg-portable-hook-outputMohamed Hegazy
security-guidance: print one JSON document from the SessionStart hook on other hosts
2026-10-15Merge remote-tracking branch 'origin/main' into ↵mhegazy/sg-skip-untracked-listingMohamed Hegazy
mhegazy/sg-skip-untracked-listing
2026-10-15Merge remote-tracking branch 'origin/main' into mhegazy/sg-state-file-savemhegazy/sg-state-file-saveMohamed Hegazy
2026-10-15Merge remote-tracking branch 'origin/main' into mhegazy/sg-diff-prefix-configmhegazy/sg-diff-prefix-configMohamed Hegazy
2026-10-15Merge remote-tracking branch 'origin/main' into mhegazy/sg-user-config-dirmhegazy/sg-user-config-dirClaude