crefft Source 2026.10.4

Security Agent Family Guide

crefft > AI > Security Agents

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

Quick Reference

CommandAgentModelUse Case
/securitySecurity ArchitectOpusFull security assessment
/security quickCode Security ReviewerHaikuFast code scan
/security codeCode Security ReviewerSonnetDeep code analysis
/security depsSupply Chain AuditorHaiku+Dependency + SLSA audit
/security infraInfrastructure SecuritySonnetIaC, cloud, containers
/security threatThreat ModelerSonnetDesign-time analysis
/security networkNetwork Security AnalystSonnetZero trust, segmentation
/security detectDetection EngineeringSonnetFingerprinting, hunting
/security emergingEmerging Tech SecuritySonnetAI/ML, quantum, TEEs
/security redteamRed Team OperatorOpusAttack path analysis
/security siemSIEM/SOAR IntegrationSonnetDetection rules, playbooks
/security complianceCompliance AssessorSonnetRegulatory compliance
/incidentIncident Response LeadOpusSecurity events
/security postureSecurity Posture ScoreSonnetQuantified security metrics
/security-fixRemediation GeneratorSonnetGenerate fixes

Overview

The crefft Security Agent Family is a coordinated set of specialized AI agents for comprehensive security analysis. Unlike monolithic security tools, this family provides:

  1. Lifecycle Coverage - From design to incident response
  2. Cost Optimization - Right model for each task (80% cost savings vs. all-Opus)
  3. Deep Specialization - Each agent is an expert in its domain
  4. Educational Focus - Teaches developers, not just flags issues
  5. Standards-Based - RFC 2119 severities, OWASP/CWE mappings

Architecture

┌─────────────────────────────────────────────────────────────────────────────┐
│                      CREFFT  SECURITY AGENT FAMILY                          │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│                      ┌────────────────────────────┐                         │
│                      │    SECURITY ARCHITECT      │                         │
│                      │    (Opus - Coordinator)    │                         │
│                      └─────────────┬──────────────┘                         │
│                                    │                                         │
│  ┌──────────┬──────────┬──────────┼──────────┬──────────┬──────────┐       │
│  ▼          ▼          ▼          ▼          ▼          ▼          ▼       │
│ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌──────┐│
│ │ CODE   │ │SUPPLY  │ │ INFRA  │ │THREAT  │ │NETWORK │ │COMPLI- │ │INCID-││
│ │REVIEWER│ │ CHAIN  │ │SECURITY│ │MODELER │ │SECURITY│ │ ANCE   │ │ ENT  ││
│ │(Sonnet)│ │(Haiku+)│ │(Sonnet)│ │(Sonnet)│ │(Sonnet)│ │(Sonnet)│ │(Opus)││
│ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └──────┘│
│                                                                              │
│ ┌────────────────────────────────────────────────────────────────────────┐  │
│ │                     SPECIALIZED DOMAIN AGENTS                          │  │
│ │  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐  ┌────────────┐ │  │
│ │  │  DETECTION   │  │  EMERGING    │  │  RED TEAM    │  │ SIEM/SOAR  │ │  │
│ │  │ ENGINEERING  │  │    TECH      │  │  OPERATOR    │  │INTEGRATION │ │  │
│ │  │  (Sonnet)    │  │  (Sonnet)    │  │   (Opus)     │  │  (Sonnet)  │ │  │
│ │  │ JA4+, Hunt   │  │ AI/ML, PQC   │  │ ATT&CK Sim   │  │ Rules, SOC │ │  │
│ │  └──────────────┘  └──────────────┘  └──────────────┘  └────────────┘ │  │
│ └────────────────────────────────────────────────────────────────────────┘  │
│                                                                              │
│ ┌────────────────────────────────────────────────────────────────────────┐  │
│ │                        SUPPORTING AGENTS                               │  │
│ │  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐  ┌────────────┐│  │
│ │  │  SECURITY    │  │ REMEDIATION  │  │  SECURITY    │  │  POSTURE   ││  │
│ │  │  EDUCATOR    │  │  GENERATOR   │  │  REPORTER    │  │   SCORE    ││  │
│ │  │  (Haiku)     │  │  (Sonnet)    │  │  (Haiku)     │  │  (Sonnet)  ││  │
│ │  └──────────────┘  └──────────────┘  └──────────────┘  └────────────┘│  │
│ └────────────────────────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────────────────────┘

Agent Specifications

Tier 1: Strategic Coordinator

Security Architect

The Security Architect is the strategic coordinator for all security efforts.

AttributeValue
ModelOpus 4.5
Command/security
InvocationOn PR, manual, or triggered by security-sensitive paths

Responsibilities:

  • Assess overall security posture
  • Route to appropriate specialists
  • Synthesize findings across domains
  • Provide prioritized remediation roadmap

When to Use:

  • Comprehensive security review
  • Cross-domain security assessment
  • Executive-level security reporting

Tier 2: Domain Specialists

Threat Modeler

Analyzes system designs BEFORE implementation.

AttributeValue
ModelSonnet 4.5
Command/threat-model
MethodologySTRIDE, Attack Trees, Data Flow Diagrams

Output:

  • Data flow diagrams (Mermaid)
  • STRIDE analysis per trust boundary
  • Attack trees for critical assets
  • Security requirements (RFC 2119)
  • Risk assessment matrix

When to Use:

  • New feature design
  • Architecture changes
  • API design review
  • External integrations

Code Security Reviewer

Deep semantic analysis of source code.

AttributeValue
ModelSonnet 4.5 → Opus 4.5 (for critical findings)
Command/security code or automatic on PR
CoverageOWASP Top 10, CWE Top 25, language-specific

Detection Capabilities:

  • SQL/NoSQL/Command injection
  • XSS (Stored, Reflected, DOM)
  • CSRF, SSRF
  • Authentication/Authorization flaws
  • Cryptographic weaknesses
  • Hardcoded secrets
  • Business logic flaws

When to Use:

  • Every PR (automated)
  • Pre-merge security gate
  • Legacy code audit

Supply Chain Auditor

Analyzes dependencies for risks.

AttributeValue
ModelHaiku 3.5 + Sonnet 4.5
Command/security deps
CoverageCVEs, licenses, typosquatting, maintainer risk

Analysis Includes:

  • Known CVE scanning
  • Transitive dependency analysis
  • License compliance matrix
  • Supply chain attack indicators
  • SBOM generation (CycloneDX/SPDX)

When to Use:

  • Dependency updates
  • New package additions
  • Periodic audits (weekly/monthly)

Infrastructure Security Analyst

IaC and cloud configuration analysis.

AttributeValue
ModelSonnet 4.5
Command/security infra
CoverageTerraform, Kubernetes, Docker, AWS/GCP/Azure

Checks:

  • CIS Benchmark compliance
  • IAM/RBAC misconfigurations
  • Network exposure
  • Encryption at rest/transit
  • Container security
  • CI/CD pipeline security

When to Use:

  • IaC changes
  • Cloud resource provisioning
  • Kubernetes deployments

Compliance Assessor

Regulatory and standards compliance.

AttributeValue
ModelSonnet 4.5
Command/compliance <framework>
FrameworksGDPR, HIPAA, PCI-DSS, SOC 2, ISO 27001, NIST

Output:

  • Compliance matrix per framework
  • Gap analysis with remediation
  • Evidence inventory
  • Audit preparation checklist

When to Use:

  • Audit preparation
  • Compliance verification
  • New regulatory requirements

Incident Response Lead

Security incident handling.

AttributeValue
ModelOpus 4.5 (always)
Command/incident
PhasesTriage, Investigation, Containment, Remediation, Post-mortem

Capabilities:

  • Severity assessment (SEV-1 to SEV-4)
  • Timeline reconstruction
  • Root cause analysis (5 Whys)
  • Containment action generation
  • Post-mortem documentation

When to Use:

  • Security alerts
  • Suspected compromise
  • Breach investigation

Tier 2b: Specialized Domain Agents

Detection Engineering

Fingerprinting, behavioral detection, and threat hunting.

AttributeValue
ModelSonnet 4.5
Command/security detect
CoverageJA4+, JA3, behavioral patterns, ATT&CK

Capabilities:

  • JA4+ fingerprinting (TLS, HTTP, SSH, TCP)
  • Behavioral detection pattern development
  • Threat hunting hypothesis and playbooks
  • IOC lifecycle management
  • Detection-as-code practices
  • ATT&CK coverage analysis

When to Use:

  • Building detection capabilities
  • Threat hunting initiatives
  • Fingerprinting adversary infrastructure
  • Detection coverage assessment

Emerging Technologies Security

Security for AI/ML, quantum-safe crypto, and confidential computing.

AttributeValue
ModelSonnet 4.5 → Opus (novel attacks)
Command/security emerging
CoverageOWASP ML Top 10, LLM Top 10, MITRE ATLAS

Capabilities:

  • AI/ML security (prompt injection, model theft, data poisoning)
  • Quantum-safe cryptography (ML-KEM, ML-DSA, crypto agility)
  • Confidential computing (TEEs, attestation, enclaves)
  • Privacy-enhancing technologies (DP, FHE, MPC)

When to Use:

  • LLM/AI feature implementation
  • Post-quantum crypto planning
  • Confidential workload design
  • Privacy-sensitive data processing

Network Security Analyst

Zero trust architecture and network security.

AttributeValue
ModelSonnet 4.5
Command/security network
CoverageNIST SP 800-207, CIS Benchmarks

Capabilities:

  • Zero trust maturity assessment
  • Micro-segmentation design
  • DNS security (DNSSEC, DoH/DoT)
  • IDS/IPS configuration review
  • Network traffic analysis patterns

When to Use:

  • Zero trust implementation
  • Network architecture review
  • Segmentation planning
  • DNS security hardening

Red Team Operator

Adversary simulation and attack path analysis.

AttributeValue
ModelOpus 4.5 (always)
Command/security redteam
MethodologyMITRE ATT&CK, Cyber Kill Chain

Capabilities:

  • Attack path enumeration
  • Adversary emulation planning
  • Purple team exercise design
  • Detection gap identification
  • Offensive security guidance

When to Use:

  • Authorized penetration testing
  • Attack surface assessment
  • Purple team exercises
  • Security control validation

SIEM/SOAR Integration

Detection engineering and security operations.

AttributeValue
ModelSonnet 4.5
Command/security siem
CoverageSigma, Splunk SPL, Elastic KQL

Capabilities:

  • Detection rule development (multi-platform)
  • SOAR playbook design
  • SOC metrics and KPIs
  • Log source architecture
  • Alert tuning guidance

When to Use:

  • SIEM rule development
  • Playbook automation
  • SOC capability building
  • Detection coverage planning

Tier 3: Supporting Agents

Security Posture Score

Quantifies overall security into a single actionable metric.

AttributeValue
ModelSonnet 4.5
Command/security posture
Output0-100 score w/ component breakdown

Capabilities:

  • Weighted component scoring (code, supply chain, infrastructure, detection, access control, attack surface)
  • Trend analysis over time
  • Business impact quantification (ALE, ROI)
  • Industry benchmark comparison
  • Executive dashboard generation
  • Remediation ROI prioritization

Score Components:

ComponentWeightMeasures
Code Security25%Vulnerability density, fix velocity
Supply Chain20%CVE count, SLSA level, update lag
Infrastructure20%CIS compliance, misconfigurations
Detection Coverage15%ATT&CK coverage, MTTD
Access Control10%Least privilege, MFA, PAM
Attack Surface10%Exposed services, API security

When to Use:

  • Executive security reporting
  • Board-level security communication
  • Security program health tracking
  • Remediation prioritization
  • Compliance evidence

Security Educator

Explains vulnerabilities to developers.

AttributeValue
ModelHaiku 3.5
InvocationAttached to findings automatically

Content Types:

  • Plain-language explanations
  • Attack walkthroughs
  • Secure coding patterns
  • Practice exercises

Remediation Generator

Creates fixes for vulnerabilities.

AttributeValue
ModelSonnet 4.5
Command/security-fix

Output:

  • Git patch/diff
  • Security regression tests
  • Rollback instructions
  • PR template

Security Reporter

Generates reports for different audiences.

AttributeValue
ModelHaiku 3.5
FormatsExecutive, Technical, Compliance, Trend

Framework-Specific Security Patterns

Security agents MUST apply framework-specific checks based on the detected stack.

Django Security Patterns

VulnerabilityCheckRemediation
SQL InjectionRaw SQL via cursor.execute() with string formattingUse parameterized queries: cursor.execute(sql, [param])
SQL Injectionextra() or raw() with user inputUse ORM query methods with F() expressions
XSSmark_safe() with user contentUse template auto-escaping, escape() for dynamic
XSS|safe filter with user inputRemove filter, let auto-escape work
CSRF@csrf_exempt on state-changing viewsRemove decorator, use CSRF token properly
CSRFMissing {% csrf_token %} in formsAdd token to all POST forms
Auth@login_required missing on viewsAdd decorator to protected views
AuthCustom password validation without AUTH_PASSWORD_VALIDATORSUse Django’s validators
SecretsSECRET_KEY in code or repoMove to environment variable
SecretsDEBUG = True in production settingsUse separate production settings
ClickjackingMissing X_FRAME_OPTIONSSet X_FRAME_OPTIONS = 'DENY'

Flask Security Patterns

VulnerabilityCheckRemediation
SQL Injectiondb.execute() with f-stringsUse parameterized queries with ?
SQL InjectionString formatting in SQLAlchemy text()Use bound parameters: text("...").bindparams()
XSSMarkup() with user contentUse Jinja2 auto-escaping, avoid |safe
XSSrender_template_string() with user inputNever interpolate user input in templates
CSRFMissing Flask-WTF CSRF protectionEnable CSRFProtect(app)
SessionSECRET_KEY hardcodedLoad from environment
SessionWeak SECRET_KEYUse secrets.token_hex(32)
Debugdebug=True in productionUse environment variable
HeadersMissing security headersUse Flask-Talisman
File Uploadsave() without filename sanitizationUse secure_filename()

Rails Security Patterns

VulnerabilityCheckRemediation
SQL InjectionString interpolation in where()Use hash conditions or ? placeholders
SQL Injectionfind_by_sql with string interpolationUse array form with placeholders
XSSraw() or html_safe on user contentUse ERB auto-escaping, sanitize() for HTML
XSSrender inline: with user inputNever interpolate user input
Mass AssignmentMissing strong_parametersDefine permit() whitelist
CSRFskip_before_action :verify_authenticity_tokenRemove unless API endpoint with token auth
AuthCustom authenticate without timing-safe compareUse secure_compare() or Devise
Sessionssecret_key_base in secrets.yml committedUse credentials or environment
RedirectOpen redirect via redirect_to(params[:url])Validate against allowlist or use path only
File Accesssend_file(params[:file]) path traversalValidate against known paths

Next.js Security Patterns

VulnerabilityCheckRemediation
XSSdangerouslySetInnerHTML without sanitizationUse DOMPurify or remove entirely
XSSTemplate literals with user content in JSXLet React’s auto-escaping work
SSRFfetch() with user-controlled URL in Server ComponentsValidate against allowlist
AuthMissing auth check in Server FunctionValidate session at start of every function
AuthExposing secrets in client componentsUse Server Components for secret access
AuthzObject identity taken from client inputRe-read the row by ID scoped to the session owner
CSRFHand-rolled Origin checks in Server FunctionsDelete them; the framework already compares hosts
CSRFProxy host missing from serverActions.allowedOriginsAdd the browser-facing host to allowedOrigins
SecretsNEXT_PUBLIC_ prefix on sensitive varsRemove prefix, access only server-side
Injectioneval() in Server ComponentsNever use eval
Redirectredirect() with user inputValidate destination path
CacheCaching authenticated dataUse revalidate: 0 or no-store

Server Function CSRF and Authorization

Reviewers MUST NOT report a missing handwritten Origin check in a Server Function as a CSRF finding. Next.js 16.3.4 compares the host in the request’s Origin header against the app’s own host, taken from x-forwarded-host or host, and rejects the action when the two differ. See serverActions.

Why: flagging absent code that the framework supersedes produces false positives, and a hand-rolled check that disagrees with the framework’s host comparison is a second, weaker gate to maintain.

Reviewers MUST look for two real problems instead.

First, a reverse proxy that forwards its own host rather than the public one in x-forwarded-host makes every action fail until the browser-facing host is listed. Configure it, rather than disabling the check:

// next.config.js — extra hosts allowed to invoke Server Functions
module.exports = {
  experimental: {
    serverActions: {
      allowedOrigins: ['my-proxy.com', '*.my-proxy.com'],
    },
  },
}

Second, the built-in check has a documented gap: a request carrying no Origin header at all is allowed through with a warning rather than rejected. An application with a stricter policy SHOULD reject Origin-absent state-changing requests in middleware, and MUST NOT rely on the framework check as its only authorization.

Every Server Function is a public HTTP endpoint. Rendering a form only on an authenticated page is not a security boundary, so each function MUST authenticate, MUST authorize the specific object it touches, and MUST treat FormData, parameters, and headers as untrusted. See Server Actions.

// app/items/actions.ts
'use server'

import { auth } from '@/lib/auth'
import { db } from '@/lib/db'

// Don't: no auth, no ownership check, and the whole item comes from the
// client, so anyone who can POST here can complete any item.
export async function completeItemUnsafe(item: Item) {
  await db.item.update({ where: { id: item.id }, data: { completed: true } })
}

// Do: take only the change, derive identity from the session, and look the
// row up by ownership before writing.
export async function completeItem(itemId: string) {
  const session = await auth()
  if (!session?.user) throw new Error('Unauthorized')

  const item = await db.item.findFirst({
    where: { id: itemId, ownerId: session.user.id },
  })
  if (!item) throw new Error('Forbidden')

  await db.item.update({ where: { id: item.id }, data: { completed: true } })
}

Return values are serialized to the client, so actions SHOULD return the minimum the UI renders rather than raw database records. See Data Security.

FastAPI Security Patterns

VulnerabilityCheckRemediation
SQL InjectionRaw SQL in SQLAlchemy with f-stringsUse ORM or parameterized queries
SQL Injectiontext() without bound paramsUse .bindparams()
AuthMissing Depends(get_current_user)Add auth dependency to protected routes
AuthJWT validation without audience/issuerValidate aud and iss claims
CORSallow_origins=["*"] in productionSpecify explicit origins
CORSallow_credentials=True with wildcard originNever combine these
InputMissing Field() validation constraintsAdd min_length, max_length, regex
InputPath parameters without validationUse Path(..., ge=1) for IDs
SecretsLoading secrets from codeUse pydantic-settings from environment
DoSNo rate limitingAdd slowapi or similar

Axum (Rust) Security Patterns

VulnerabilityCheckRemediation
SQL InjectionString formatting in sqlx::query!Use compile-time checked query! macro
AuthMissing Extension<User> or auth middlewareAdd auth layer to protected routes
AuthJWT validation without exp checkValidate expiration in decode
CSRFState-changing handlers without tokenUse axum-csrf for form endpoints
Panicunwrap() in handlersUse ? with error types
PanicMissing catch-panic layerAdd tower-http::catch_panic
HeadersMissing security headersAdd tower-http::set_header layer
CORSCorsLayer::permissive() in productionConfigure explicit allowed origins
SecretsSecrets in codeUse config crate with environment
DoSNo request limitsAdd tower::limit layer

Gin (Go) Security Patterns

VulnerabilityCheckRemediation
SQL InjectionString concatenation in db.Query()Use parameterized queries with ?
SQL Injectionfmt.Sprintf for SQLUse db.Query(sql, args...)
XSSc.Header("Content-Type", "text/html") with user dataUse templating with auto-escape
XSSUnescaped output via c.Writer.WriteStringUse html/template
AuthMissing auth middleware on groupsAdd AuthRequired() middleware
CSRFNo CSRF protection for formsAdd csrf middleware
CORScors.Default() in productionConfigure specific origins
SecretsHardcoded secrets in codeUse viper or environment
PanicNo recovery middlewareAdd gin.Recovery()
InputMissing binding validation tagsAdd binding:"required" etc.

Severity Levels

All findings use RFC 2119 severity levels:

LevelKeywordMeaningAction Required
CriticalMUST FIXExploitable, data breach riskBlock merge
HighMUSTSignificant security weaknessFix before merge
MediumSHOULDSecurity improvement neededFix soon
LowMAYMinor hardening opportunityConsider
InfoN/AObservation onlyAwareness

Workflow Examples

Example 1: Pull Request Security Review

sequenceDiagram
    participant Dev as Developer
    participant SA as Security Architect
    participant CSR as Code Reviewer
    participant SCA as Supply Chain
    participant SE as Educator
    participant RG as Remediation

    Dev->>SA: Opens PR
    SA->>SA: Analyze changes
    SA->>CSR: Code changes detected
    SA->>SCA: package.json changed
    CSR-->>SA: 1 High, 2 Medium findings
    SCA-->>SA: 1 Critical CVE
    SA->>Dev: Security Report
    Dev->>SE: "Explain finding HIGH-001"
    SE-->>Dev: Vulnerability explanation
    Dev->>RG: "/security-fix HIGH-001"
    RG-->>Dev: Patch + test
    Dev->>SA: Re-review
    SA-->>Dev: ✅ Approved

Example 2: New Feature Threat Model

sequenceDiagram
    participant PM as Product Manager
    participant TM as Threat Modeler
    participant CA as Compliance Assessor
    participant SA as Security Architect

    PM->>TM: /threat-model "Payment feature"
    TM->>TM: STRIDE analysis
    TM->>CA: PCI-DSS implications
    CA-->>TM: Compliance requirements
    TM-->>PM: Threat Model Document
    TM-->>PM: Security Requirements
    PM->>SA: Review threat model
    SA-->>PM: Approved with conditions

Example 3: Security Incident

sequenceDiagram
    participant Alert as SIEM Alert
    participant IRL as Incident Lead
    participant CSR as Code Reviewer
    participant ISA as Infra Security
    participant RG as Remediation
    participant SR as Reporter

    Alert->>IRL: /incident triage
    IRL->>IRL: SEV-2 Assessment
    IRL->>CSR: Analyze vulnerable code
    IRL->>ISA: Check infrastructure
    CSR-->>IRL: SQL injection found
    ISA-->>IRL: No lateral movement
    IRL->>IRL: Containment plan
    IRL->>RG: Generate fix
    RG-->>IRL: Patch ready
    IRL->>SR: Generate post-mortem
    SR-->>IRL: Report complete

Cost Optimization

The agent family is designed for cost efficiency:

AgentModelEst. Cost/InvocationVolume
Security ArchitectOpus$0.50Per PR
Code Security ReviewerSonnet→Opus$0.20Per PR
Supply Chain AuditorHaiku+Sonnet$0.05On dep changes
Infrastructure SecuritySonnet$0.15On IaC changes
Compliance AssessorSonnet$0.20On demand
Threat ModelerSonnet$0.30Per feature
Network SecuritySonnet$0.20On demand
Detection EngineeringSonnet$0.25On demand
Emerging Tech SecuritySonnet$0.25On AI/ML features
Red Team OperatorOpus$0.80Quarterly
SIEM/SOAR IntegrationSonnet$0.20On demand
Security Posture ScoreSonnet$0.25Weekly/Monthly
Incident ResponseOpus$1.00Rare
Supporting AgentsHaiku$0.02Frequent

Cost by Mode:

ModeTypical CostUse Case
/security quick~$0.02Every commit
/security~$0.20PR review
/security full~$1.00Pre-merge gate

Estimated Monthly Cost (20-developer team, 100 PRs):

  • Full assessment: ~$100/month
  • Compare to: Snyk ($1,000+), GitHub Advanced Security ($980+)

Configuration

Claude Code has no agents.security settings block, and nothing in settings.json registers an agent, schedules a review, or blocks a merge. The family is activated by putting definition files where Claude Code looks for them, and it is constrained through the documented permissions and hooks keys. Everything below uses only settings that exist.

Install the Agents and Commands

Copy or symlink the crefft definitions into the project scope:

# Run from the root of the project you are protecting.
CREFFT=../crefft                      # path to your crefft checkout
mkdir -p .claude/agents/security .claude/commands

cp "$CREFFT"/agents/security/*.md .claude/agents/security/
cp "$CREFFT"/commands/security.md .claude/commands/
cp "$CREFFT"/commands/security-fix.md .claude/commands/
cp "$CREFFT"/commands/threat-model.md .claude/commands/
cp "$CREFFT"/commands/incident.md .claude/commands/

Teams MUST commit .claude/agents/ and .claude/commands/ so every contributor gets the same definitions. Individuals MAY install into ~/.claude/agents/ and ~/.claude/commands/ instead, which applies the family to every project on that machine.

Each agent file MUST carry name and description frontmatter. Claude Code silently skips a file missing either one and records the reason only in the debug log, so a typo produces no agent and no error:

---
name: code-security-reviewer
description: Identify code vulnerabilities with CWE/OWASP mapping. Use on
  changed source files before merge.
model: sonnet
tools: Read, Grep, Glob
---

Why: .claude/agents/ is the project location Claude Code scans for subagent definitions, and a foo.md in .claude/commands/ is what makes /foo typable. description is the only thing Claude reads when deciding whether to delegate, so it MUST say when the agent applies, not what it is.

Agent names MUST be unique across the whole tree; when two files in one agents directory declare the same name, Claude Code loads only one of them and the choice is filesystem read order. Run /doctor after installing: it reports files in the same directory that share a name.

Restrict What Each Agent May Do

Reporting agents SHOULD declare a read-only tools list in frontmatter, so an agent that is meant to find problems cannot rewrite the code it is judging. Only the Remediation Generator needs Edit.

Agent roletools frontmatter
Reviewers, auditors, modelers, reportersRead, Grep, Glob
Red Team Operator (needs command output)Read, Grep, Glob, Bash
Remediation GeneratorRead, Grep, Glob, Edit

Why: tools is enforced by Claude Code, not by the model, so it holds even when a prompt injection in the reviewed source tells the agent to do otherwise. Instructions in the agent body do not.

Back that with project settings that keep every agent away from credentials. Deny rules beat allow rules, and a Read deny also blocks Edit and Write on the same path:

{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "permissions": {
    "deny": [
      "Read(**/.env)",
      "Read(**/.env.*)",
      "Read(**/*.pem)",
      "Read(**/*.key)",
      "Read(**/id_rsa*)"
    ],
    "ask": [
      "Edit(**/.github/workflows/**)",
      "Bash(git push *)"
    ]
  }
}

Trigger Reviews on Sensitive Paths

There is no autoReview or triggerPaths setting. The supported mechanism is a PostToolUse hook whose if filter uses permission-rule path syntax. One handler is needed per path pattern, because a single if holds one rule:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "if": "Edit(**/auth/**)",
            "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/security-on-edit.sh",
            "statusMessage": "Security review of auth change"
          },
          {
            "type": "command",
            "if": "Edit(**/api/**)",
            "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/security-on-edit.sh",
            "statusMessage": "Security review of API change"
          }
        ]
      }
    ]
  }
}

Why: Edit(...) rules cover every built-in file-writing tool, including Write, whereas a Write(...) path rule is accepted and then never consulted. **/auth/** matches at any depth; a bare auth/** would match only the top-level directory in an allow rule.

The hook receives the PostToolUse JSON on stdin, not a filename argument, so it needs a small adapter over the shared security-quick.sh wrapper:

#!/usr/bin/env bash
# .claude/hooks/security-on-edit.sh — PostToolUse adapter.
set -uo pipefail

file=$(jq -r '.tool_input.file_path // empty')
[ -n "$file" ] || exit 0

wrapper="$(dirname "$0")/security-quick.sh"
if ! output=$("$wrapper" "$file" 2>&1); then
  printf '%s\n' "$output" >&2
  exit 2
fi
exit 0

The adapter MUST exit 2, not 1, when it wants Claude to act on the finding. On PostToolUse only exit 2 surfaces stderr to Claude; exit 1 is recorded as a non-blocking hook error and the turn continues, which is exactly the silent gate this section exists to avoid. PostToolUse fires after the write, so it cannot undo the edit; it tells Claude to fix what it just wrote.

type: "agent" hooks can run a subagent instead of a script, but that handler type is documented as experimental and SHOULD NOT carry a gate teams depend on.

Severity Thresholds

No Claude Code setting blocks a merge, and inventing one gives a team a gate that silently does nothing. A threshold is a property of the program that consumes the review: the pre-commit wrapper below and the CI gate in Integration each read a structured verdict and convert it to an exit status. Both read SECURITY_BLOCK_SEVERITY, so one environment variable sets the bar in both places.

LevelSECURITY_BLOCK_SEVERITYEffect
Critical onlycriticalBlocks on Critical
DefaulthighBlocks on Critical and High
StrictmediumBlocks on Critical, High, and Medium

Integration

GitHub Actions

Claude Code Action v1 takes prompt and claude_args; it has no command or fail_on input, so the severity gate MUST be a separate step that reads the structured output and exits non-zero:

# .github/workflows/security-review.yml
name: Security Review

on:
  pull_request:
    branches: [main]

permissions: {}

concurrency:
  group: security-review-${{ github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  security:
    # Fork pull requests cannot read secrets; skip rather than fail open.
    if: github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
      - name: Check out the pull request
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          fetch-depth: 0

      - name: Run the security review
        id: review
        uses: anthropics/claude-code-action@9c5ddab2e6d17b83ea679153b31f1d5f023cf636 # v1.0.217
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          prompt: |
            Run /security full over the diff between
            ${{ github.event.pull_request.base.sha }} and HEAD.
            Report only findings you can tie to a changed line.
            Set highest_severity to the worst severity you report,
            or "none" when the diff is clean.
          claude_args: |
            --max-turns 12
            --json-schema '{"type":"object","required":["highest_severity"],"properties":{"highest_severity":{"type":"string","enum":["none","low","medium","high","critical"]}}}'
            --allowed-tools "Read" "Grep" "Glob" "Bash(git diff *)" "Bash(git log *)"

      - name: Enforce the severity gate
        env:
          VERDICT: ${{ steps.review.outputs.structured_output }}
          SECURITY_BLOCK_SEVERITY: high
        run: |
          set -euo pipefail
          severity=$(printf '%s' "$VERDICT" |
            jq -r '.highest_severity // empty' 2>/dev/null || true)
          if [ -z "$severity" ]; then
            echo "No structured verdict returned; failing closed." >&2
            exit 1
          fi
          rank() {
            case "$1" in
              none) echo 0 ;; low) echo 1 ;; medium) echo 2 ;;
              high) echo 3 ;; critical) echo 4 ;; *) echo 4 ;;
            esac
          }
          if [ "$(rank "$severity")" -ge "$(rank "$SECURITY_BLOCK_SEVERITY")" ]; then
            echo "Blocking: highest severity is $severity." >&2
            exit 1
          fi
          echo "Highest severity is $severity; below the gate."

Why each part is there:

  • permissions: {} at workflow level drops the default token scopes, and the job grants back only contents: read and pull-requests: write, so a prompt injection in the diff cannot reach anything else.
  • Actions are pinned to full commit SHAs. A tag is a mutable pointer; a SHA is the artifact you reviewed.
  • --json-schema is what makes steps.review.outputs.structured_output populate. It MUST stay on one line: the action splits claude_args on whitespace.
  • The gate step fails closed on an empty verdict, so a crashed or rate-limited review blocks the merge rather than passing it.
  • The if guard is required because secrets.ANTHROPIC_API_KEY is empty for pull requests from forks. Reviewing untrusted forks needs pull_request_target and its own threat model; do not simply remove the guard.

Pre-commit Hook

pre-commit matches files by identify tags, and typescript is not one of them. Use types_or so the hook fires on any listed language rather than requiring a file to be all of them at once:

# .pre-commit-config.yaml
minimum_pre_commit_version: '4.6.2'
repos:
  - repo: local
    hooks:
      - id: security-quick
        name: Quick Security Scan
        entry: .claude/hooks/security-quick.sh
        language: script
        pass_filenames: true
        require_serial: true
        types_or: [python, javascript, ts, tsx]
        exclude: '^(vendor|third_party)/'

Why: types: [python, javascript, typescript] fails two ways. typescript is not a recognized tag, so pre-commit aborts with Type tag 'typescript' is not recognized; and once the spelling is corrected to ts, types is an AND across tags, so no file is both Python and JavaScript and the hook is reported as (no files to check) Skipped with exit status 0. A security hook that always passes is worse than no hook. ts and tsx are separate tags, so .tsx files need their own entry.

The entry MUST be a repository-owned script, not claude /security quick. claude "query" starts an interactive session; only claude -p runs a query and exits, and a model’s prose is not a gate until something turns it into an exit status:

#!/usr/bin/env bash
# .claude/hooks/security-quick.sh — blocks the commit on qualifying findings.
set -euo pipefail

: "${SECURITY_BLOCK_SEVERITY:=high}"
[ "$#" -gt 0 ] || exit 0

schema='{"type":"object","required":["highest_severity"],"properties":{"highest_severity":{"type":"string","enum":["none","low","medium","high","critical"]}}}'

verdict=$(printf '%s\n' "$@" | claude -p \
  'Run /security quick on the files listed on stdin. Set highest_severity
   to the worst severity you find, or "none" if the files are clean.' \
  --output-format json \
  --json-schema "$schema" \
  --permission-mode plan \
  --max-turns 6 \
  --allowed-tools "Read" "Grep" "Glob")

severity=$(printf '%s' "$verdict" |
  jq -r '.structured_output.highest_severity // empty' 2>/dev/null || true)
if [ -z "$severity" ]; then
  echo "security-quick: no structured verdict returned; failing closed." >&2
  exit 1
fi

rank() {
  case "$1" in
    none) echo 0 ;; low) echo 1 ;; medium) echo 2 ;;
    high) echo 3 ;; critical) echo 4 ;; *) echo 4 ;;
  esac
}

if [ "$(rank "$severity")" -ge "$(rank "$SECURITY_BLOCK_SEVERITY")" ]; then
  printf '%s' "$verdict" | jq -r '.result // empty' >&2 || true
  echo "security-quick: blocking commit, highest severity is $severity." >&2
  exit 1
fi

echo "security-quick: highest severity is $severity."

Both scripts MUST be executable: chmod +x .claude/hooks/security-quick.sh .claude/hooks/security-on-edit.sh. A hook whose path is wrong or not executable exits 127, which Claude Code records as a non-blocking error, so watch the first run. They need jq and a Claude Code installation that is authenticated non-interactively; claude setup-token produces a long-lived token for that. Teams SHOULD pin the Claude Code version in their bootstrap so the hook’s behavior does not drift under contributors.

Best Practices

DO

  • MUST run /security on all PRs with code changes
  • MUST run /threat-model for new features handling sensitive data
  • MUST address Critical and High findings before merge
  • SHOULD run /security deps weekly
  • SHOULD use /compliance before audits
  • MAY use /security quick for rapid iteration

DON’T

  • MUST NOT ignore Critical findings
  • MUST NOT skip security review for “small” changes
  • SHOULD NOT rely solely on automated review (human review still needed)
  • SHOULD NOT use only Code Reviewer for IaC changes

Extending the Family

Custom Rules

Claude Code does not read a .claude/security-rules.yaml, and crefft ships no parser for one. Project-specific rules go in .claude/rules/, where every .md file is loaded and a paths frontmatter list scopes a rule so it enters context only when Claude touches matching files:

---
paths:
  - "src/**/*.{ts,tsx}"
---

# CUSTOM-001: No console.log in production code

- **MUST NOT** leave `console.log(` in shipped code; use the project logger.
- Severity: Medium. Report file and line, and propose the logger call.
- Test files (`*.test.ts`) and `debug/` are out of scope.

Why: .claude/rules/*.md is a documented location that Claude Code loads, and paths keeps a long rule set out of context until it is relevant.

Rules are context, not enforcement: they shape what an agent looks for, and they cannot stop a tool call. A rule that MUST hold regardless of the model belongs in a PreToolUse hook or a permissions.deny entry, or in a deterministic linter the pre-commit hook also runs.

Custom Compliance Framework

Frameworks are expressed the same way, as a rule file the Compliance Assessor reads:

---
paths:
  - "src/**/*"
---

# Company Security Policy (ISP)

| Control | Requirement | Evidence to look for |
|---------|-------------|----------------------|
| ISP-001 | MFA required | Authentication path enforces a second factor |
| ISP-002 | Encryption at rest | All PII columns are encrypted before storage |

Troubleshooting

Common Issues

IssueSolution
Agent never runsname/description missing from frontmatter; check claude --debug
/security not typablecommands/security.md not copied into .claude/commands/
Too many false positivesRaise SECURITY_BLOCK_SEVERITY, or narrow scope with exclude in .pre-commit-config.yaml and paths in .claude/rules/
Pre-commit hook never firestypes requires every tag at once; use types_or
Missing findingsEnsure all relevant files are included in scope
Slow reviewsUse /security quick for initial pass
High costsLower --max-turns, or route to a cheaper model in frontmatter

Debug Mode

claude --debug

Shows subagent loading, skipped agent files, and hook resolution in the debug log.

See Also

References

Core Standards

Specialized Domains

Detection & Response

Vendored References

Security agents use offline reference data for speed and reliability:

reference/security/
├── manifest.json           # Version tracking and update schedule
├── mitre/
│   ├── attack/            # ATT&CK techniques and tactics
│   └── atlas/             # AI/ML threat landscape
├── cwe/                   # CWE Top 25 and common weaknesses
├── owasp/                 # Top 10 Web, API, LLM
├── fingerprints/ja4/      # JA4+ malware signatures
├── sigma/                 # Sigma rules index
├── slsa/                  # SLSA levels and verification
├── nist/                  # CSF 2.0 and SP 800-53
└── compliance/            # GDPR, HIPAA, PCI-DSS, SOC 2

References auto-update weekly via GitHub Actions. See manifest.json for versions.


Last Updated: 2026-09-08 Version: 1.1.0 Maintainer: Security Team