summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorClaude <noreply@anthropic.com>2026-11-09 23:13:55 +0000
committerClaude <noreply@anthropic.com>2026-11-09 23:13:55 +0000
commitde3593da190f7de5ca465432219ef44bfa9c9fa3 (patch)
tree19cfc3afd49a730dac32ae9c492ab022810a3946 /plugins
parent0412be76f50ab4f4f8abff3753efa9269fbbca5b (diff)
security-guidance: find Claude Code for the gateway sign-in check on Windows
In a session signed in to a Claude apps gateway the check only knew macOS and Linux paths, so Windows reviews were skipped unless SG_AGENTIC_CLI_PATH was set. Look at the native installer's claude.exe too. Co-authored-by: mhegazy <mhegazy@anthropic.com>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/security-guidance/README.md4
-rw-r--r--plugins/security-guidance/hooks/llm.py8
-rw-r--r--plugins/security-guidance/tests/test_gateway_sign_in.py61
3 files changed, 70 insertions, 3 deletions
diff --git a/plugins/security-guidance/README.md b/plugins/security-guidance/README.md
index e0c4a888..73329b72 100644
--- a/plugins/security-guidance/README.md
+++ b/plugins/security-guidance/README.md
@@ -55,7 +55,7 @@ The pattern warnings need no credentials. The LLM reviews (the diff review on St
- **A cloud provider (Bedrock, Vertex, Foundry)** — if Claude Code is configured for one, reviews run through Claude Code with that provider config.
- **`ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN` in the environment** — used as is, against `ANTHROPIC_BASE_URL` if you set one.
- **Signed in to Claude Code (`/login`)** — Claude Code passes your sign-in to the plugin's hooks, and reviews use that account.
-- **Signed in to a Claude apps gateway (`/login`)** — Claude Code passes no sign-in to plugins on a gateway, so reviews run through your installed Claude Code, which uses its own stored sign-in. The plugin never reads it. The plugin looks for Claude Code at `~/.local/bin/claude`, where the native installer puts it on macOS and Linux; on Windows, or for any other install, set `SG_AGENTIC_CLI_PATH` to its full path.
+- **Signed in to a Claude apps gateway (`/login`)** — Claude Code passes no sign-in to plugins on a gateway, so reviews run through your installed Claude Code, which uses its own stored sign-in. The plugin never reads it. The plugin looks for Claude Code where the native installer puts it: `~/.local/bin/claude` on macOS and Linux, `~\.local\bin\claude.exe` on Windows. For any other install, set `SG_AGENTIC_CLI_PATH` to its full path.
Claude Code does not pass your sign-in to plugins in a session started with `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`, `DISABLE_TELEMETRY`, or `DO_NOT_TRACK` set. If no credentials reach the plugin, for that or any other reason, and the plugin cannot review through a Claude apps gateway sign-in, the LLM reviews are skipped and only the pattern warnings run. The plugin tells you so when Claude edits a file in a git repo, at most once a week. Set `ENABLE_CODE_SECURITY_REVIEW=0` if that is what you want; it also hides the notice.
@@ -150,7 +150,7 @@ This is a best-effort assistive tool, not a guarantee. Treat findings as suggest
**Looking into one commit review** — set `SECURITY_GUIDANCE_PERSIST_SESSIONS=1` before the run; the reviewer's prompt, tool calls and answer are then kept as session transcripts under `~/.claude/projects/`.
-**Review never finds anything** — verify your API path works, and that credentials reach the plugin (see [Credentials](#credentials)): `~/.claude/security/log.txt` says `no API credentials` when they don't. When a commit or push review gets no usable answer from the model, Claude is told once per session for each kind of review and failure (for example "Commit security review did not complete: …"), and the reason is logged. If a commit whose review failed is pushed later from Claude Code, the push review checks it. On 3P providers, if you set `SECURITY_REVIEW_MODEL`, check it is a provider-specific id your account can invoke. On LLM gateways, check the gateway's logs for `POST /v1/messages` traffic from the plugin. In a session signed in to a Claude apps gateway with `/login`, reviews run only when `claude auth status` shows the gateway and that you are logged in. They run through the Claude Code at `~/.local/bin/claude`, where the native installer puts it on macOS and Linux. On Windows, or for any other install, set `SG_AGENTIC_CLI_PATH` to its full path.
+**Review never finds anything** — verify your API path works, and that credentials reach the plugin (see [Credentials](#credentials)): `~/.claude/security/log.txt` says `no API credentials` when they don't. When a commit or push review gets no usable answer from the model, Claude is told once per session for each kind of review and failure (for example "Commit security review did not complete: …"), and the reason is logged. If a commit whose review failed is pushed later from Claude Code, the push review checks it. On 3P providers, if you set `SECURITY_REVIEW_MODEL`, check it is a provider-specific id your account can invoke. On LLM gateways, check the gateway's logs for `POST /v1/messages` traffic from the plugin. In a session signed in to a Claude apps gateway with `/login`, reviews run only when `claude auth status` shows the gateway and that you are logged in. They run through the Claude Code at `~/.local/bin/claude`, where the native installer puts it on macOS and Linux, or on Windows at `~\.local\bin\claude.exe`. For any other install, set `SG_AGENTIC_CLI_PATH` to its full path.
**Too many false positives** — set `SECURITY_REVIEW_MODEL` to a cheaper model (`claude-sonnet-5-5`) and re-evaluate; if precision is the priority, stay on the default.
diff --git a/plugins/security-guidance/hooks/llm.py b/plugins/security-guidance/hooks/llm.py
index ee9ad2be..5dd6eb4e 100644
--- a/plugins/security-guidance/hooks/llm.py
+++ b/plugins/security-guidance/hooks/llm.py
@@ -962,7 +962,13 @@ def gateway_review_cli(session_id) -> Optional[str]:
global _gateway_cli, _gateway_check_unanswered
if _gateway_cli is not None:
return _gateway_cli or None
- cli = _user_cli_path() or ""
+ cli = _user_cli_path()
+ if cli is None and _WINDOWS:
+ # The native installer's fixed path, as on macOS and Linux. Not PATH:
+ # this check starts the program with no user action.
+ native = os.path.join(os.path.expanduser("~"), ".local", "bin", "claude.exe")
+ cli = native if os.path.isfile(native) else None
+ cli = cli or ""
ok = None
# No skip for CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC, as on Bedrock and Vertex:
# the gateway docs suggest setting it, and the review goes through the
diff --git a/plugins/security-guidance/tests/test_gateway_sign_in.py b/plugins/security-guidance/tests/test_gateway_sign_in.py
index 7b6e9fc4..0ff6d221 100644
--- a/plugins/security-guidance/tests/test_gateway_sign_in.py
+++ b/plugins/security-guidance/tests/test_gateway_sign_in.py
@@ -102,6 +102,52 @@ class TestGatewaySignInCheck:
monkeypatch.setattr(llm, "_user_cli_path", lambda: None)
assert llm.can_review("s1") is False
+ @pytest.fixture
+ def windows_home(self, no_credential, monkeypatch, tmp_path):
+ """Windows path choices, with `~\\.local\\bin` in an empty home folder."""
+ monkeypatch.delenv("SG_AGENTIC_CLI_PATH")
+ monkeypatch.setattr(llm, "_WINDOWS", True)
+ home = tmp_path / "home"
+ monkeypatch.setenv("HOME", str(home))
+ monkeypatch.setenv("USERPROFILE", str(home))
+ bin_dir = home / ".local" / "bin"
+ bin_dir.mkdir(parents=True)
+ return bin_dir
+
+ @staticmethod
+ def _claude_exe(folder):
+ # write_cli adds .exe to the name on Windows only.
+ return make_cli(folder, SIGNED_IN, name="claude" if os.name == "nt" else "claude.exe")
+
+ def test_windows_finds_the_installed_claude_exe(self, windows_home):
+ cli, calls = self._claude_exe(windows_home)
+ assert llm.gateway_review_cli("s1") == str(cli)
+ assert len(calls_of(calls)) == 1
+
+ def test_windows_with_no_claude_exe_means_no_review(self, windows_home):
+ assert llm.can_review("s1") is False
+
+ def test_windows_does_not_search_path(self, windows_home, monkeypatch, tmp_path):
+ on_path = tmp_path / "on-path"
+ on_path.mkdir()
+ _, calls = self._claude_exe(on_path)
+ monkeypatch.setenv("PATH", str(on_path))
+ assert llm.can_review("s1") is False
+ assert calls_of(calls) == []
+
+ def test_windows_lookup_leaves_a_named_cli_alone(self, windows_home, monkeypatch):
+ _, calls = self._claude_exe(windows_home)
+ monkeypatch.setenv("SG_AGENTIC_CLI_PATH", "")
+ assert llm.can_review("s1") is False
+ assert calls_of(calls) == []
+
+ def test_windows_lookup_is_windows_only(self, windows_home, monkeypatch):
+ _, calls = self._claude_exe(windows_home)
+ monkeypatch.setattr(llm, "_WINDOWS", False)
+ monkeypatch.setattr(llm, "_user_cli_path", lambda: None)
+ assert llm.can_review("s1") is False
+ assert calls_of(calls) == []
+
def test_relative_cli_path_is_not_run(self, no_credential, monkeypatch, tmp_path):
cli, calls = make_cli(tmp_path, SIGNED_IN)
monkeypatch.chdir(tmp_path)
@@ -274,6 +320,21 @@ def test_timed_out_review_logs_what_the_cli_retried(no_credential, monkeypatch,
assert llm._gateway_review_timed_out is False
+@pytest.mark.skipif(os.name != "nt", reason="the claude.exe lookup is Windows only")
+def test_hook_on_windows_asks_the_installed_claude_exe(hook_env, tmp_path, workspace):
+ home = tmp_path / "home"
+ bin_dir = home / ".local" / "bin"
+ bin_dir.mkdir(parents=True)
+ _, calls = make_cli(bin_dir, SIGNED_IN)
+ env = {k: v for k, v in without_credential(hook_env).items()
+ if k not in ("SG_AGENTIC_CLI_PATH", "CLAUDE_CODE_EXECPATH")}
+ env.update({"USERPROFILE": str(home), "HOME": str(home)})
+ _, repo = workspace
+ _, out = commit_file(repo, "app.py", VULN_PY)
+ run_hook(bash_payload(repo, "git commit -m change", out), env)
+ assert calls_of(calls)[0].startswith("auth status --json")
+
+
def without_credential(hook_env):
return {k: v for k, v in hook_env.items()
if k not in ("ANTHROPIC_API_KEY", "SECURITY_REVIEW_MODEL",