Claude Skills Guide

Claude Code for Security Scan Automation

Security scanning automation has become essential for teams shipping code frequently. Claude Code provides a powerful foundation for building automated security workflows that catch vulnerabilities before they reach production. This guide shows you how to use Claude Code skills and hooks to create robust security scan pipelines.

Setting Up Security Scan Skills

Claude Code works best for security automation when you configure dedicated skills for different scanning tasks. The tdd skill proves surprisingly useful here—while designed for test-driven development, its structured approach to running commands and validating outputs maps directly to security scan execution.

Start by creating a security scanning skill:

{
  "name": "security-scanner",
  "description": "Runs security scans on codebase",
  "commands": [
    {
      "name": "scan-deps",
      "command": "npm audit --json",
      "validator": "exit_code"
    },
    {
      "name": "scan-secrets",
      "command": "gitleaks detect --report-format json"
    }
  ]
}

This skill structure lets you run dependency audits and secret detection as discrete operations. The key advantage is consistency—each scan produces structured output you can parse and act upon.

Automating Dependency Vulnerability Scans

Dependency scanning represents one of the highest-ROI security automations. Tools like npm audit, pip-audit, and OWASP Dependency-Check all produce machine-readable output that Claude Code can process.

Here’s a practical approach using a Claude hook:

#!/bin/bash
# Pre-commit security hook

echo "Running dependency vulnerability scan..."

AUDIT_OUTPUT=$(npm audit --json 2>/dev/null)
VULN_COUNT=$(echo "$AUDIT_OUTPUT" | jq '.metadata.vulnerabilities.total // 0')

if [ "$VULN_COUNT" -gt 0 ]; then
  echo "⚠️  Found $VULN_COUNT vulnerabilities"
  echo "$AUDIT_OUTPUT" | jq '.vulnerabilities | to_entries | .[0:5]'
  exit 1
fi

echo "✅ No vulnerabilities found"
exit 0

This hook runs before each commit, blocking builds that introduce known vulnerabilities. The integration with Claude Code hooks means you can trigger this scan automatically whenever you ask Claude to commit code changes.

Secret Detection in Codebases

Detecting secrets committed accidentally happens more often than teams realize. The supermemory skill offers an interesting approach—its document indexing capabilities can be adapted to track sensitive patterns across your codebase.

A practical secret detection setup uses gitleaks:

# .gitleaks.toml
[rules]
  [[rules.BasicAuth]]
    description = "Basic Authorization Header"
    regex = '''(authorization|Authorization)\s*:\s*[Bb]asic\s+[A-Za-z0-9+/=]+'''
    
  [[rules.AWSAccessKey]]
    description = "AWS Access Key"
    regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
    
  [[rules.GitHubToken]]
    description = "GitHub Token"
    regex = '''gh[pousr]_[A-Za-z0-9_]{36,251}'''

Combine this with a Claude Code skill that runs gitleaks on every pull request:

// security-skills/github-check.mjs
import { execSync } from 'child_process';

export async function runSecretScan(repoPath) {
  const output = execSync('gitleaks detect --source . --report-format json', {
    cwd: repoPath,
    encoding: 'utf-8'
  });
  
  const findings = JSON.parse(output);
  
  if (findings.length > 0) {
    return {
      blocked: true,
      findings: findings.map(f => ({
        file: f.File,
        rule: f.RuleID,
        line: f.StartLine
      }))
    };
  }
  
  return { blocked: false };
}

SAST Integration for Code Analysis

Static Application Security Testing (SAST) tools analyze source code for vulnerabilities. Tools like Semgrep, Bandit (Python), and ESLint (with security rules) fit well into Claude Code workflows.

The pdf skill—typically used for PDF manipulation—can actually help here. Many security reports come as PDF documents from commercial scanners. You can automate the extraction of vulnerability data from these reports:

// Extract findings from security PDF reports
import { readPdf } from 'claude-pdf-skill';

export async function parseSecurityReport(pdfPath) {
  const text = await readPdf(pdfPath);
  
  const vulnPattern = /CVE-\d{4}-\d{4,7}/g;
  const cves = [...new Set(text.match(vulnPattern) || [])];
  
  return {
    cvssPattern: text.match(/CVSS[\s:]+[\d.]+/g) || [],
    cveCount: cves.length,
    cves
  };
}

This becomes valuable when integrating with commercial scanners that produce PDF reports—Claude Code can parse these and extract actionable data.

Container Security Scanning

Containerized applications require their own scanning layer. Trivy and Grype are popular open-source tools that integrate easily:

#!/bin/bash
# Scan container image for vulnerabilities

IMAGE=$1
TRIVY_OUTPUT=$(trivy image --format json --severity HIGH,CRITICAL "$IMAGE")

VULNS=$(echo "$TRIVY_OUTPUT" | jq '.Results[].Vulnerabilities | length')

if [ "$VULNS" -gt 0 ]; then
  echo "Container has vulnerabilities"
  echo "$TRIVY_OUTPUT" | jq '.Results[] | select(.Vulnerabilities) | {Target: .Target, Vulnerabilities: .Vulnerabilities}'
  exit 1
fi

In Claude Code, you can wrap this in a skill that accepts an image name and returns structured vulnerability data:

export async function scanContainer(imageName) {
  const result = await exec(`trivy image --format json ${imageName}`);
  const parsed = JSON.parse(result.stdout);
  
  const critical = parsed.Results
    .flatMap(r => r.Vulnerabilities || [])
    .filter(v => v.Severity === 'CRITICAL');
  
  return {
    image: imageName,
    criticalCount: critical.length,
    criticalVulns: critical.map(v => v.VulnerabilityID)
  };
}

CI/CD Pipeline Integration

Putting it all together, your CI/CD pipeline benefits from layered security scanning:

# .github/workflows/security-scan.yml
name: Security Scans

on: [push, pull_request]

jobs:
  dependency-scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm audit --audit-level=high
      
  secret-scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: gitleaks detect --source . --exit-code
      
  sast-scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: semgrep --config=auto --json
      
  container-scan:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - run: trivy image --severity HIGH,CRITICAL myapp:${{ github.sha }}

Each stage runs in parallel where possible, giving you fast feedback. Claude Code hooks can trigger these scans automatically, ensuring security checks happen consistently without manual intervention.

Building Custom Security Workflows

The real power of Claude Code for security automation comes from combining these tools into custom workflows. You can create skills that:

For teams using the frontend-design skill to build React applications, adding security scanning to the component generation workflow catches issues like unsafe DOM manipulation or missing CSRF protections early.

The key is treating security scanning as code—version controlled, automated, and integrated into your development workflow. Claude Code provides the automation layer that makes this practical without adding friction to your development process.

Built by theluckystrike — More at zovo.one