Skip to content
Back to search

agentshield

AI agent security scanner. Detect vulnerabilities in agent configurations, MCP servers, and tool permissions. Available as CLI, GitHub Action, ECC plugin, and GitHub App integration. πŸ›‘οΈ

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/affaan-m--agentshield/badge.svg)](/listings/affaan-m--agentshield)

HTML

<a href="/listings/affaan-m--agentshield"><img src="/api/listings/affaan-m--agentshield/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

# Scan your Claude Code config (no install required)
npx ecc-agentshield scan

# Or install globally
npm install -g ecc-agentshield
agentshield scan

That's it. AgentShield auto-discovers your `~/.claude/` directory, scans all config files, and prints a graded security report.

Discovery intentionally skips common generated directories such as `node_modules`, build output, and `.dmux` worktree mirrors so transient copies do not duplicate findings.

  AgentShield Security Report

  Grade: F (0/100)

  Score Breakdown
  Secrets        β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0
  Permissions    β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0
  Hooks          β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0
  MCP Servers    β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0
  Agents         β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0

  ● CRITICAL  Hardcoded Anthropic API key
    CLAUDE.md:13
    Evidence: sk-ant-a...cdef
    Fix: Replace with environment variable reference [auto-fixable]

  ● CRITICAL  Overly permissive allow rule: Bash(*)
    settings.json
    Evidence: Bash(*)
    Fix: Restrict to specific commands: Bash(git *), Bash(npm *), Bash(node *)

  Summary
  Files scanned: 6
  Findings: 73 total β€” 19 critical, 29 high, 15 medium, 4 low, 6 info
  Auto-fixable: 8 (use --fix)

More commands

# Scan a specific directory
agentshield scan --path /path/to/.claude

# Auto-fix safe issues (replaces hardcoded secrets with env var references)
agentshield scan --fix

# JSON output for CI pipelines
agentshield scan --format json

# Generate an HTML executive security report
agentshield scan --format html > report.html

# Generate a portable audit bundle
agentshield scan --evidence-pack ./agentshield-evidence

# Three-agent Claude Opus adversarial analysis (requires ANTHROPIC_API_KEY)
agentshield scan --opus --stream

# Generate a secure baseline config
agentshield init

JSON reports now expose `findings[].runtimeConfidence` when AgentShield can distinguish active runtime config from project-local settings, template/example inventories, installed Claude plugin caches, declarative plugin manifests, and manifest-resolved non-shell hook implementations. Reports also include local harness adapter evidence for Claude Code, OpenCode, Codex, Gemini, Zed, VS Code, dmux, terminal-agent wrappers, and project-local templates when matching markers are present.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md Β· README Β· 1,057 lines Β· 1 finding marked

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. <div align="center">
  2. <img src="./assets/agentshield-logo.png" alt="AgentShield" width="180" />
  3. # AgentShield
  4. **Security auditor for AI agent configurations**
  5. Scans Claude Code setups for hardcoded secrets, permission misconfigs,<br/>
  6. hook injection, MCP server risks, and agent prompt injection vectors.<br/>
  7. Available as CLI, GitHub Action, and [GitHub App](https://github.com/apps/ecc-tools) integration.
  8. [![npm version](https://img.shields.io/npm/v/ecc-agentshield)](https://www.npmjs.com/package/ecc-agentshield)
  9. [![npm downloads](https://img.shields.io/npm/dm/ecc-agentshield)](https://www.npmjs.com/package/ecc-agentshield)
  10. [![tests](https://img.shields.io/badge/tests-passing-brightgreen)]()
  11. [![coverage](https://img.shields.io/badge/coverage-v8-blue)]()
  12. [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
  13. [Quick Start](#quick-start) Β· [What It Catches](#what-it-catches) Β· [API Reference](#api-reference) Β· [Opus Pipeline](#opus-46-deep-analysis---opus) Β· [GitHub Action](#github-action) Β· [Distribution](#distribution) Β· [MiniClaw](#miniclaw) Β· [Changelog](./CHANGELOG.md)
  14. <a href="https://compute.itomarkets.com">
  15. <img src="./assets/ito.svg" alt="ItΓ΄ Markets" width="180" />
  16. </a>
  17. <br />
  18. <sub><strong>Preferred compute sponsor:</strong> Run or self-host any open-source model. ItΓ΄ is ECC's suggested compute provider. Any GPU provider works. ECC only links to the ItΓ΄ dashboard for sign-in and GPU rental or management; it does not create or manage rentals or provision compute or serving. Managed inference through ItΓ΄ is not live yet.</sub>
  19. </div>
  20. ---
  21. ## Why
  22. The AI agent ecosystem is growing faster than its security tooling. In January 2026 alone:
  23. - **12%** of a major agent skill marketplace was malicious (341 of 2,857 community skills)
  24. - A **CVSS 8.8** CVE exposed 17,500+ internet-facing instances to one-click RCE
  25. - The Moltbook breach compromised **1.5M API tokens** across 770,000 agents
  26. Developers install community skills, connect MCP servers, and configure hooks without any automated way to audit the security of their setup. AgentShield scans your `.claude/` directory and flags vulnerabilities before they become exploits.
  27. Built at the [Claude Code Hackathon](https://cerebralvalley.ai/e/claude-code-hackathon) (Cerebral Valley x Anthropic, Feb 2026). Part of the [Everything Claude Code](https://github.com/affaan-m/everything-claude-code) ecosystem (42K+ stars).
  28. ## Quick Start
  29. ```bash
  30. # Scan your Claude Code config (no install required)
  31. npx ecc-agentshield scan
  32. # Or install globally
  33. npm install -g ecc-agentshield
  34. agentshield scan
  35. ```
  36. That's it. AgentShield auto-discovers your `~/.claude/` directory, scans all config files, and prints a graded security report.
  37. Discovery intentionally skips common generated directories such as `node_modules`, build output, and `.dmux` worktree mirrors so transient copies do not duplicate findings.
  38. ```
  39. AgentShield Security Report
  40. Grade: F (0/100)
  41. Score Breakdown
  42. Secrets β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0
  43. Permissions β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0
  44. Hooks β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0
  45. MCP Servers β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0
  46. Agents β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0
  47. ● CRITICAL Hardcoded Anthropic API key
  48. CLAUDE.md:13
  49. Evidence: sk-ant-a...cdef
  50. Fix: Replace with environment variable reference [auto-fixable]
  51. ● CRITICAL Overly permissive allow rule: Bash(*)
  52. settings.json
  53. Evidence: Bash(*)
  54. Fix: Restrict to specific commands: Bash(git *), Bash(npm *), Bash(node *)
  55. Summary
  56. Files scanned: 6
  57. Findings: 73 total β€” 19 critical, 29 high, 15 medium, 4 low, 6 info
  58. Auto-fixable: 8 (use --fix)
  59. ```
  60. ### More commands
  61. ```bash
  62. # Scan a specific directory
  63. agentshield scan --path /path/to/.claude
  64. # Auto-fix safe issues (replaces hardcoded secrets with env var references)
  65. agentshield scan --fix
  66. # JSON output for CI pipelines
  67. agentshield scan --format json
  68. # Generate an HTML executive security report
  69. agentshield scan --format html > report.html
  70. # Generate a portable audit bundle
  71. agentshield scan --evidence-pack ./agentshield-evidence
  72. # Three-agent Claude Opus adversarial analysis (requires ANTHROPIC_API_KEY)
  73. agentshield scan --opus --stream
  74. # Generate a secure baseline config
  75. agentshield init
  76. ```
  77. JSON reports now expose `findings[].runtimeConfidence` when AgentShield can distinguish active runtime config from project-local settings, template/example inventories, installed Claude plugin caches, declarative plugin manifests, and manifest-resolved non-shell hook implementations. Reports also include local harness adapter evidence for Claude Code, OpenCode, Codex, Gemini, Zed, VS Code, dmux, terminal-agent wrappers, and project-local templates when matching markers are present.
  78. ## What It Catches
  79. **268 rules** across 15 modules, graded A to F with a 0 to 100 numeric score. Recognized defenses are listed and never penalized.
  80. #### Scoring and recognized defenses
  81. The score starts at 100 per category and only findings deduct from it: critical 25, high 15, medium 5, low 2, info 0. Protective configuration the scanner finds (deny and ask lists, sandbox settings, blocking PreToolUse hooks, read-only agent tool lists, Codex `sandbox_mode`, Hermes manual approvals, and similar) is listed in every report under "Recognized Defenses" so it gets credit and is visibly never penalized. Defenses do not add points either: the score cannot be gamed by adding decorative deny rules, it can only be lowered by real findings. Guard-pattern findings the permission rules emit at info severity ("Deny/ask rule blocking ...", "Prohibition of ...", "Mention of ...") are enforced to a zero deduction in `src/reporter/score.ts`.
  82. ### Secrets Detection
  83. | What | Examples |
  84. |------|----------|
  85. | API keys | Anthropic (`sk-ant-`), OpenAI (`sk-proj-`/`sk-`), xAI (`xai-`), AWS (`AKIA`), Google/Gemini (`AIza`), Stripe (`sk_test_`/`sk_live_`) |
  86. | Tokens | GitHub PATs (`ghp_`/`github_pat_`), Linear (`lin_api_`), Cloudflare (`CF_API_TOKEN=`), Slack (`xox[bprs]-`), JWTs (`eyJ...`), Bearer tokens |
  87. | Credentials | Hardcoded passwords, database connection strings (postgres/mongo/mysql/redis), private key material |
  88. | Env leaks | Secrets passed through environment variables in configs, `echo $SECRET` in hooks |
  89. ### Permission Audit (17 rules)
  90. | What | Examples |
  91. |------|----------|
  92. | Wildcard access | `Bash(*)`, `Write(*)`, `Edit(*)` β€” unrestricted tool permissions |
  93. | Missing deny lists | No deny rules for `rm -rf`, `sudo`, `chmod 777` |
  94. | Dangerous flags | `--dangerously-skip-permissions` usage |
  95. | Mutable tool exposure | All mutable tools (Write, Edit, Bash) allowed without scoping |
  96. | Destructive git | `git push --force`, `git reset --hard` in allowed commands |
  97. | Unrestricted network | `curl *`, `wget`, `ssh *`, `scp *` in allow list without scope |
  98. ### Hook Analysis (40 rules)
  99. | What | Examples |
  100. |------|----------|
  101. | Command injection | `${file}` interpolation in shell commands β€” attacker-controlled filenames become code |
  102. | Data exfiltration | `curl -X POST` with variable interpolation sending data to external URLs |
  103. | Silent errors | `2>/dev/null`, `\|\| true` β€” failing security hooks that silently pass |
  104. | Missing hooks | No PreToolUse hooks, no Stop hooks for session-end validation |
  105. | Network exposure | Unthrottled network requests in hooks, sensitive file access without filtering |
  106. | Session startup | SessionStart hooks that download and execute remote scripts |
  107. | Package installs | Global `npm install -g`, `pip install`, `gem install`, `cargo install` in hooks |
  108. | Container escape | Docker `--privileged`, `--pid=host`, `--network=host`, root volume mounts |
  109. | Credential access | macOS Keychain, GNOME Keyring, /etc/shadow reads |
  110. | Reverse shells | `/dev/tcp`, `mkfifo + nc`, Python/Perl socket shells |
  111. | Clipboard access | `pbcopy`, `xclip`, `xsel`, `wl-copy` β€” exfiltration via clipboard |
  112. | Log tampering | `journalctl --vacuum`, `rm /var/log`, `history -c` β€” anti-forensics |
  113. ### MCP Server Security (49 rules)
  114. | What | Examples |
  115. |------|----------|
  116. | High-risk servers | Shell/command MCPs, filesystem with root access, database MCPs, browser automation |
  117. | Supply chain | `npx -y` auto-install without confirmation β€” typosquatting vector |
  118. | Hardcoded secrets | API tokens in MCP environment config instead of env var references |
  119. | Remote transport | MCP servers connecting to remote URLs (SSE/streamable HTTP) |
  120. | Shell metacharacters | `&&`, `\|`, `;` in MCP server command arguments |
  121. | Missing metadata | No version pin, no description, excessive server count |
  122. | Sensitive file args | `.env`, `.pem`, `credentials.json` passed as server arguments |
  123. | Network exposure | Binding to `0.0.0.0` instead of localhost |
  124. | Auto-approve | `autoApprove` settings that skip user confirmation for tool calls |
  125. | Missing timeouts | High-risk servers without timeout β€” resource exhaustion risk |
  126. Supply-chain verification (`agentshield scan --supply-chain`) extracts MCP
  127. package references plus root `package.json` and `package-lock.json` dependency
  128. evidence, then reports provenance counts for npm vs git, pinned vs unpinned,
  129. known-good packages, and npm-registry-backed metadata. Add
  130. `--supply-chain-online` to query npm for downloads, maintainers, postinstall
  131. scripts, deprecation, and package age.
  132. Package-manager hardening checks also scan `.npmrc`, `.yarnrc.yml`, and
  133. `pnpm-workspace.yaml` for plaintext registry credentials, explicit dependency
  134. lifecycle-script enablement, and missing or weak release-age cooldowns where the
  135. package manager supports them. npm configs are checked for lifecycle-script
  136. blocking and unsupported release-age keys that can create false confidence; use
  137. pnpm `minimumReleaseAge` / `minimum-release-age`, Yarn `npmMinimalAgeGate`, or an
  138. external package-manager policy wrapper for cooldown enforcement.
  139. AgentShield also scans AI developer-tool persistence surfaces used by recent npm
  140. and PyPI campaign payloads, including Claude Code hook settings,
  141. `.claude/router_runtime.js`, VS Code `tasks.json` folder-open automation,
  142. Zed project `tasks.json`, `.vscode/setup.mjs`, `.zed/setup.mjs`, GitHub
  143. workflow drop-ins, LaunchAgent/systemd dead-man switch artifacts,
  144. `gh-token-monitor` token-store files, metadata-service credential targets, and
  145. reported exfiltration or second-stage network indicators. These indicators are
  146. emitted as critical hook findings so CI can fail fast even after the malicious
  147. package has been uninstalled.
  148. #### MCP Confidence Notes
  149. AgentShield scans both active MCP config and repository-shipped MCP templates.
  150. - Findings from `.mcp.json`, `mcp.json`, `.claude/mcp.json`, `.claude.json`, and active `settings.json` are highest-confidence runtime exposure only under active Claude configuration roots; copies in docs, examples, or template directories are classified separately.
  151. - Findings from `settings.local.json` are emitted as `runtimeConfidence: project-local-optional`.
  152. - Findings from locations such as `mcp-configs/`, `config/mcp/`, or `configs/mcp/` indicate risky MCP definitions present in repository templates, not guaranteed active runtime enablement.
  153. - JSON, markdown, terminal, and HTML outputs now expose source context via `runtimeConfidence: active-runtime | project-local-optional | template-example | docs-example | plugin-cache | plugin-manifest | hook-code`.
  154. - Non-secret `template-example` MCP findings are score-weighted at `0.25x`, and one template file is capped at `10` deduction points per score category so a single MCP catalog cannot score like dozens of enabled servers.
  155. - In template files, findings such as risky server type, remote URL transport, `npx -y`, unpinned packages, and environment inheritance are still valuable, but they should be interpreted as "this repo ships a risky MCP template" rather than "this MCP is definitely enabled right now."
  156. - Aggregate findings like large MCP server counts are especially likely to overstate runtime exposure when the source file is a template catalog.
  157. ### Agent Config Review (41 rules)
  158. | What | Examples |
  159. |------|----------|
  160. | Unrestricted tools | Agents with Bash access, no `allowedTools` restriction |
  161. | Prompt injection surface | Agents processing external/user-provided content without defenses |
  162. | Auto-run instructions | `CLAUDE.md` containing "Always run", "without asking", "automatically install" |
  163. | Hidden instructions | Unicode zero-width characters, HTML comments, base64-encoded directives |
  164. | URL execution | `CLAUDE.md` instructing agents to fetch and execute remote URLs |
  165. | Time bombs | Delayed execution instructions triggered by time or absence conditions |
  166. | Data harvesting | Bulk collection of passwords, credentials, or database dumps |
  167. | Prompt reflection | `ignore previous instructions`, `you are now`, DAN jailbreak, fake system prompts |
    • Dismissed after review: Quotes instruction-override phrasing (in quotes, code, a table or an example): "ignore previous instructions"
    • Line 221 on GitHub
  168. | Output manipulation | `always report ok`, `remove warnings from output`, suppress security findings |
  169. Structured JSON under `.claude/subagents/` and `.claude/slash-commands/` is analyzed like agent config when it declares `allowedTools` or similar tool metadata. Slash commands under `commands/` and `slash-commands/` are typed `command-md`: they get the injection and dangerous-instruction rules but not the skill packaging hygiene rules, which only apply to `SKILL.md`. Freeform `skill-md` prompt text still has narrower security coverage than `agent-md` and `CLAUDE.md`.
  170. #### Scanner Accuracy Notes
  171. - Live audit notes and follow-up items are tracked in [`false-positive-audit.md`](./false-positive-audit.md).
  172. - The most useful operator guidance is in the audit's [`Triage Rules For Current Reports`](./false-positive-audit.md#triage-rules-for-current-reports) section.
  173. - The audit doc also includes a reusable [`False-Positive Taxonomy`](./false-positive-audit.md#false-positive-taxonomy), [`Repo Audit Worksheet`](./false-positive-audit.md#repo-audit-worksheet), and [`Release Gate For Accuracy Changes`](./false-positive-audit.md#release-gate-for-accuracy-changes).
  174. - Cross-file hook-manifest awareness now suppresses settings-only `hooks-no-pretooluse` when a companion `hooks/hooks.json` manifest defines PreToolUse hooks.
  175. - Manifest-referenced hook implementations are now discovered from `hooks/hooks.json`-style indirection; shell targets continue through hook rules, and non-shell `hook-code` targets now emit targeted findings for explicit `output(...)` context injection, transcript input access, and remote shell payloads executed via child-process wrappers.
  176. - Current known high-signal caveats are broader non-shell hook execution that still needs language-aware analysis beyond those current `hook-code` signals, and `skill-md` prompt text that still bypasses most agent/injection rules.
  177. - `runtimeConfidence` now appears on MCP findings, `settings.local.json`, docs/examples, installed Claude plugin caches, plugin manifests, and manifest-resolved non-shell hook code. Scoring discounts non-secret `template-example` and `docs-example` findings at `0.25x`, non-secret `project-local-optional` findings at `0.75x`, and non-secret `plugin-cache` / `plugin-manifest` findings at `0.5x`. Non-secret `template-example` findings are also capped at `10` deduction points per file and score category so one catalog file cannot dominate the grade. `hook-code` findings currently stay at full weight, but the active rules there are narrow language-aware implementation signals.
  178. - Practical reading rule: `template-example` means "repo ships this risky template", not "this is definitely enabled right now."
  179. - Practical reading rule: `docs-example` means "repo ships risky sample guidance", not "this example is active runtime config."
  180. - Practical reading rule: `plugin-cache` means "installed plugin content is present on disk", not "this file is top-level runtime config"; real secrets still stay critical.
  181. - Practical reading rule: `plugin-manifest` means "the repo declares this hook behavior", while `hook-code` means "the scanner reached the referenced non-shell implementation."
  182. - Current edge case: docs-only example trees now re-add the standalone `CLAUDE.md` example file for scanning, but still suppress the rest of the nested example subtree unless a runtime companion exists.
  183. - Current edge case: tutorial/example bundles outside the current `docs/`, `commands/`, `examples/`, `samples/`, `demo/`, `tutorial/`, `guide/`, `cookbook/`, and `playground/` heuristics can still be treated as live config until broader example-root classification lands.
  184. - Docs-only nested `CLAUDE.md` roots under `docs/` are now skipped unless runtime config companions exist in the same subtree.
  185. - Exact `Bash(curl https://...)` and `Bash(wget https://...)` allow entries with pinned literal URLs no longer trigger the generic `permissions-permissive-*` finding; wildcard and dynamic network permissions still do.
  186. - Exact `Bash(node scripts/foo.js ...)` and `Bash(python3 ./tools/audit.py ...)` wrapper commands no longer trigger the generic interpreter-access finding; inline eval forms such as `node -e` and `python -c` still do.
  187. - Exact read-only Docker inventory commands such as `Bash(docker ps)` and `Bash(docker image ls)` no longer trigger the generic Docker-access finding; execution-oriented forms such as `docker run` and `docker exec` still do.
  188. - Exact `settings.local.json` allowlists now downgrade `permissions-no-deny-list` from high to medium when every allow entry is fully specified; wildcard or dynamic project-local permissions still keep the higher severity.
  189. - Exact local-only `settings.local.json` allowlists now also downgrade `hooks-no-pretooluse` from medium to low; broader or network-capable project-local configs still keep the higher severity.
  190. - Comment-only shell-hook lines are now ignored by the hook exfiltration, sensitive-path, and silent-fail regex rules, so inline remediation notes and commented examples no longer look like live hook behavior.
  191. - Narrow specialist agents, subagents, and slash commands now downgrade generic Bash-access and escalation-chain findings from high to medium; broader generalist workflows still keep the higher severity.
  192. - Repo-scoped filesystem MCP servers using relative paths like `./` now grade lower than unrestricted root/home filesystem access; root-level filesystem exposure still stays high.
  193. - Defensive agent-review content that mentions patterns like ``fetch(userProvidedUrl)`` no longer triggers `agents-injection-surface`; direct instructions to fetch/process external content still do.
  194. - `agents-explorer-write` now uses role metadata and the lead agent intro instead of any later workflow/example text, so procedural `search for ...` steps in normal worker prompts no longer get mislabeled as explorer-style agents. Example: `chief-of-staff.md` no longer trips that rule just because it contains `gog gmail search ...`.
  195. - `agents-oversized-prompt` now measures effective prompt size instead of raw file length, discounting fenced code blocks and Markdown tables. Example-heavy agents like `chief-of-staff.md` and `planner.md` no longer trip the rule, while prose-heavy agents still do.
  196. - Markdown example/test passwords in example-like paths such as `docs/`, `commands/`, `examples/`, `tutorials/`, and `demos/` are now suppressed when the surrounding context is clearly instructional; that suppression does not apply to normal agent/config markdown.
  197. #### False-Positive Audit Workflow
  198. Use this workflow when a repo scan looks noisy or when you are tuning AgentShield rules.
  199. 1. Start with JSON output so you can inspect file paths, `runtimeConfidence`, and score impact directly.
  200. 2. Separate active runtime findings from lower-confidence source kinds before changing any rules.
  201. 3. Validate suspected false positives against at least one real repo and one minimal synthetic fixture.
  202. 4. Prefer source-aware reclassification and wording changes before adding blanket suppression.
  203. 5. Keep real secrets and explicit execution paths visible even inside examples, manifests, or templates.
  204. 6. Re-run targeted tests, then the full gate, before changing release behavior.
  205. Recommended commands:
  206. ```bash
  207. agentshield scan --path /repo --format json > report.json
  208. jq '.findings | group_by(.runtimeConfidence // "none") | map({
  209. runtimeConfidence: (.[0].runtimeConfidence // "none"),
  210. count: length
  211. })' report.json
  212. jq '.findings | group_by(.file) | map({
  213. file: .[0].file,
  214. count: length
  215. }) | sort_by(-.count)[:20]' report.json
  216. ```
  217. Confidence-first triage commands:
  218. ```bash
  219. # Highest-signal findings first: active runtime + project-local
  220. jq '.findings
  221. | map(select((.runtimeConfidence // "active-runtime") | IN("active-runtime","project-local-optional")))
  222. | map(select(.severity | IN("critical","high","medium")))
  223. | map({file, severity, runtimeConfidence, title})' report.json
  224. # Lower-confidence inventory that usually needs interpretation, not suppression
  225. jq '.findings
  226. | map(select((.runtimeConfidence // "") | IN("template-example","docs-example","plugin-cache","plugin-manifest")))
  227. | map({file, severity, runtimeConfidence, title})' report.json
  228. ```
  229. Recommended audit order:
  230. - `active-runtime` and `project-local-optional`: treat as highest-signal findings first.
  231. - `template-example`, `docs-example`, and `plugin-cache`: confirm whether the repo or installed plugin cache is shipping risky guidance versus actually enabling it.
  232. - `plugin-manifest`: confirm whether the risk is in declarative hook wiring or the referenced implementation.
  233. - `hook-code`: confirm whether the implementation actually injects context, reads transcripts, or shells out in a risky way.
  234. Rule-design guidelines:
  235. - Prefer source-aware labeling over suppression. If a finding is real but lower confidence, keep it visible and say why.
  236. - Prefer cross-file context over single-file guesses. Companion manifests and referenced hook implementations usually matter more than isolated config.
  237. - Prefer narrow, behavior-based `hook-code` rules over generic wrapper heuristics. `spawnSync("bash", ["-lc", "curl ... | bash"])` is high-signal; ordinary `spawnSync("prettier", ...)` is not.
  238. - Do not downgrade real secrets just because they appear in docs or examples. Structural findings can be downgraded; committed credentials should stay critical.
  239. - Keep example-root heuristics evidence-based. Today the scanner treats `docs/`, `commands/`, `examples/`, `example/`, `samples/`, `sample/`, `demo/`, `demos/`, `tutorial/`, `tutorials/`, `guide/`, `guides/`, `cookbook/`, and `playground/` as example-like paths.
  240. When you change rule accuracy, update both:
  241. - [`false-positive-audit.md`](./false-positive-audit.md) with the new baseline and remaining gaps
  242. - the targeted regression tests for the specific rule family you changed
  243. - `agentshield scan --corpus-gate` in CI so the built-in attack corpus must stay fully detected; failed corpus gates now include a prioritized accuracy improvement plan by category, missing rule, and missed config
  244. - the corpus now includes an env proxy/DNS exfiltration fixture so proxy hijack, runtime import mutation, env-token exfiltration, credential-store access, and clipboard access stay covered together
  245. - if you are filing a scanner-noise bug, start from the audit doc's [`False-Positive Issue Template`](./false-positive-audit.md#false-positive-issue-template)
  246. #### Reducing False Positives In Practice
  247. The current scan profile is not dominated by broken matchers. It is mostly dominated by lower-confidence source kinds that need different interpretation.
  248. Current patterns from the latest live scans:
  249. - template MCP inventory is still the biggest noise source by count in `everything-claude-code`
  250. - example/tutorial config needs example-aware wording and weighting, not blanket suppression
  251. - declarative hook manifests and executable hook implementations need different handling
  252. - many remaining agent findings are policy findings about intentionally privileged agents, not obvious rule bugs
  253. - the latest alert review reduced specialist agent-capability severity inflation, repo-scoped filesystem MCP inflation, and template-catalog score inflation; remaining noise is now mostly template count/interpretation and active-runtime remote MCP URLs
  254. Recurring pattern signatures to recognize:
  255. - one template file dominating the report usually means confidence/weighting work, not a broken matcher
  256. - broad `agents-*` clusters across files with explicit tool metadata usually mean policy review, not false-positive suppression
  257. - very small `project-local-optional` clusters usually mean scope is already modeled and only severity may need tuning
  258. - a repo-scoped filesystem MCP with relative-path args should not be treated like root/home filesystem access
  259. When to open a false-positive issue instead of just triaging the report:
  260. - the same finding pattern reproduces across at least one real repo and one minimal synthetic fixture
  261. - the finding is wrong for its own source kind, not just lower-confidence than `active-runtime`
  262. - the fix needs matcher changes, not just better wording, score weighting, or cross-file context
  263. - the finding would still be misleading even after reading `runtimeConfidence`
  264. Recommended operating model:
  265. - Start with `runtimeConfidence` before changing any rule. Separate `active-runtime` from `template-example`, `docs-example`, `plugin-cache`, `plugin-manifest`, and `project-local-optional`.
  266. - Reclassify before suppressing. If the finding is real but lower confidence, keep it visible and adjust wording or score weight instead of hiding it.
  267. - Keep secrets on a stricter standard. Real credentials should stay critical even in docs, examples, plugin caches, or manifests.
  268. - Use cross-file context whenever possible. Settings, manifests, and referenced hook implementations usually need to be read together.
  269. - For `hook-code`, add only narrow language-aware rules for explicit risky behavior. Avoid broad wrapper heuristics.
  270. - For agent rules, anchor on role metadata and lead instructions before matching arbitrary later prose.
  271. Repo conventions that help AgentShield scan accurately:
  272. - put reusable MCP catalogs under template paths such as `mcp-configs/` instead of live runtime config files
  273. - keep local-only overrides in `settings.local.json`
  274. - keep tutorials and examples under example-like paths such as `docs/`, `examples/`, `tutorials/`, `demos/`, or `guides/`
  275. - keep `hooks/hooks.json` declarative and put the implementation in separate hook script files
  276. - keep large agent examples inside fenced code blocks so prompt-size and role heuristics stay accurate
  277. Current high-value places to audit first:
  278. - files with the highest finding count
  279. - files with `runtimeConfidence: template-example` or `plugin-cache`
  280. - `settings.local.json` findings that may be project-local rather than repo-wide
  281. - `plugin-manifest` findings that need confirmation in the referenced implementation
  282. - `hook-code` findings that involve context injection, transcript access, or child-process execution
  283. ## Features
  284. ### Auto-Fix Engine (`--fix`)
  285. Automatically applies safe fixes:
  286. - Replaces hardcoded secrets with `${ENV_VAR}` references
  287. - Tightens wildcard permissions (`Bash(*)` β†’ scoped `Bash(git *)`, `Bash(npm *)`)
  288. Only fixes marked `auto: true` are applied. Permission changes require human review.
  289. **Verify-after-fix:** `--fix` does not trust itself. After applying fixes it re-scans the target, and if the posture score regressed or a new high/critical finding appeared (the kind of churn a naive permission tighten can cause), it rolls every modified file back to its original content. On success it prints a tamper-evident attestation digest binding the before/after score and finding deltas, so the kept fixes are provably non-regressing.
  290. ### External Rule Packs (`--rule-pack`)
  291. Run community or private detection rules alongside the built-ins, without recompiling:
  292. ```bash
  293. agentshield scan --rule-pack ./my-pack.json
  294. agentshield scan --rule-pack ./pack-a.json --rule-pack ./pack-b.json # repeatable
  295. ```
  296. A pack is a JSON file validated with the same fail-closed approach as `--policy` (bad JSON, schema violations, duplicate ids, or an uncompilable regex abort the scan):
  297. ```json
  298. {
  299. "version": 1,
  300. "name": "my-pack",
  301. "rules": [
  302. {
  303. "id": "tool-poisoning-001",
  304. "name": "Tool description poisoning",
  305. "description": "Hidden instruction in a tool description",
  306. "severity": "high",
  307. "category": "injection",
  308. "patterns": ["ignore (?:all )?previous instructions"],
  309. "fileTypes": ["agent-md", "claude-md"]
  310. }
  311. ]
  312. }
  313. ```
  314. Each pattern is a JS regex run against file content; `fileTypes` is optional and scopes a rule to specific config types. External findings count toward the overall grade. Anyone with a pack in this shape can plug in.
  315. ### Secure Init (`agentshield init`)
  316. Generates a hardened `.claude/` directory with scoped permissions, safety hooks, and security best practices. Existing files are never overwritten.
  317. ### Claude Opus Deep Analysis (`--opus`)
  318. Three-agent adversarial pipeline powered by Claude Opus (claude-opus-5 by default; the injection tester uses claude-sonnet-5):
  319. 1. **Red Team (Attacker)** β€” finds exploitable attack vectors and multi-step chains
  320. 2. **Blue Team (Defender)** β€” evaluates existing protections and recommends hardening
  321. 3. **Auditor** β€” synthesizes both perspectives into a prioritized risk assessment
  322. The Attacker finds that `curl` hooks with `${file}` interpolation + `Bash(*)` = command injection pivot. The Defender notes no PreToolUse hooks exist to stop it. The Auditor chains them into a prioritized action list.
  323. ```bash
  324. agentshield scan --opus # Red + Blue run in parallel
  325. agentshield scan --opus --stream # Sequential with real-time output
  326. agentshield scan --opus --stream -v # Verbose β€” see full agent reasoning
  327. ```
  328. ```
  329. ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  330. ┃ Phase 1a: ATTACKER (Red Team) ┃
  331. ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
  332. βœ“ Attacker analysis complete (4521 tokens)
  333. ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  334. ┃ Phase 1b: DEFENDER (Blue Team) ┃
  335. ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
  336. βœ“ Defender analysis complete (3892 tokens)
  337. ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  338. ┃ Phase 2: AUDITOR ┃
  339. ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
  340. Risk Level: CRITICAL
  341. Opus Score: β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 15/100
  342. ```
  343. Requires `ANTHROPIC_API_KEY` environment variable.
  344. #### OrcaRouter provider
  345. The `--opus` and `--injection` analysis modes can also run through
  346. [OrcaRouter](https://www.orcarouter.ai), an OpenAI/Anthropic-compatible gateway
  347. that routes each request to the most cost-effective upstream model:
  348. ```bash
  349. export ORCAROUTER_API_KEY=your-key-here
  350. agentshield scan --opus --provider orcarouter
  351. agentshield scan --injection --provider orcarouter
  352. ```
  353. The provider points the Anthropic client at `https://api.orcarouter.ai` and
  354. uses the gateway's namespaced model ids (e.g. `anthropic/claude-sonnet-5`,
  355. `anthropic/claude-opus-5`). The default provider remains Anthropic.
  356. With `--provider orcarouter` the scanned configuration contents are sent to
  357. OrcaRouter's API instead of Anthropic's, so do not use it on configs containing
  358. secrets you have not redacted.
  359. ### Compliance Mapping (`--compliance`)
  360. Map findings to audit-framework control IDs so GRC teams get an auditor-ready coverage artifact instead of a raw findings list:
  361. ```bash
  362. agentshield scan --compliance soc2 # SOC 2 Trust Services Criteria
  363. agentshield scan --compliance pci,iso # comma-separated
  364. agentshield scan --compliance all # SOC 2 + PCI DSS + ISO 27001
  365. ```
  366. Each framework prints a control-coverage table (control id, title, highest severity, finding count, examples), ordered by severity:
  367. ```
  368. ## Compliance Mapping: SOC 2 (Trust Services Criteria)
  369. Mapped 194/194 findings to 5 control(s). 0 finding(s) had no mapped control.
  370. | Control | Title | Highest | Findings | Examples |
  371. | CC6.1 | Logical access - credentials | critical | 76 | Hardcoded Anthropic API key; ... |
  372. ```
  373. Mapping is finding-category-level guidance (SOC 2, PCI DSS v4.0, ISO/IEC 27001:2022 Annex A), not a certified crosswalk; confirm control applicability with your auditor.
  374. ### Output Formats
  375. | Format | Flag | Use Case |
  376. |--------|------|----------|
  377. | Terminal | `--format terminal` (default) | Interactive use |
  378. | JSON | `--format json` | CI pipelines, programmatic access |
  379. | Markdown | `--format markdown` | Documentation, PRs |
  380. | HTML | `--format html` | Executive report with risk posture and priorities |
  381. | Evidence pack | `--evidence-pack <dir>` | Audit and buyer reviews |
  382. | Remediation plan | `--remediation-plan <path>` | Stable-fingerprint fix queue for CI and ticketing |
  383. Evidence packs write a deterministic directory containing `manifest.json`,
  384. `README.md`, `agentshield-report.json`, `agentshield-report.html`,
  385. `agentshield-results.sarif`, `policy-evaluation.json`,
  386. `baseline-comparison.json`, `supply-chain.json`, and
  387. `ci-context.json`, and `remediation-plan.json`. The manifest records SHA-256
  388. digests and byte counts for bundle artifacts plus a bundle digest over the
  389. machine-readable evidence. `ci-context.json` records whitelisted GitHub Actions
  390. workflow, commit, run, and runner provenance without copying arbitrary
  391. environment variables into the bundle.
  392. Redaction is enabled by default for local paths, usernames, emails, and
  393. token-shaped strings; use `--no-evidence-redact` only for private internal
  394. bundles.
  395. Remediation plans write a JSON queue of findings with stable hashed
  396. fingerprints, severity, file, fixability, ordered workflow phases, and the
  397. recommended next command. The workflow phases route safe auto-fixes first,
  398. manual-review findings second, and verification last so maintainers can attach
  399. the plan to CI tickets without turning every finding into a separate thread.
  400. They intentionally omit raw evidence and fix before/after values so teams can
  401. attach the plan to tickets without copying token-shaped strings.
  402. Verify a saved evidence pack before attaching it to CI artifacts or customer
  403. handoffs:
  404. ```bash
  405. agentshield evidence-pack verify ./agentshield-evidence
  406. agentshield evidence-pack verify ./agentshield-evidence --json
  407. ```
  408. Inspect a verified evidence pack when a downstream GitHub App, Linear sync, or
  409. security-review workflow needs a compact readback without opening every artifact:
  410. ```bash
  411. agentshield evidence-pack inspect ./agentshield-evidence
  412. agentshield evidence-pack inspect ./agentshield-evidence --json
  413. ```
  414. Aggregate multiple verified evidence packs when an operator needs fleet-level
  415. routing across repos, teams, or harnesses. The JSON output includes
  416. `operatorReadback` for promotion status/digest checks and `reviewItems` with
  417. source evidence paths and owner-ready recommendations for packs that need
  418. follow-up:
  419. ```bash
  420. agentshield evidence-pack fleet ./repo-a-evidence ./repo-b-evidence
  421. agentshield evidence-pack fleet ./repo-a-evidence ./repo-b-evidence --json
  422. ```
  423. `operatorReadback` is the stable field for downstream GitHub App, Linear, or
  424. ECC Tools routing. It reports `ready`, `status`, `digest`, owner counts,
  425. blocking review counts, approval routes, deterministic `approvalIds`, and the
  426. next operator action so fleet promotion can be gated without parsing terminal
  427. prose. Each review item also carries the same `approvalId` plus a
  428. Linear-friendly ticket `externalId`, allowing sync jobs to dedupe owner approval
  429. threads across reruns.
  430. ### JSON Report Shape
  431. `agentshield scan --format json` is the supported machine-readable scanner interface today.
  432. ```json
  433. {
  434. "timestamp": "2026-03-13T19:42:00.000Z",
  435. "targetPath": "/repo/.claude",
  436. "score": {
  437. "grade": "C",
  438. "numericScore": 66,
  439. "breakdown": {
  440. "secrets": 100,
  441. "permissions": 70,
  442. "hooks": 80,
  443. "mcp": 35,
  444. "agents": 45
  445. }
  446. },
  447. "summary": {
  448. "totalFindings": 29,
  449. "critical": 1,
  450. "high": 7,
  451. "medium": 8,
  452. "low": 10,
  453. "info": 3,
  454. "filesScanned": 17,
  455. "autoFixable": 2,
  456. "defenses": 4
  457. },
  458. "defenses": [
  459. {
  460. "id": "defense-deny-list",
  461. "title": "Permission deny list",
  462. "file": ".claude/settings.json",
  463. "detail": "6 deny rules; covers .env, ~/.ssh, curl, sudo, rm -rf. Deny wins over allow regardless of specificity.",
  464. "harness": "claude-code"
  465. }
  466. ],
  467. "findings": [
  468. {
  469. "id": "mcp-risky-filesystem",
  470. "severity": "medium",
  471. "category": "mcp",
  472. "title": "Template defines risky MCP server: filesystem",
  473. "description": "Repository template includes a high-risk filesystem MCP server.",
  474. "file": "mcp-configs/mcp-servers.json",
  475. "runtimeConfidence": "template-example"
  476. }
  477. ]
  478. }
  479. ```
  480. Notes:
  481. - `runtimeConfidence` is emitted for active runtime config, `settings.local.json`, docs/examples, installed Claude plugin caches, plugin manifests, and manifest-resolved non-shell hook code.
  482. - `harnessAdapters` is local marker evidence only. It does not call external services or imply a hosted/team entitlement.
  483. - Adapter `confidence` is `strong` when a primary harness marker exists, and `partial` when only supporting directories or secondary markers are present.
  484. - `active-runtime` means active config such as `.mcp.json`, `mcp.json`, `.claude/mcp.json`, `.claude.json`, or active `settings.json`.
  485. - `project-local-optional` means project-local settings such as `settings.local.json`.
  486. - `template-example` means template/catalog files such as `mcp-configs/` or `config/mcp/`.
  487. - `docs-example` means docs/tutorial/example content such as `docs/guide/settings.json` or `commands/*.md`.
  488. - `plugin-cache` means installed Claude plugin cache content such as `.claude/plugins/cache/...`.
  489. - `plugin-manifest` means declarative hook manifests such as `hooks/hooks.json`.
  490. - `hook-code` means a manifest-resolved non-shell implementation such as `scripts/hooks/session-start.js`.
  491. - Recognized defenses (`defenses[]` in JSON, "Recognized Defenses" in terminal and markdown) are credited, never penalized, and never add points.
  492. - Score weighting discounts non-secret `template-example` and `docs-example` findings to `0.25x`, non-secret `project-local-optional` findings to `0.75x`, and non-secret `plugin-cache` / `plugin-manifest` findings to `0.5x`; committed secrets still count at full weight. Non-secret `template-example` findings are also capped at `10` deduction points per file and score category. See [`false-positive-audit.md`](./false-positive-audit.md).
  493. ## API Reference
  494. AgentShield currently has three distinct automation surfaces:
  495. - CLI: `agentshield scan`, `agentshield init`, and `agentshield miniclaw start`
  496. - Scanner report JSON/SARIF: `agentshield scan --format json` or `agentshield scan --format sarif --output agentshield.sarif`
  497. - Organization policy gate: `agentshield scan --policy agentshield-policy.json`
  498. - MiniClaw package + HTTP API: `ecc-agentshield/miniclaw`
  499. Important packaging note:
  500. - The npm package root export currently points at the CLI entrypoint, not a semver-stable scanner library module.
  501. - Internal scanner modules such as `src/scanner/index.ts` and `src/reporter/score.ts` are useful for contributors, but they should not be documented as supported `import` paths for package consumers yet.
  502. - If you need automation around scanner results today, prefer the JSON report format over importing scanner internals from the package root.
  503. Detailed request/response and schema notes live in [`API.md`](./API.md).
  504. ## GitHub Action
  505. ```yaml
  506. - name: AgentShield Security Scan
  507. uses: affaan-m/agentshield@v1
  508. with:
  509. path: "."
  510. min-severity: "medium"
  511. fail-on-findings: "true"
  512. ```
  513. **Inputs:**
  514. | Input | Default | Description |
  515. |-------|---------|-------------|
  516. | `path` | `.` | Path to scan |
  517. | `min-severity` | `medium` | Minimum severity: critical, high, medium, low, info |
  518. | `fail-on-findings` | `true` | Fail the action if findings meet severity threshold |
  519. | `format` | `terminal` | Output format: terminal, json, markdown, sarif |
  520. | `sarif-output` | `agentshield-results.sarif` | SARIF output path when `format` is `sarif` |
  521. | `baseline` | `""` | Optional AgentShield baseline JSON path for drift comparison |
  522. | `save-baseline` | `""` | Optional path to write the current scan as a new baseline |
  523. | `policy` | `""` | Optional organization policy JSON path |
  524. | `fail-on-policy` | `true` | Fail the action if the organization policy is non-compliant |
  525. | `supply-chain` | `true` | Verify MCP npm/git package provenance and known malicious package risk |
  526. | `supply-chain-online` | `false` | Query npm registry metadata during supply-chain verification |
  527. | `fail-on-supply-chain` | follows `fail-on-findings` | Fail the action when supply-chain verification finds critical or high package risks |
  528. | `evidence-pack` | `""` | Optional directory for a portable audit evidence bundle |
  529. | `verify-evidence-pack` | `true` | Verify evidence-pack artifact hashes after writing |
  530. | `policy-promotion-manifest` | `""` | Optional policy export manifest to verify and promote or dry-run |
  531. | `policy-promotion-pack` | `""` | Policy pack id when the manifest contains multiple packs |
  532. | `policy-promotion-output` | `.agentshield/policy.json` | Active policy path to write when promotion dry-run is disabled |
  533. | `policy-promotion-dry-run` | `true` | Verify promotion review evidence without writing the active policy |
  534. | `fail-on-policy-promotion` | `false` | Fail when promotion review items still require action |
  535. **Outputs:** `score` (0–100), `grade` (A–F), `total-findings`, `critical-count`, `sarif-path`, `baseline-path`, `baseline-status`, `new-findings`, `resolved-findings`, `unchanged-findings`, `score-delta`, `policy-status`, `policy-violations`, `policy-promotion-status`, `policy-promotion-pack`, `policy-promotion-review-items`, `policy-promotion-action-required-count`, `policy-promotion-digest`, `supply-chain-status`, `supply-chain-risky-packages`, `supply-chain-critical-count`, `supply-chain-high-count`, `package-manager-hardening-status`, `package-manager-hardening-findings`, `package-manager-hardening-critical-count`, `package-manager-hardening-high-count`, `package-manager-hardening-registry-credentials`, `package-manager-hardening-lifecycle-scripts`, `package-manager-hardening-release-age-gates`, `evidence-pack-path`, `evidence-pack-status`, `evidence-pack-digest`
  536. The action writes a markdown job summary and emits GitHub annotations inline on affected files. When `format: sarif` is set, it also writes a SARIF 2.1.0 report that can be uploaded to GitHub code scanning with `github/codeql-action/upload-sarif`. When `baseline` is set, the action appends a baseline drift summary, emits regression annotations for new findings, and reports `baseline-status` as `passed`, `failed`, `missing`, or `not-run`. When `policy` is set, the SARIF report includes organization-policy violations as `agentshield-policy/*` code-scanning results, appends the organization policy result to the job summary, emits policy violation annotations, and fails by default unless `fail-on-policy: "false"` is set. When `policy-promotion-manifest` is set, the action verifies the selected policy export digest, emits promotion review-item counts, appends the owner/protected-rollout/runtime-smoke review items to the job summary, and marks runtime smoke as verified when the same job also scans with the promoted policy. Supply-chain verification runs offline by default for MCP package references, appends package-risk evidence to the job summary, writes real `supply-chain.json` evidence packs, and fails on critical/high package risk whenever the action is in failing mode unless `fail-on-supply-chain: "false"` is set. Package-manager hardening outputs and job-summary evidence separately count plaintext registry credentials, lifecycle-script drift, and release-age gate drift so CI and hosted consumers can route supply-chain configuration risk even when the main finding gate is collecting evidence only.
  537. Baseline drift gate:
  538. ```yaml
  539. - name: AgentShield Drift Gate
  540. uses: affaan-m/agentshield@v1
  541. with:
  542. path: "."
  543. baseline: ".github/agentshield-baseline.json"
  544. fail-on-findings: "false"
  545. ```
  546. Use `fail-on-findings: "false"` when the workflow should fail only on drift from the baseline. Keep the default `fail-on-findings: "true"` when any current finding at or above `min-severity` should still fail the action.
  547. ## CLI Reference
  548. ```
  549. agentshield scan [options] Scan configuration directory
  550. -p, --path <path> Path to scan (default: ~/.claude or cwd)
  551. -f, --format <format> Output: terminal, json, markdown, html, sarif
  552. -o, --output <path> Write the primary report output to a file
  553. --fix Auto-apply safe fixes
  554. --opus Enable Claude Opus multi-agent analysis
  555. --provider <provider> LLM provider for --opus/--injection: anthropic or orcarouter
  556. --stream Stream Opus analysis in real-time
  557. --injection Run active prompt injection testing
  558. --sandbox Execute hooks in a sandbox and observe behavior
  559. --taint Run taint analysis (data flow tracking)
  560. --deep Run injection + sandbox + taint + opus together
  561. --log <path> Write structured scan logs to a file
  562. --log-format <format> Log format: ndjson or json
  563. --corpus Run built-in attack corpus benchmark
  564. --corpus-gate Fail if the built-in attack corpus regresses
  565. --baseline <path> Compare against a baseline file
  566. --save-baseline <path> Save current scan results as a baseline file
  567. --gate Fail on new critical/high findings or score drop
  568. --supply-chain Verify MCP package provenance and risk
  569. --supply-chain-online Include npm registry metadata
  570. --compliance <frameworks> Map findings to controls: soc2, pci, iso, all
  571. --rule-pack <path> Load an external JSON rule pack (repeatable)
  572. --policy <path> Validate against an organization policy
  573. --evidence-pack <dir> Write portable evidence bundle
  574. --remediation-plan <path> Write stable-fingerprint JSON remediation plan
  575. --no-evidence-redact Disable evidence-pack redaction
  576. --min-severity <severity> Filter: critical, high, medium, low, info
  577. -v, --verbose Show detailed output
  578. agentshield init Generate secure baseline config
  579. agentshield baseline write Write a scan baseline JSON file
  580. agentshield evidence-pack fleet Summarize multiple evidence packs for routing
  581. agentshield evidence-pack inspect Verify and summarize an evidence bundle
  582. agentshield evidence-pack verify Verify artifact and bundle digests
  583. agentshield policy export Export policy packs plus checksum manifest
  584. agentshield policy init Generate an organization policy preset
  585. agentshield policy promote Verify and promote an exported policy
  586. ```
  587. Report footer CTA: terminal and markdown reports can append a one-line ECC
  588. Tools Pro footer. It is off by default. Set `AGENTSHIELD_CTA=1` (or
  589. `ECC_CTA=1`) to enable it; set `AGENTSHIELD_NO_CTA=1` (or `ECC_NO_CTA=1`) to
  590. hard-suppress it, which wins over opt-in. JSON and SARIF output never include
  591. it.
  592. Baseline write:
  593. ```bash
  594. agentshield baseline write --path .claude --output .github/agentshield-baseline.json
  595. agentshield baseline write --path .claude --output baseline.json --json
  596. ```
  597. The baseline command is a first-class wrapper around the existing scan baseline
  598. format. New baselines store stable hashed evidence fingerprints and omit raw
  599. evidence values, so teams can keep baseline snapshots in CI without copying
  600. token-shaped strings into long-lived artifacts. Existing raw-evidence baselines
  601. remain comparable during migration. Use it to create the accepted snapshot,
  602. then compare future scans with
  603. `agentshield scan --baseline .github/agentshield-baseline.json --gate`.
  604. Runtime monitor lifecycle:
  605. ```bash
  606. # Install the PreToolUse runtime monitor
  607. agentshield runtime install
  608. # Check whether the hook, policy, and log path are healthy
  609. agentshield runtime status --check
  610. # Back up invalid runtime files and restore a healthy install
  611. agentshield runtime repair
  612. ```
  613. Organization policy files support enterprise metadata and temporary exceptions:
  614. ```bash
  615. agentshield policy init --pack enterprise --owner security-platform@acme.example
  616. agentshield policy init --pack regulated --name "Acme Regulated Policy"
  617. agentshield policy export --output-dir .github/agentshield-policies --owner security-platform@acme.example
  618. agentshield policy export --pack ci-enforcement --name-prefix "Acme" --json
  619. agentshield policy promote --manifest .github/agentshield-policies/manifest.json --pack ci-enforcement --output .agentshield/policy.json
  620. agentshield policy promote --manifest .github/agentshield-policies/manifest.json --pack ci-enforcement --dry-run --json
  621. ```
  622. Policy pack presets are starter baselines, not hidden SaaS policy. `oss` keeps
  623. public repos permissive while requiring destructive-command deny entries;
  624. `team` adds the runtime hook; `enterprise` raises score gates and blocks broad
  625. tool allowlists; `regulated` disallows critical/high findings and bans broader
  626. MCP/tool surfaces; `high-risk-hooks-mcp` focuses on hook/MCP-heavy repos; and
  627. `ci-enforcement` is tuned for branch-protection evidence.
  628. Policy export writes one JSON policy file per selected pack plus a
  629. `manifest.json` containing SHA-256 digests. This gives platform teams a stable
  630. artifact bundle for branch-protection review, audit attachment, or downstream
  631. policy promotion without relying on generated console output.
  632. Policy promotion is the review gate for those exported bundles. It reads the
  633. export manifest, verifies the selected policy file digest, validates the policy
  634. schema, and only then writes the active policy path. Use `--dry-run --json` in
  635. review workflows to prove the exact pack, source file, output path, owner list,
  636. and digest before a protected branch or operator copies the policy into place.
  637. Promotion results also include `reviewItems` for owner approval, protected PR
  638. rollout, and the runtime smoke test needed before enabling an enforcing CI gate.
  639. ```json
  640. {
  641. "version": 1,
  642. "name": "Acme Corp Security Policy",
  643. "policy_pack": "enterprise",
  644. "owners": ["security-platform@acme.example"],
  645. "min_score": 85,
  646. "max_severity": "high",
  647. "required_deny_list": ["Bash(rm -rf"],
  648. "exceptions": [
  649. {
  650. "id": "AS-EX-001",
  651. "rule": "required_hooks",
  652. "owner": "security-platform@acme.example",
  653. "reason": "Legacy repository migration window",
  654. "expires_at": "2026-06-30T23:59:59.000Z",
  655. "scope": "agentshield",
  656. "ticket": "SEC-1234"
  657. }
  658. ]
  659. }
  660. ```
  661. Policy evaluation now includes an exception lifecycle audit in terminal output
  662. and GitHub Action summaries: total exceptions, active exceptions, exceptions
  663. expiring within seven days, expired exceptions, owners, tickets, scopes, and
  664. days until expiry. This keeps temporary waivers visible in branch-protection
  665. evidence instead of letting them become silent permanent bypasses.
  666. Exit codes:
  667. - `0`: scan completed without critical findings
  668. - `1`: CLI usage or runtime error
  669. - `2`: scan completed and found at least one critical issue
  670. ## Security Rules Summary
  671. | Category | Rules | Patterns | Severity Range |
  672. |----------|-------|----------|----------------|
  673. | Secrets | 10 | 14 | Critical -- Medium |
  674. | Permissions | 10 | -- | Critical -- Medium |
  675. | Hooks | 34 | -- | Critical -- Low |
  676. | MCP Servers | 23 | -- | Critical -- Info |
  677. | Agents | 25 | -- | Critical -- Info |
  678. | **Total** | **102** | **14** | |
  679. ## Architecture
  680. ```
  681. src/
  682. β”œβ”€β”€ index.ts CLI entry point (commander)
  683. β”œβ”€β”€ action.ts GitHub Action entry point
  684. β”œβ”€β”€ types.ts Type system + Zod schemas
  685. β”œβ”€β”€ scanner/
  686. β”‚ β”œβ”€β”€ discovery.ts Config file discovery
  687. β”‚ └── index.ts Scan orchestrator
  688. β”œβ”€β”€ rules/
  689. β”‚ β”œβ”€β”€ index.ts Rule registry
  690. β”‚ β”œβ”€β”€ secrets.ts Secret detection (10 rules, 14 patterns)
  691. β”‚ β”œβ”€β”€ permissions.ts Permission audit (17 rules)
  692. β”‚ β”œβ”€β”€ mcp.ts MCP server security (26 rules)
  693. β”‚ β”œβ”€β”€ hooks.ts Hook analysis (40 rules)
  694. β”‚ └── agents.ts Agent config review (41 rules)
  695. β”œβ”€β”€ reporter/
  696. β”‚ β”œβ”€β”€ score.ts Scoring engine (A-F grades)
  697. β”‚ β”œβ”€β”€ terminal.ts Color terminal output
  698. β”‚ β”œβ”€β”€ json.ts JSON + Markdown output
  699. β”‚ └── html.ts Self-contained HTML report
  700. β”œβ”€β”€ fixer/
  701. β”‚ β”œβ”€β”€ transforms.ts Fix transforms (secret, permission, generic)
  702. β”‚ └── index.ts Fix engine orchestrator
  703. β”œβ”€β”€ init/
  704. β”‚ └── index.ts Secure config generator
  705. └── opus/
  706. β”œβ”€β”€ prompts.ts Attacker/Defender/Auditor system prompts
  707. β”œβ”€β”€ pipeline.ts Three-agent Claude Opus pipeline
  708. └── render.ts Opus analysis rendering
  709. ```
  710. ## MiniClaw
  711. MiniClaw is a minimal, sandboxed AI agent runtime bundled with AgentShield. Where typical agent platforms expose many attack surfaces (Telegram, Discord, email, community plugins), MiniClaw presents a **single HTTP endpoint** backed by an **isolated sandbox**.
  712. ```bash
  713. # Start with secure defaults (localhost:3847, no network, safe tools only)
  714. npx ecc-agentshield miniclaw start
  715. # Custom configuration
  716. npx ecc-agentshield miniclaw start --port 4000 --network localhost --rate-limit 20
  717. ```
  718. Or use as a library:
  719. ```typescript
  720. import { startMiniClaw } from 'ecc-agentshield/miniclaw';
  721. const { server, stop } = startMiniClaw();
  722. // Listening on http://localhost:3847
  723. ```
  724. MiniClaw-specific package exports and HTTP endpoints are documented in [`src/miniclaw/README.md`](./src/miniclaw/README.md) and summarized in [`API.md`](./API.md). The React dashboard source lives in [`src/miniclaw/dashboard.tsx`](./src/miniclaw/dashboard.tsx), but it is not yet published as a separate npm subpath.
  725. ### Security Model
  726. Four independently enforced layers:
  727. ```
  728. Request β†’ [Rate Limit] β†’ [CORS] β†’ [Size Cap] β†’ [Sanitize Prompt]
  729. ↓
  730. [Tool Whitelist]
  731. ↓
  732. [Sandbox FS]
  733. ↓
  734. [Filter Output] β†’ Response
  735. ```
  736. - **Server** β€” Rate limiting (10 req/min/IP), CORS, 10KB request cap, localhost-only binding
  737. - **Prompt Router** β€” Strips 12+ injection pattern categories (system prompt overrides, identity reassignment, jailbreaks, data exfiltration URLs, zero-width Unicode, base64 payloads)
  738. - **Tool Whitelist** β€” Three tiers: Safe (read/search/list), Guarded (write/edit), Restricted (bash/network β€” disabled by default)
  739. - **Sandbox** β€” Isolated filesystem per session, path traversal blocked, symlink escape detection, extension whitelist, 10MB file cap, 5-min timeout, no network by default
  740. ### HTTP API
  741. | Method | Endpoint | Description |
  742. |--------|----------|-------------|
  743. | `POST` | `/api/prompt` | Send a prompt |
  744. | `POST` | `/api/session` | Create a sandboxed session |
  745. | `GET` | `/api/session` | Session info |
  746. | `DELETE` | `/api/session/:id` | Destroy session + cleanup |
  747. | `GET` | `/api/events/:sessionId` | Security audit events |
  748. | `GET` | `/api/health` | Health check |
  749. MiniClaw has **zero external runtime dependencies** β€” Node.js built-ins only (`http`, `fs`, `path`, `crypto`). The optional React dashboard requires React 18+ as a peer dependency.
  750. ## Development
  751. ```bash
  752. npm install # Install dependencies
  753. npm run dev # Development mode
  754. npm test # Run tests
  755. npm run test:coverage # Coverage report
  756. npm run typecheck # Type check
  757. npm run build # Build
  758. npm run scan:demo # Demo scan against vulnerable examples
  759. ```
  760. ## Distribution
  761. AgentShield is available through multiple channels:
  762. | Channel | Use Case | Install |
  763. |---------|----------|---------|
  764. | **Standalone CLI** | Direct scanning from your terminal | `npm install -g ecc-agentshield` or `npx ecc-agentshield scan` |
  765. | **GitHub Action** | Automated security checks on PRs in CI/CD | `uses: affaan-m/agentshield@v1` |
  766. | **ECC Plugin** | Claude Code users via the ECC skill ecosystem | Install through [Everything Claude Code](https://github.com/affaan-m/everything-claude-code) |
  767. | **ECC Tools GitHub App** | Integrated scanning across your GitHub org | Install at [github.com/apps/ecc-tools](https://github.com/apps/ecc-tools) |
  768. | **ECC Tools Pro** | GitHub App with automated repo analysis, Stripe billing ($19/seat/mo) | [Install](https://github.com/apps/ecc-tools) |
  769. ## FAQ
  770. ### What is AgentShield?
  771. AgentShield is a **security auditor for AI agent configurations**. It scans Claude Code setups for hardcoded secrets, permission misconfigs, hook injection, MCP server risks, and agent prompt injection vectors.
  772. | Feature | Description |
  773. |---------|-------------|
  774. | **Security Auditor** | Scans `.claude/` directory for vulnerabilities |
  775. | **Multiple Surfaces** | CLI, GitHub Action, GitHub App integration |
  776. | **Auto-Fix** | Replaces hardcoded secrets with env var references |
  777. | **Graded Reports** | Security score (0-100) with findings breakdown |
  778. | **Opus Pipeline** | Three-agent adversarial analysis with Anthropic API |
  779. | **Evidence Pack** | Portable audit bundle for compliance |
  780. ### What can AgentShield detect?
  781. | Category | Examples |
  782. |----------|----------|
  783. | **Secrets** | Hardcoded API keys, tokens, private keys, connection strings |
  784. | **Permissions** | Overly permissive allow rules like `Bash(*)` |
  785. | **Hooks** | Hook injection vectors, unsafe hooks |
  786. | **MCP Servers** | MCP server risks, malicious MCP configs |
  787. | **Agents** | Agent prompt injection vectors |
  788. ### How to get started?
  789. **Quick Start (no install):**
  790. ```bash
  791. npx ecc-agentshield scan
  792. ```
  793. **Install globally:**
  794. ```bash
  795. npm install -g ecc-agentshield
  796. agentshield scan
  797. ```
  798. **Auto-fix safe issues:**
  799. ```bash
  800. agentshield scan --fix
  801. ```
  802. ### What output formats are available?
  803. | Format | Use Case |
  804. |--------|----------|
  805. | **Default** | Terminal graded security report |
  806. | **JSON** | CI pipelines and automation |
  807. | **HTML** | Executive security report |
  808. | **Evidence Pack** | Portable audit bundle for compliance |
  809. ### What is the Opus Pipeline?
  810. The Opus Pipeline is a **three-agent adversarial analysis** that runs on Claude Opus through the Anthropic API:
  811. 1. **Attacker**: hunts for exploitable weaknesses in the scanned config
  812. 2. **Defender**: proposes concrete hardening for each weakness
  813. 3. **Auditor**: reconciles both views into a ranked risk assessment
  814. **Usage:**
  815. ```bash
  816. agentshield scan --opus --stream
  817. ```
  818. ### What is MiniClaw?
  819. MiniClaw is a **sandboxed agent runtime** included with AgentShield:
  820. - **Prompt Router**: Strips 12+ injection pattern categories
  821. - **Tool Whitelist**: Safe/Guarded/Restricted tiers
  822. - **Sandbox**: Isolated filesystem, path traversal blocked
  823. - **HTTP API**: REST endpoints for session management
  824. ### Is AgentShield free and open source?
  825. Yes! AgentShield is **MIT licensed** and free to use. Built at the Claude Code Hackathon (Cerebral Valley x Anthropic, Feb 2026).
  826. ### How to contribute?
  827. Contributions welcome! Check the [repository](https://github.com/affaan-m/agentshield) for issues and pull requests. See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
  828. ### Where to get help?
  829. | Resource | Link |
  830. |----------|------|
  831. | **Repository** | [github.com/affaan-m/agentshield](https://github.com/affaan-m/agentshield) |
  832. | **npm Package** | [npmjs.com/package/ecc-agentshield](https://www.npmjs.com/package/ecc-agentshield) |
  833. | **Changelog** | [CHANGELOG.md](./CHANGELOG.md) |
  834. | **Everything Claude Code** | [github.com/affaan-m/everything-claude-code](https://github.com/affaan-m/everything-claude-code) |
  835. | **Twitter** | [@affaanmustafa](https://x.com/affaanmustafa) |
  836. ## License
  837. MIT
  838. ---
  839. <div align="center">
  840. Built by [@affaanmustafa](https://x.com/affaanmustafa) Β· Part of [Everything Claude Code](https://github.com/affaan-m/everything-claude-code)
  841. </div>

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.