# Security Gates for Agent-Written Code: Semgrep, Gitleaks, TruffleHog, Snyk and Claude Security Review

URL: https://developertoolkit.ai/en/ecosystem/observability/agent-security-gates/
Description: Stop secrets and vulnerable code in agent commits: a Gitleaks pre-commit hook, Semgrep and TruffleHog in CI, and Claude security review on every pull request.

Security gates for agent-written code are deterministic scanners and review agents placed at four points: inside the agent session, at `git commit`, in CI, and on the pull request. Gitleaks and TruffleHog stop secrets, Semgrep and Snyk find vulnerable code and dependencies, and Claude's security review adds a model's judgement. Only CI can be made mandatory for every contributor.

Your agent wires up Stripe checkout in 12 minutes, the tests pass, and the diff contains `new Stripe("sk_live_…")` because the key was in the `.env` file it read for context. Nobody reads line 40 of a 600-line diff, and the agent commits every few minutes. This page is for developers who want the agent to be stopped before a secret or an injection reaches `main`, and for tech leads who need that stop to hold for eight people and three different agents.

## What you'll set up with these security gates

- **A Gitleaks pre-commit hook** that blocks an agent's commit containing a secret.
- **A four-layer workflow** with the tool for each layer in Claude Code, Codex and Cursor.
- **Two tested Claude Code hooks**: one scans every written file, one stops the agent skipping commit hooks.
- **CI workflows** for TruffleHog, Semgrep and a hardened `claude-code-security-review`.
- **Three copy-paste prompts**, the metrics that prove the gates work, and the traps.

This page covers the scanners. The review bots that read a diff for logic bugs are compared in [AI code review bots](/en/ecosystem/observability/ai-code-review-bots/); the procedure a human follows on an agent's pull request is in [reviewing an agent's pull request](/en/workflows/ship/agent-pr-review/).

## Which security gate catches what?

Every tool below was checked on 2026-09-26 against its own README, the npm or PyPI registry, Anthropic's plugin marketplace file, or the installed CLIs (Claude Code 2.1.283, Codex CLI 0.157.1).

| Layer | Tool | Catches | Runs where | Can it block? | Cost |
| ----- | ---- | ------- | ---------- | ------------- | ---- |
| 1. In session | `security-guidance` plugin (Anthropic) | ~25 dangerous patterns on edit; LLM diff review at end of turn; agentic review on `git commit` | Claude Code hooks | Feeds findings back to Claude; you can switch it off | Model tokens per review |
| 1. In session | Semgrep Guardian (plugin: MCP server, hooks, skills) | Code, Supply Chain and Secrets findings on every file the agent writes | Claude Code, Cursor; `semgrep mcp` in any MCP client | Prompts the agent to regenerate until clean | Free CLI; Pro rules need `semgrep login` |
| 1. In session | `/security-review` (built into Claude Code) | Injection, auth and data-exposure risks in the branch diff | Your session | No, it reports | Normal usage |
| 2. Commit | Gitleaks pre-commit hook | Hardcoded secrets in staged changes | Your machine, any agent | Yes, unless skipped | Free |
| 3. CI | TruffleHog | Secrets, verified live against the issuer | GitHub Actions or any CI | Yes, `--fail` exits 183 | Free |
| 3. CI | Semgrep | Vulnerable code patterns, new findings only | Any CI | Yes, `--error` exits 1 | Free CLI |
| 3. CI | Snyk MCP and CLI; SonarQube MCP | Vulnerable dependencies and code; quality gates | Agent session and CI | Through your Snyk or SonarQube gate | Vendor plan |
| 4. Pull request | `anthropics/claude-code-security-review` | Semantic vulnerabilities, with false-positive filtering | GitHub Actions | Only through a check you build | API tokens |
| Tooling | Snyk Agent Scan | Prompt injection and tool poisoning in MCP configs and skills | Your machine or CI | `--ci` exits non-zero | Snyk token |

The split that matters: layers 1 and 2 run on the developer's machine, where the agent or the developer can turn them off. Layer 3 runs where nobody can, so it is the only one you make a required check. Layers 1 and 2 exist to make layer 3 boring.

Popularity on 2026-09-26: `gitleaks/gitleaks` had 29.5k GitHub stars, `trufflesecurity/trufflehog` 28.1k and `semgrep/semgrep` 16.8k; in Anthropic's plugin directory (claude.com/plugins), `security-guidance` showed 241,800 installs. Stars and installs measure attention, not detection quality.

## Example: a Gitleaks pre-commit hook stops an agent's commit

This is the smallest gate with the largest payoff, and it works for every agent, because every agent commits through `git`.

1. Install Gitleaks and the `pre-commit` framework (PyPI `pre-commit` 4.6.2 on 2026-09-26):

   ```bash
   # Terminal
   brew install gitleaks
   pipx install pre-commit
   ```

2. Add `.pre-commit-config.yaml` at the repository root. The `rev` below is the one Gitleaks' README pins; `pre-commit autoupdate` moves it to the latest release.

   ```yaml
   repos:
     - repo: https://github.com/gitleaks/gitleaks
       rev: v8.24.2
       hooks:
         - id: gitleaks
   ```

   The `gitleaks` hook runs `gitleaks git --pre-commit --redact --staged --verbose`, so it scans only what is staged and never prints the secret. If Gitleaks is already installed through Homebrew, the `gitleaks-system` hook ID uses that binary instead of building one.

3. Install the hook and pin it to the latest release:

   ```bash
   pre-commit autoupdate
   pre-commit install
   ```

   `pre-commit install` writes `.git/hooks/pre-commit`, which is per clone. Every developer runs it once, and every new worktree shares it through the common `.git` directory.

4. Let the agent commit. When the staged diff contains a live Stripe key, the commit fails and the agent reads this in its shell output (the finding block is real Gitleaks 8.24.2 output):

   ```text
   Detect hardcoded secrets.................................................Failed
   - hook id: gitleaks
   - exit code: 1

   Finding:     ...tripe = new Stripe("REDACTED");
   Secret:      REDACTED
   RuleID:      stripe-access-token
   Entropy:     5.280395
   File:        src/billing.ts
   Line:        1
   Fingerprint: src/billing.ts:stripe-access-token:1
   ```

5. Check what the agent does next. The right recovery is to replace the literal with `process.env.STRIPE_SECRET_KEY`, unstage, and commit again. The wrong recoveries are `git commit --no-verify`, `SKIP=gitleaks git commit`, or a `#gitleaks:allow` comment, all of which Gitleaks documents. The second Claude Code hook in the next section denies the first two; the CI layer catches the first two, and a `#gitleaks:allow` comment too when TruffleHog can verify the key or when you add Gitleaks to CI with `--ignore-gitleaks-allow` (Layer 3).

6. Rotate the key anyway. The secret was in a file the agent read, so it was in the model's context and in the session transcript. A blocked commit means it did not reach Git history, not that it stayed private.

## Build the four-layer security workflow

Each layer is cheaper than the next and catches what the previous one missed:

1. **Hook, in the session.** Each written file is scanned and findings go back to the agent before the turn ends.
2. **Pre-commit, on the machine.** Gitleaks blocks the commit, whichever agent, IDE or human made it.
3. **CI, on every push and pull request.** TruffleHog and Semgrep run where no agent can skip them. This is the required check.
4. **Security review, on the pull request.** A model reads the diff for flaws no pattern matches, such as an authorization check on the wrong object, and a human on your escalation list reads its findings.

### Layer 1: scan inside the agent session

The in-session layer differs most between the tools, so pick your tab.

**Claude Code**

    **Anthropic's `security-guidance` plugin** runs three layers as hooks: regex warnings on `Edit` and `Write` for about 25 dangerous patterns (`yaml.load`, `pickle.load`, raw `innerHTML`, hardcoded secrets), an LLM review of the diff when Claude finishes a turn, and an agentic reviewer on `git commit` that reads related files to trace data flow. It needs Claude Code 2.1.144 or later and Python 3.8 or later.

    ```bash
    # Terminal
    claude plugin install security-guidance@claude-plugins-official
    ```

    Put rules your codebase needs in `.claude/claude-security-guidance.md` and commit it. The combined user, project and local files have an 8 KB budget, and the commit reviewer does not read them. In multi-agent setups that share one worktree, set `ENABLE_STOP_REVIEW=0`, because another agent can move `HEAD` between turns.

    **Semgrep Guardian** bundles the Semgrep MCP server, hooks and skills, and rescans every file the agent writes with Semgrep Code, Supply Chain and Secrets:

    ```text
    # Inside Claude Code
    /plugin install semgrep@claude-plugins-official
    /setup-semgrep-plugin
    ```

    `/setup-semgrep-plugin` also installs the Semgrep CLI. Before you push, run `/security-review`, which reviews the diff between your branch and the default branch on `origin`.

    **Two hooks of your own.** The first scans each written file with Gitleaks, so the agent hears about a secret seconds after writing it rather than at commit time. Save it as `.claude/hooks/scan-secrets.sh` and make it executable:

    ```bash
    #!/usr/bin/env bash
    # .claude/hooks/scan-secrets.sh (PostToolUse, matcher "Edit|Write")
    set -uo pipefail
    command -v gitleaks >/dev/null || { echo "gitleaks not installed; secret scan skipped" >&2; exit 0; }
    file=$(jq -r '.tool_input.file_path // empty')
    [ -z "$file" ] || [ ! -f "$file" ] && exit 0

    if ! out=$(gitleaks dir "$file" --redact --no-banner --verbose 2>&1); then
      echo "Gitleaks found a hardcoded secret in $file:" >&2
      echo "$out" | grep -E '^(RuleID|Line):' >&2
      echo "Remove the literal. Read the value from an environment variable instead, and do not add gitleaks:allow." >&2
      exit 2
    fi
    exit 0
    ```

    Exit code 2 puts the message in front of Claude, which fixes the file on its next step. The second hook denies the commands that skip the pre-commit layer. Save it as `.claude/hooks/guard-commit.sh`:

    ```bash
    #!/usr/bin/env bash
    # .claude/hooks/guard-commit.sh (PreToolUse, matcher "Bash")
    set -uo pipefail
    cmd=$(jq -r '.tool_input.command // empty')

    deny() {
      jq -nc --arg r "$1" '{hookSpecificOutput: {hookEventName: "PreToolUse",
        permissionDecision: "deny", permissionDecisionReason: $r}}'
      exit 0
    }

    [[ $cmd =~ git[[:space:]] ]] || exit 0
    [[ $cmd =~ --no-verify|(^|[[:space:]])-[a-zA-Z]*n[a-zA-Z]*([[:space:]]|$)|SKIP=|core\.hooksPath ]] &&
      [[ $cmd =~ git[[:space:]]+(-c[[:space:]]+[^[:space:]]+[[:space:]]+)*(commit|push|config) ]] &&
      deny "Commit hooks must run. Fix what the hook reported and commit again without --no-verify, -n, SKIP= or a hooksPath override."
    exit 0
    ```

    Tested against eight commands: it denies `git commit --no-verify`, `git commit -nm`, `SKIP=gitleaks git commit`, `git -c core.hooksPath=/dev/null commit`, `git push --no-verify` and `git config core.hooksPath`, and allows `git commit -m "fix n+1 query"` and `git log -n 5`. It can false-positive on a commit message that contains a standalone `-n` word or on a compound command; the agent then rephrases, which is the safe failure direction. Register both in `.claude/settings.json`:

    ```json
    {
      "hooks": {
        "PreToolUse": [
          { "matcher": "Bash",
            "hooks": [{ "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/guard-commit.sh", "args": [] }] }
        ],
        "PostToolUse": [
          { "matcher": "Edit|Write",
            "hooks": [{ "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/scan-secrets.sh", "args": [], "timeout": 30 }] }
        ]
      }
    }
    ```

    The hook format and the deny semantics are covered in [Claude Code hooks for automation](/en/claude-code/automate/hooks-automation/).

**Codex**

    **Semgrep as an MCP server.** The server ships inside the `semgrep` binary (PyPI 1.178.0 on 2026-09-26); the old `semgrep/mcp` repository is archived.

    ```bash
    # Terminal
    brew install semgrep
    codex mcp add semgrep -- semgrep mcp
    ```

    Then ask Codex to scan what it changed.

    **Snyk as an MCP server.** The Official MCP Registry lists `io.snyk/mcp` as the npm package `snyk` with the arguments `mcp -t stdio`. Authenticate the CLI once with `snyk auth`, then pin the version you tested:

    ```bash
    codex mcp add snyk -- npx -y snyk@1.1307.4 mcp -t stdio
    ```

    **A security pass before you push.** `codex review` takes either custom instructions or a target such as `--base main`, not both (Codex CLI 0.157.1). For a security pass, give the instructions and name the base in them:

    ```bash
    codex review "Security pass only: review the changes on this branch against main for injection, missing authorization, hardcoded secrets, SSRF, path traversal, unsafe deserialization. Report file:line, severity and the input that triggers it."
    ```

    Codex 0.157.1 also has `PreToolUse` and `PostToolUse` hooks, which need persisted trust before they run. The Gitleaks pre-commit hook covers commits Codex makes without extra wiring. For deeper scanning, see [Codex Security](/en/codex/operate/codex-security/); OpenAI's docs, checked 2026-10-12, also describe `@codex security review` (a research preview) as a pull request comment.

**Cursor**

    **Semgrep Guardian for Cursor.** Semgrep's README (read 2026-09-26) installs it from the Cursor Plugin Marketplace: open **Plugins**, search for "Semgrep", click **Add to Cursor**, then run the setup skill and restart Cursor:

    ```text
    # Cursor agent chat
    /setup-semgrep-plugin
    ```

    **Semgrep or Snyk as plain MCP servers.** Add them to `.cursor/mcp.json` in the repository so the whole team gets the same scanners:

    ```json
    {
      "mcpServers": {
        "semgrep": { "command": "semgrep", "args": ["mcp"] },
        "snyk": { "command": "npx", "args": ["-y", "snyk@1.1307.4", "mcp", "-t", "stdio"] }
      }
    }
    ```

    Cursor also has hooks (JSON over standard input and output) and Bugbot, which Cursor describes as identifying "bugs, security issues, and code quality problems" (cursor.com, checked 2026-10-12; Cursor's hooks page lists events such as `preToolUse`, `beforeShellExecution` and `afterFileEdit`). The Gitleaks pre-commit hook fires on commits the Cursor agent makes, exactly as it does in the terminal. The Cursor-specific settings are in [Cursor security](/en/cursor-ide/operate/security/).

### Layer 2: block the commit on the machine

Layer 2 is the Gitleaks hook from the [example above](#example-a-gitleaks-pre-commit-hook-stops-an-agents-commit); add `pre-commit install` to the repository's setup script so a fresh clone or agent sandbox gets it too.

### Layer 3: scan in CI where no agent can skip it

This workflow runs on every pull request. It holds no secrets, uses a read-only token, and keeps the token out of `.git/config`. Save it as `.github/workflows/security-gates.yml`:

```yaml
name: Security gates
on:
  pull_request:
  push:
    branches: [main]
permissions:
  contents: read
jobs:
  secrets:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
          persist-credentials: false
      - uses: trufflesecurity/trufflehog@main # pin to a release commit SHA
        with:
          extra_args: --results=verified,unknown
  sast:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    container: semgrep/semgrep # pin a version tag or a sha256 digest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
          persist-credentials: false
      - name: Semgrep, new findings only
        env:
          BASE_SHA: ${{ github.event.pull_request.base.sha }}
        run: semgrep scan --config p/default --error --metrics=off --baseline-commit "$BASE_SHA"
```

The TruffleHog action passes `--fail` itself, so a verified live secret turns the job red with exit code 183. `--results=verified,unknown` drops unverified candidates to keep noise down. Semgrep's `--error` exits 1 on findings, and `--baseline-commit` reports only those the pull request introduced. To run Gitleaks in CI as well, `gitleaks git --redact --ignore-gitleaks-allow --log-opts="$BASE_SHA..HEAD"` scans the pull request's commit range and ignores `#gitleaks:allow` comments, so it also catches a suppressed key that TruffleHog cannot verify, such as a revoked or test-format key.

Then mark `secrets` and `sast` as required status checks; a failing job that is not required blocks nothing. One more condition makes the gate one an agent cannot skip: on `pull_request`, GitHub runs this YAML from the pull request's merge ref, so a pull request can edit the workflow and switch its own check off. Add `/.github/` to `CODEOWNERS` with a security owner and turn on required code-owner review in branch protection or a ruleset, so a change to the workflow cannot merge without that person.

### Layer 4: security review on the pull request

`anthropics/claude-code-security-review` runs Claude Code over the pull request's diff and posts findings as review comments. Its README says it "is not hardened against prompt injection attacks and should only be used to review trusted PRs". The workflow below, adapted from that README, adds four protections: it skips pull requests from forks, keeps the token out of `.git/config`, removes the pull request's own agent configuration before Claude Code starts, and sets the model explicitly:

```yaml
name: Security review
on:
  pull_request:
permissions:
  contents: read
  pull-requests: write
jobs:
  security:
    if: github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          fetch-depth: 2
          persist-credentials: false
      - name: Drop the pull request's agent config so the reviewer loads none of it
        run: rm -rf .claude .mcp.json CLAUDE.md CLAUDE.local.md
      - uses: anthropics/claude-code-security-review@main # pin to a commit SHA
        with:
          comment-pr: true
          claude-api-key: ${{ secrets.CLAUDE_API_KEY }}
          claude-model: claude-opus-5-5
```

The `rm -rf` step matters because the action runs the `claude` CLI in the checked-out tree while the API key is in the environment as `ANTHROPIC_API_KEY`, so hooks or MCP servers committed in the pull request would run with it. The action reads the diff from the GitHub API, so the review still sees changes to those files. Set `claude-model`: the action's code falls back to `claude-opus-4-1-20250805`, and Anthropic retired Claude Opus 4.1 on the Claude API in 2026. Model choice and prices are on the [models hub](/en/ecosystem/models/).

To gate on the action's `findings-count` output, add a step that fails when it is above zero and mark the job required; otherwise keep it advisory. `run-every-commit: true` reviews every push instead of once per pull request, at a higher cost and, per its README, with more false positives. Denial of service, rate limiting, generic input validation and open redirects are excluded by default; add what your system cares about in the file named by `custom-security-scan-instructions`.

## Scan the agent's own tools with Snyk Agent Scan

The agent itself is attack surface. An MCP server's tool description or a skill's `SKILL.md` can carry instructions the agent obeys. Snyk Agent Scan (formerly `mcp-scan`; PyPI `snyk-agent-scan` 0.6.4 on 2026-09-26) finds the agent harnesses, MCP servers and skills on a machine and scans them for prompt injection, tool poisoning and toxic flows. It needs a Snyk API token and is Python only:

```bash
# Terminal, with SNYK_TOKEN exported from your secret store
uvx snyk-agent-scan@0.6.4 ~/.claude/skills
uvx snyk-agent-scan@0.6.4 ./vendor-skill/SKILL.md
uvx snyk-agent-scan@0.6.4 --ci
```

Run it before you install a marketplace skill or plugin, and on a schedule across the team's machines. `--dangerously-run-mcp-servers` skips the per-server consent prompt and starts every configured stdio server, so use it only where you have checked every command. The wider procedure is in [MCP security](/en/ecosystem/mcp/mcp-security/) and [skill security](/en/ecosystem/skills/skill-security/).

If your organization already gates on **SonarQube**, its official MCP server (the Docker image `sonarsource/sonarqube-mcp`) lets the agent read the quality gate and fix new issues in the session; the setup for Claude Code, Codex and Cursor is in the [server README](https://github.com/SonarSource/sonarqube-mcp-server).

## How much context do the security tools cost?

The `security-guidance` plugin runs as hooks, so it adds nothing to the context window until a finding comes back, but each end-of-turn and commit review costs model tokens. The Semgrep plugin and the Snyk and SonarQube servers add MCP tool definitions, which Claude Code and Codex load through tool search. Measure instead of guessing: `claude plugin details semgrep` prints the plugin's components and projected token cost, and `/context` before and after shows the difference. Pre-commit, CI and the pull-request review cost no session context, which is one more reason to put the mandatory gates there.

## Copy-paste prompts for security gates

**Copy-paste prompt: install the four security gates in this repository**

```text
Set up security gates in this repository in this order, and stop after each
step to show me the diff:

1. Add .pre-commit-config.yaml with the gitleaks hook from
   https://github.com/gitleaks/gitleaks, run `pre-commit autoupdate` and
   `pre-commit install`.
2. Add .github/workflows/security-gates.yml with two jobs on pull_request:
   TruffleHog (trufflesecurity/trufflehog, extra_args
   --results=verified,unknown) and Semgrep in the semgrep/semgrep container
   (semgrep scan --config p/default --error --metrics=off --baseline-commit
   on the PR base SHA). permissions: contents: read only.
   persist-credentials: false on every checkout.
3. Run `gitleaks git --redact --verbose` over the full history and list any
   finding by file, line and rule. Do not print secret values.
4. Add /.github/ to CODEOWNERS with the security owner, then list the
   branch-protection settings I must change to make both jobs required and
   to require code-owner review. Do not change repository settings yourself.
```

**Copy-paste prompt: recover from a blocked commit**

```text
The pre-commit hook blocked the last commit. Read the hook output again.

For each finding:
- Replace the literal with a read from an environment variable and add the
  variable name, without a value, to .env.example.
- If the value is a test fixture, replace it with an obviously fake value
  that does not match the rule.
Never use --no-verify, -n, SKIP=, core.hooksPath, a gitleaks:allow comment or
a .gitleaksignore entry. Re-stage and commit. Then tell me which real
credentials appeared in any file you read this session, so I can rotate them.
```

**Copy-paste prompt: triage Semgrep findings with a failing test first**

```text
Run a Semgrep scan on the files changed on this branch against main, using
the Semgrep MCP tools if they are available, otherwise
`semgrep scan --config p/default --baseline-commit $(git merge-base main HEAD)`.

For each finding, classify it as EXPLOITABLE, NOT REACHABLE or FALSE
POSITIVE, quoting the code that decides it. For EXPLOITABLE, write a test
that demonstrates the attack and fails, then fix the code until it passes.
For FALSE POSITIVE, do not add nosemgrep or any suppression; list it for me
with a one-sentence reason. End with a table: rule, file:line, class, test.
```

## How do you prove the security gates work?

A gate you have never seen fire is an assumption. Prove each layer with a drill, then watch four numbers.

**Run a canary drill each quarter.** On a throwaway branch, have the agent commit a fake credential in a format the scanners detect, and add one known-vulnerable pattern, such as a shell command built from request input. Record which layer stopped each. If CI stops something pre-commit should have, a developer's hook is missing; if nothing stops it, you found the gap before an attacker did. For a live-format test key, use one your provider issues for testing and revoke it after the drill.

| Metric | Definition | Act when |
| ------ | ---------- | -------- |
| **Layer of first catch** | For each finding, the earliest layer that caught it | Findings move later (CI instead of session); check that hooks and pre-commit are installed on every machine |
| **Escaped secrets** | Secrets found in `main` history or reported by GitHub secret scanning after merge | Any non-zero value: rotate, then add the missed format to the Gitleaks config |
| **Suppressions added** | New `#gitleaks:allow`, `nosemgrep`, `.gitleaksignore` or `.semgrepignore` entries per month | Suppressions grow faster than findings; review who added them and why |
| **Security-review precision** | Security-review comments that led to a code change, divided by comments posted | Precision falls; tighten `custom-security-scan-instructions` or the false-positive file |

**Who signs off.** CI owns the gate: the required checks decide whether a pull request can merge. The agent owns fixing findings. A named security owner in `CODEOWNERS` approves any change to `.gitleaksignore`, `.gitleaks.toml`, `.semgrepignore`, `.pre-commit-config.yaml`, the workflow files and `.claude/`, because those are the files that switch the gates off. The same owner reads every pull request on your escalation list (authentication, payments, data access), whatever the scanners said. The escalation list lives in [reviewing an agent's pull request](/en/workflows/ship/agent-pr-review/).

**Traps that install the wrong tool or disable the gate**

Checked 2026-09-26 with `npm view` and the PyPI JSON API:

- **`npm i gitleaks`** installs an unrelated 1.0.0 package ("custom rules"), and **`npm i trufflehog`** a 0.0.5 package that searches subreddit posts. Both scanners are Go binaries: Homebrew, Docker or a release download.
- **`npm i semgrep`** is a 0.0.1 stub. Semgrep comes from Homebrew, PyPI or Docker.
- **`uvx semgrep-mcp`** installs PyPI `semgrep-mcp` 0.9.0 from the archived `semgrep/mcp` repository. Use `semgrep mcp`.
- **`npx mcp-scan`** runs an unrelated npm project (2.0.13). Snyk Agent Scan is `uvx snyk-agent-scan`, and Snyk says it publishes no npm package for it; `@snyk/agent-scan` does not exist.
- **`@sonarsource/sonarqube-mcp-server`** returns 404 on npm. The server is the Docker image `sonarsource/sonarqube-mcp`.
- **`/security-review`, `security-guidance` and `claude-security` are three different things.** The first is a built-in command, the second a hooks plugin, the third a deep-scan plugin (`claude-security@claude-plugins-official`).
- **`claude-code-security-review` without `claude-model`** falls back to a model retired on the Claude API.
- **The `security-guidance` reviewer honours inline justifications.** Its README says a comment explaining why a line is safe is treated as an exclusion, so an agent can silence a finding by writing one. Review new justification comments like suppressions.

## What breaks when agents meet security gates?

**The agent skips the hook** with `--no-verify`. Recovery: `guard-commit.sh` in Claude Code and the required CI jobs everywhere. A regex hook is a typo-catcher; a command wrapped in a script gets past it. CI is the boundary.

**The agent suppresses instead of fixing** with `#gitleaks:allow`, `nosemgrep` or a `.gitleaksignore` line. Recovery: `CODEOWNERS` on the ignore files, the "suppressions added" metric, and a CI Gitleaks run with `--ignore-gitleaks-allow` (Layer 3).

**The secret reached the model even though the commit was blocked.** The agent read `.env` for context, so the value sits in the transcript and possibly in telemetry. Recovery: rotate, then deny reads of `.env*` in the agent's permissions; the deny rules and sandboxing options are in [permissions and sandboxing](/en/workflows/harness/permissions-and-sandboxing/).

**Semgrep fails every pull request on an old codebase**, and people start merging with admin rights. Recovery: `--baseline-commit`, then burn down the backlog separately.

**The pull-request reviewer follows instructions planted in the diff**, such as a comment saying the file is pre-approved. Recovery: the fork condition and config-removal step above, with deterministic scanners as the required checks and the LLM review as advice.

**The in-session review fights a parallel agent** in the same worktree, reporting its changes to the wrong session. Recovery: `ENABLE_STOP_REVIEW=0`, or one worktree per agent, as in [running agents in parallel](/en/ecosystem/agent-tools/parallel-agents/).

**A hallucinated package slips past every scanner.** Secret and code scanners do not check that a dependency is real and trusted. Recovery: the lockfile-diff gate in [dependency checks for agent changes](/en/workflows/test/dependency-verification/).

## Where to go next with agent security

- [AI code review bots compared](/en/ecosystem/observability/ai-code-review-bots/) — The review layer beside the scanners: Claude Code Review, codex review, Bugbot and more.
- [Reviewing an agent's pull request](/en/workflows/ship/agent-pr-review/) — The human triage and escalation classes on top of the gates.
- [Claude Code hooks for automation](/en/claude-code/automate/hooks-automation/) — Hook events, deny semantics and how to test hooks before you rely on them.
- [Dependency checks for agent changes](/en/workflows/test/dependency-verification/) — Hallucinated and typosquatted packages, which secret and code scanners miss.
- [MCP security](/en/ecosystem/mcp/mcp-security/) — Vetting and scoping the MCP servers your agents run.
- [Security scanning and vulnerability testing](/en/workflows/test/security-testing/) — Vulnerability scanning, dependency audits and penetration-testing patterns beyond the commit gates.
- [Measuring agentic engineering](/en/ecosystem/observability/) — Where security findings fit in the weekly agent report.
