Claude Skills Guide

Secret leaks are among the most critical security vulnerabilities in software development. A single exposed API key or database password can lead to data breaches, unauthorized access, and significant financial damage. Gitleaks is a powerful open-source tool that scans Git repositories for secrets, and when combined with Claude Code, it becomes an even more powerful part of your security workflow. This guide shows you how to integrate Claude Code with Gitleaks for automated secret scanning.

Why Integrate Claude Code with Gitleaks?

Gitleaks runs as a standalone CLI tool that detects secrets in your codebase. It supports over 100 secret types, including AWS keys, GitHub tokens, private keys, and database connection strings. While Gitleaks is excellent at scanning, pairing it with Claude Code adds several advantages:

Setting Up Gitleaks with Claude Code

Before integrating, ensure Gitleaks is installed on your system. The recommended approach is to use Homebrew on macOS:

brew install gitleaks

For other platforms, download the appropriate binary from the Gitleaks GitHub releases.

Once installed, verify the installation:

gitleaks version

Now create a Claude Skill that wraps Gitleaks and provides a user-friendly interface. Create a file called gitleaks-secret-scanner.md in your .claude/skills/ directory:

# Gitleaks Secret Scanner

Run Gitleaks to scan for secrets in the repository.

## Usage

Invoke this skill when you need to scan for exposed secrets.

## Steps

1. Run `gitleaks detect --source . --report-format json` to scan the repository
2. Parse the JSON output for findings
3. Categorize findings by severity and secret type
4. Provide actionable remediation advice for each finding

## Example Command

Invoke with: `/gitleaks-secret-scanner`

This basic skill structure provides a foundation. To make it more powerful, enhance it with detailed output parsing and remediation guidance.

Running Automated Scans

The most effective secret scanning workflow runs at multiple points in your development cycle:

Pre-commit Scanning

Prevent secrets from entering your repository by scanning before each commit. Create a pre-commit hook:

#!/bin/bash
# .git/hooks/pre-commit

gitleaks detect --source . --exit-code 1

if [ $? -eq 1 ]; then
    echo "Secrets detected! Commit blocked."
    echo "Run 'gitleaks detect --source . --report-format json' for details"
    exit 1
fi

Make the hook executable and add it to your repository:

chmod +x .git/hooks/pre-commit
git add .git/hooks/pre-commit

CI/CD Integration

For automated scanning in your CI pipeline, add Gitleaks to GitHub Actions:

name: Gitleaks Secret Scan

on: [push, pull_request]

jobs:
  gitleaks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run Gitleaks
        uses: gitleaks/gitleaks-action@v2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

This configuration runs Gitleaks on every push and pull request, blocking merges when secrets are detected.

Customizing Gitleaks Rules

Every project has different secret patterns. Gitleaks allows you to create custom rules for organization-specific secrets. Create a gitleaks.toml configuration file:

[rule "AWS Access Key ID"]
description = "Detects AWS Access Key ID"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
keywords = ["AKIA", "AGPA", "AIDA", "AROA"]

[rule "Custom API Token"]
description = "Detects custom organization API tokens"
regex = '''myorg-[a-zA-Z0-9]{32}'''
keywords = ["myorg-"]

Place this file in your project root and Gitleaks will use it for all scans. The custom rules catch secrets specific to your organization that wouldn’t be detected by default rules.

Working with Scan Results

When Gitleaks detects secrets, you need a clear process for handling findings. Here’s a practical workflow:

  1. Verify the finding: Not all detections are real secrets. Some may be test credentials or example values.

  2. Assess severity: Determine if the secret is active, expired, or test data.

  3. Rotate immediately: For real secrets, rotate them immediately and update your secrets management system.

  4. Clean history: If a secret was committed, use tools like git filter-repo to rewrite history and remove the secret.

  5. Update patterns: If a detection was a false positive, add it to your Gitleaks allowlist.

Advanced: Claude Code Enhanced Workflow

To take your secret scanning further, create an enhanced Claude Skill that provides detailed remediation guidance:

# Gitleaks Secret Scanner - Enhanced

Comprehensive secret scanning with remediation guidance.

## Usage

Invoke when scanning for secrets or investigating potential leaks.

## Steps

1. Run: `gitleaks detect --source . --report-format json --report-path gitleaks-report.json`
2. Read the JSON report
3. For each finding:
   - Identify the secret type
   - Provide severity assessment
   - Explain remediation steps
   - Suggest preventive measures
4. Summarize findings with action items

This enhanced skill provides developers with context-specific advice rather than just raw scan output.

Best Practices for Secret Scanning

Follow these practices to maintain security without slowing development:

Conclusion

Integrating Claude Code with Gitleaks creates a robust secret scanning workflow that catches vulnerabilities early and provides actionable remediation guidance. Start with basic scans in your pre-commit hooks, then expand to CI/CD integration and custom rules as your security maturity grows. Remember that secret scanning is part of a larger security strategy—combine it with secrets management, access controls, and team education for comprehensive protection.

The key is to make secret scanning automatic and routine, so your team catches issues before they become security incidents.

Built by theluckystrike — More at zovo.one