Claude Code Security Reviewer Documentation

repository·main·Indexed 26 days ago

https://github.com/anthropics/claude-code-security-review

An AI-powered GitHub Action and toolset using Anthropic's Claude to perform deep semantic security analysis on pull requests. It detects vulnerabilities ranging from injection attacks to business logic flaws. The documentation covers the GitHub Action setup, the SAST Evaluation Tool for running evaluations on PRs, the /security-review slash command for Claude Code, and guides for configuring custom false positive filtering and security scan instructions.

Tokens
2.5K
Snippets
6
Records
16
Agent score
90%

What's inside Claude Code Security Reviewer

  1. Quick Start: Set up Claude Code Security Review GitHub Action

    main

    To use the Claude Code Security Reviewer in your repository, create a GitHub Actions workflow file (e.g., .github/workflows/security.yml). The action requires pull-requests: write permissions to post comments on your PRs.

    Ensure you have a CLAUDE_API_KEY stored in your GitHub repository secrets. This key must be enabled for both the Claude API and Claude Code usage.

    name: Security Review
    
    permissions:
      pull-requests: write  # Needed for leaving PR comments
      contents: read
    
    on:
      pull_request:
    
    jobs:
      security:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
            with:
              ref: ${{ github.event.pull_request.head.sha || github.sha }}
              fetch-depth: 2
          
          - uses: anthropics/claude-code-security-review@main
            with:
              comment-pr: true
              claude-api-key: ${{ secrets.CLAUDE_API_KEY }}
  2. Configure custom security scan instructions

    main

    You can extend the Claude Code Security Reviewer's audit by adding organization-specific vulnerability categories. This allows the tool to check for concerns related to your specific technology stack (e.g., GraphQL, gRPC), compliance requirements (e.g., GDPR, HIPAA), or industry-specific patterns.

    To use custom instructions, create a text file containing your categories and reference it in your workflow using the custom-security-scan-instructions input.

    - uses: anthropics/claude-code-security-review@main
      with:
        custom-security-scan-instructions: .github/custom-security-categories.txt
  3. Configure custom false positive filtering instructions

    main

    You can tailor the security analysis to your specific environment by providing custom filtering instructions via the false-positive-filtering-instructions input. This allows you to define specific exclusions, quality criteria, and precedents to reduce noise in security findings.

    To use custom instructions:

    1. Create a plain text file containing your instructions (e.g., .github/false-positive-filtering.txt).
    2. Reference the file path in your workflow configuration.
    - uses: anthropics/claude-code-security-review@main
      with:
        false-positive-filtering-instructions: .github/false-positive-filtering.txt
  4. Customize the /security-review slash command

    main

    To customize the behavior of the /security-review command (e.g., adding organization-specific false positive filtering instructions), follow these steps:

    1. Copy the security-review.md file from this repository to your project's .claude/commands/ folder.
    2. Edit the security-review.md file to include your custom instructions.
  5. Install requirements for the SAST Evaluation Tool

    main

    To use the SAST Evaluation Tool, ensure your environment meets the following requirements:

    • Python: version 3.9 or higher
    • Git: version 2.20 or higher (required for git worktree support)
    • GitHub CLI: gh must be installed for API access

    Required Environment Variables:

    • ANTHROPIC_API_KEY: Necessary for accessing the Claude API.

    Recommended Environment Variables:

    • GITHUB_TOKEN: Recommended to avoid GitHub API rate limits.
  6. Write effective custom security categories

    main

    When defining custom categories, follow these best practices to ensure high-quality security audits:

    • Be Specific: Provide clear descriptions of what constitutes each vulnerability.
    • Include Context: Explain why a pattern is a vulnerability in your specific environment.
    • Provide Examples: Describe specific attack scenarios where possible.
    • Avoid Duplicates: Do not redefine default categories like Input Validation, Authentication, Crypto, Injection, or Data Exposure.
    • Keep It Focused: Only add categories relevant to your codebase.

    Writing Patterns

    Technology-Specific (e.g., GraphQL):

    **GraphQL Security:**
    - Query depth attacks allowing unbounded recursion
    - Field-level authorization bypass
    - Introspection data leakage in production

    Compliance-Focused (e.g., GDPR):

    **GDPR Compliance:**
    - Personal data processing without consent mechanisms
    - Missing data retention limits
    - Lack of data portability APIs

    Business Logic (e.g., Payments):

    **Payment Processing:**
    - Transaction replay vulnerabilities
    - Currency conversion manipulation
    - Refund process bypass
  7. Best practices for custom false positive filtering

    main

    When implementing custom filtering instructions, follow these best practices to maintain high-quality security analysis:

    • Start with defaults: Use the action's default instructions as a baseline and modify them only as you encounter specific false positives.
    • Be specific: Include details about your unique security architecture (e.g., "We use AWS Cognito for all authentication").
    • Document assumptions: Explain the reasoning behind exclusions (e.g., "k8s resource limits prevent DOS").
    • Version control: Keep your filtering instructions in your repository to track changes alongside your code.
    • Team review: Ensure your security team reviews and approves any changes to the filtering logic.
  8. Configure Claude Code Security Review Action Inputs

    main

    The following inputs can be passed to the anthropics/claude-code-security-review action to customize its behavior:

    InputDescriptionDefaultRequired
    claude-api-keyAnthropic Claude API key for security analysis. (Must be enabled for both Claude API and Claude Code)NoneYes
    comment-prWhether to comment on PRs with findingstrueNo
    upload-resultsWhether to upload results as artifactstrueNo
    exclude-directoriesComma-separated list of directories to exclude from scanningNoneNo
    claude-modelClaude model name to use.claude-opus-4-1-20250805No
    claudecode-timeoutTimeout for ClaudeCode analysis in minutes20No
    run-every-commitRun ClaudeCode on every commit (skips cache check).falseNo
    false-positive-filtering-instructionsPath to custom false positive filtering instructions text fileNoneNo
    custom-security-scan-instructionsPath to custom security scan instructions text file to append to audit promptNoneNo
  9. Security Considerations for Claude Code Security Review

    main

    Prompt Injection Warning

    This action is not hardened against prompt injection attacks. It should only be used to review trusted pull requests.

    To ensure workflows only run after a maintainer has reviewed the PR, configure your repository to use the "Require approval for all external contributors" option in GitHub settings.