Skip to content
Back to skills

Claude Code Security Hardening

CSecurity

Hardens Claude Code settings, hooks, MCP servers and agent toolchains, and pairs with claude-security and the Claude Compliance API. Use for Claude Code or MCP security setup.

  • 7 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 21, 2026
securitypythonrustgoshellbashrailsgitapisecurity

Works with

  • claude code
  • cli
  • api
  • mcp

Security analysis

C64/100
  • highPerforms destructive filesystem operations
  • criticalContains 'ignore previous instructions' pattern — found in 91% of malicious skills (Snyk ToxicSkills)
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned November 23, 2026

npx -y skills add Peaky8linders/eu-ai-act-scanner --skill claude-code-security-hardening --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Claude Code Security Hardening?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Claude Code Security Hardening
[![Security: C — Skills Directory](https://www.skillsdirectory.com/api/skills/peaky8linders-claude-code-security-hardening/badge)](https://www.skillsdirectory.com/skills/peaky8linders-claude-code-security-hardening)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: claude-code-security-hardening
description: "Hardens Claude Code settings, hooks, MCP servers and agent toolchains, and pairs with claude-security and the Claude Compliance API. Use for Claude Code or MCP security setup."
user_invocable: true
---

# Claude Code Security, MCP Hardening & Compliance API Integration

Defensive-only hardening guide for startups shipping with **Claude Code**, **Claude Code Security** (`https://code.claude.com/docs/en/claude-security`), **MCP servers**, and the **Anthropic Claude Compliance API**. Eliminates the highest-risk developer and runtime exposures flagged by `mcp_toolchain`, `claude_code_security`, `lethal_trifecta`, and `security_controls`.

## When to invoke

- Hardening `.claude/settings.json`, enterprise **managed settings**, or `.mcp.json`
- Setting up **Claude Code Security** (`claude-security@claude-plugins-official`, `/threat-model`, `/claude-security`, `/security-review`, `security-guidance@claude-plugins-official`)
- Fixing findings from `mcp_toolchain`, `claude_code_security`, or `/ai-act-security-review`
- Preventing accidental `.env` or API-key commits in Claude Code
- Exporting and auditing **Anthropic Claude Compliance API** (`/v1/compliance/*`) logs & user preferences offline
- Enabling Claude Code **OpenTelemetry** audit trails or PR security review CI + SARIF 2.1.0 pipelines

## Applies to

- Any repository using Claude Code, Model Context Protocol (MCP) servers, or tool-calling AI agents.
- **In scope**: defensive configuration hardening, least-privilege permissions, pinning, local secret guards, and CI security review workflows.
- **Out of scope**: offensive exploitation or bypassing sandbox/access controls.

## 1. Least-Privilege `.claude/settings.json` Template

Never commit `bypassPermissions`, `"allow": ["Bash(*)"]`, or unreviewed shell hooks. Restrict permissions to explicit read/test/lint commands and deny credential paths:

```json
{
  "permissions": {
    "allow": [
      "Read",
      "Glob",
      "Grep",
      "Bash(pytest *)",
      "Bash(ruff check *)",
      "Bash(git status)",
      "Bash(git diff *)"
    ],
    "deny": [
      "Read(.env)",
      "Read(.env.*)",
      "Read(**/*.pem)",
      "Read(**/*.key)",
      "Write(.env)",
      "Write(.env.*)",
      "Bash(rm -rf *)",
      "Bash(git push --force *)"
    ]
  }
}
```

**Checklist (Art. 15(4) & OWASP Agentic ASI02/ASI03):**
- Remove `"defaultMode": "bypassPermissions"` from committed project settings.
- Replace wildcard `Bash(*)` with narrow command allowlists.
- Review any `PreToolUse` / `PostToolUse` hook commands before trusting a cloned repository.

## 2. Hardening `.mcp.json` Servers

MCP servers execute with your local environment or service credentials. Apply four strict rules:

1. **Pin versions — avoid floating installers**:
   - Bad: `"command": "npx", "args": ["-y", "@vendor/mcp-server"]` or unpinned `uvx pkg` (pulls unverified upstream code on every launch).
   - Good: Pin an exact version (`@vendor/mcp-server@1.4.2`) or invoke a locally installed, lockfile-pinned binary inside `.venv/`.
2. **Never hardcode secrets in `.mcp.json`**:
   - Bad: `"env": { "API_KEY": "sk-live-..." }`
   - Good: Reference environment variables supplied at runtime (e.g. `"${MY_API_KEY}"`) and keep real secrets in a secrets manager or untracked local shell profile.
3. **Bind locally & authenticate remote MCP endpoints**:
   - Local MCP servers should use `stdio` or bind strictly to `127.0.0.1` with Origin header validation (MCP 2025-11 / 2026 spec).
   - Any remote HTTP/SSE MCP endpoint must enforce authentication (OAuth / bearer token) and reject private/link-local SSRF targets (`169.254.169.254`, `10.0.0.0/8`, `127.0.0.1`).
4. **Audit tool descriptions for tool poisoning**:
   - Treat third-party MCP tool descriptions as untrusted prompt surface. Reject descriptions containing hidden instructions (e.g., "ignore previous instructions", "exfiltrate", "read ~/.ssh", or covert `<IMPORTANT>` directives).

Example hardened `.mcp.json`:

```json
{
  "mcpServers": {
    "eu-ai-act-scanner": {
      "command": ".venv/bin/eu-ai-act-scan-mcp",
      "args": []
    }
  }
}
```

## 3. Install the Opt-In Secret-Guard Hook

This repository ships a local-only `PreToolUse` hook: the guard script **`hooks/sensitive_data_guard.py`** (standard library only) and its registration in **`hooks/sensitive-data-guard.json`**. It:
- Blocks `Write` / `Edit` / `MultiEdit` to `.env` files, `*.pem`, `*.key` and SSH private keys (`.env.example`, `.env.sample` and `.env.template` stay allowed).
- Blocks writes whose new content adds a live-looking credential (`sk-` keys, `AKIA`, `ghp_`, `github_pat_`, `glpat-`, `xox*-`, PEM private keys).
- Checks `git diff --cached` before `git commit` and blocks the commit when the staged diff adds one of those credentials.
- Fails open: malformed input or a missing `git` never blocks your work.

To enable it:
1. Copy `hooks/sensitive_data_guard.py` to `.claude/hooks/sensitive_data_guard.py`.
2. Merge the `hooks` object from `hooks/sensitive-data-guard.json` into `.claude/settings.json` (team) or `.claude/settings.local.json` (just you).
3. On Windows without `python3` on `PATH`, change `python3` to `python` in the command.

## 4. Pair with Claude Code Security (`https://code.claude.com/docs/en/claude-security`)

Anthropic's official **Claude Code Security** workflow complements this scanner's deterministic EU AI Act checks with deep vulnerability hunting and an **adversarial verification panel**:

1. **Install official Anthropic security plugins**:
   ```bash
   /plugin install claude-security@claude-plugins-official
   /plugin install security-guidance@claude-plugins-official
   ```
   (`security-guidance@claude-plugins-official` warns on unsafe patterns in real time while editing; `claude-security@claude-plugins-official` provides full codebase auditing and threat modeling.)
2. **Generate a living `THREAT_MODEL.md` (Art. 9(2))**:
   - Run `/threat-model` to create `THREAT_MODEL.md` documenting trust boundaries, attacker goals, and high-value assets. Commit it alongside your AI docs.
3. **Run `/claude-security` or built-in `/security-review` & ingest offline**:
   - Save the report locally (SARIF 2.1.0, JSON, or structured Markdown) and pass it to `eu-ai-act-scan . --ingest-claude-security <report>` (or `scanner.claude_ecosystem.ingest_claude_security_report(...)`).
   - **Adversarial verification panel honored**: findings marked `verified: false`, `confirmed: false`, or `status` in `{"mitigated", "false_positive", "dismissed", "refuted"}` are automatically excluded; confirmed issues map to **EU AI Act Art. 15(4)** & **Art. 9(2)** with `file:line` and remediation hints.
4. **Enterprise governance — Managed Settings & OpenTelemetry**:
   - Lock org-wide `permissions.allow` / `permissions.deny` rules and disable `bypassPermissions` via enterprise **managed settings** (`managed-settings.json`) so individual repos cannot weaken security boundaries.
   - Enable Claude Code **OpenTelemetry** (`CLAUDE_CODE_ENABLE_TELEMETRY=1`) to stream developer tool-usage and session metrics into your SIEM / observability stack for Art. 12(1) and SOC 2 CC7.2 evidence.

## 5. Anthropic Claude Compliance API (Offline Org Audit Evidence)

For startups on Claude Enterprise / Team plans, pull read-only organizational audit metadata locally — **never uploading any repository code** — and unify it with your codebase scan:

1. **Create a Compliance Access Key** in `claude.ai` under **Organization settings > Data and privacy** with least-privilege scopes:
   - `read:compliance_activities` (`/v1/compliance/activities`)
   - `read:compliance_org_data` (`/v1/compliance/groups`)
   - `read:compliance_user_data` (`/v1/compliance/organizations/{org_uuid}/user_preferences`, `/v1/compliance/apps/sessions/remote/{id}/messages`)
2. **Export the key in your environment** (never pass it as a CLI flag):
   ```bash
   export ANTHROPIC_COMPLIANCE_ACCESS_KEY="sk-ant-..."
   ```
3. **Preview offline, fetch locally, and ingest offline** (`anthropic-version: 2026-10-21`):
   ```bash
   python <scanner-clone>/scripts/fetch_claude_compliance.py --dry-run
   python <scanner-clone>/scripts/fetch_claude_compliance.py --output compliance-api-export.json --org-uuid "$ORG_UUID"
   eu-ai-act-scan . --ingest-compliance-api compliance-api-export.json --dossier release-dossier.json
   ```
   (`<scanner-clone>` is the folder where you cloned eu-ai-act-scanner; the fetcher is not part of the installed engine.)
4. **What `ingest_compliance_api_export` checks automatically**:
   - **Art. 12(1) & Art. 26(6)**: verifies activity audit trail exists and flags `< 180` day retention (`cca-short-log-retention`).
   - **Art. 26(2)**: verifies organization group/RBAC governance (`cca-org-group-governance`).
   - **Art. 14(1) & Art. 50(1)**: audits *Instructions for Claude* / *Cowork Global instructions* for risky bypass directives (skip security review, hide AI disclosure, bypass human approval, disable audit logging, ignore PII/GDPR -> `cca-unsafe-user-preferences`).
   - **Art. 14(4)**: flags remote session high-risk tool executions (shell/delete/deploy/db-drop) marked `approved: false` or `bypass_permissions: true` (`cca-unreviewed-remote-session-actions`).

## 6. Automated PR Security Review & SARIF Interoperability

Combine deterministic EU AI Act scanning with Anthropic's **`anthropics/claude-code-security-review`** workflow:

1. **In Claude Code (local pre-PR)**: run `/ai-act-security-review` to execute deterministic analyzers + the 3-pass **Finder -> Adversary -> Referee** false-positive filter using `templates/security-scan-instructions.md` and `templates/false-positive-filter.md`.
2. **In GitHub Actions (CI on every PR)**:
   - Configure `anthropics/claude-code-security-review` to read `templates/security-scan-instructions.md` and `templates/false-positive-filter.md`.
   - Export offline SARIF 2.1.0 from this scanner (`scanner.sarif.write_sarif(result, "ai-act.sarif")`) to upload into GitHub Code Scanning or review locally.
   - Ingest SARIF from Semgrep, Bandit, Snyk, or CodeQL (`scanner.sarif.ingest_sarif_files(...)`) to unify cybersecurity SAST evidence under EU AI Act Art. 15(4).
3. **Track progress locally without gaming scores**:
   - Opt in per repo with `scanner.baseline.save_baseline(result, ".ai-act-baseline.json")` and diff every PR with `diff_baseline(result, ".ai-act-baseline.json")`.

## Setup

Install from this repository:

```bash
/plugin marketplace add Peaky8linders/eu-ai-act-scanner
/plugin install eu-ai-act-scanner@eu-ai-act-scanner
pip install -e ".[mcp]"
```

## Cross-references

- [founder-startup-triage](../founder-startup-triage/SKILL.md) — 3-bucket founder triage & enterprise questionnaires
- [interpreting-findings](../interpreting-findings/SKILL.md) — scoring bands & false-positive triage
- `hooks/sensitive-data-guard.json` — opt-in secret & `.env` PreToolUse hook
- `templates/security-scan-instructions.md` & `templates/false-positive-filter.md` — reusable PR security review rules

## Source of truth

EU Regulation 2024/1689 Art. 15(4)–(5) (cybersecurity & robustness), OWASP Top 10 for Agentic Applications (ASI01–ASI10), and MCP Authorization & Security best practices.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in security →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.