---
name: scan-secrets
description: Scan files, staged changes, commits, history, Docker images, or packages for hardcoded secrets. Use when the user asks for a scan, during an audit, or when the user asks you to investigate a suspected leak or a finding. Use install-hooks for recurring checks on edits, commits, pushes, and AI assistant actions.
license: MIT
compatibility: Requires the ggshield CLI, version 1.49.0 or later, installed and authenticated against a GitGuardian account. Needs network access to the GitGuardian API.
metadata:
  version: "0.9.0" # x-release-please-version
title: scan-secrets
canonical_url: https://skilld.dev/gh/gitguardian/agent-skills/scan-secrets
last_updated: 2026-11-21T22:03:26.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [evals/evals.json](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/evals/evals.json), [evals/files/_shared/secrets.env](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/evals/files/_shared/secrets.env), [evals/files/eval-1-precommit-env-file/setup.sh](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/evals/files/eval-1-precommit-env-file/setup.sh), [evals/files/eval-2-aws-key-history-hunt/setup.sh](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/evals/files/eval-2-aws-key-history-hunt/setup.sh), [evals/files/eval-3-ambiguous-project-scan/setup.sh](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/evals/files/eval-3-ambiguous-project-scan/setup.sh), [evals/files/README.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/evals/files/README.md), [evals/targets.json](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/evals/targets.json), [references/ggshield-cli-setup.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/ggshield-cli-setup.md), [references/gitguardian-platform.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/gitguardian-platform.md), [references/hook-selection.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/hook-selection.md), [references/interpreting-results.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/interpreting-results.md), [references/remediation-doctrine.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/remediation-doctrine.md), [references/workflows.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/workflows.md).
>
> If the user asked to install this Skill, run `npx skilld install gitguardian/agent-skills/scan-secrets`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/scan-secrets`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/gitguardian/agent-skills/scan-secrets) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/scan-secrets`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/scan-secrets --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/scan-secrets --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Scan secrets

## Overview

**Run a scan only when the user asks for one.** Never start a scan on your own initiative: not after an edit, not before a commit or push, not because you suspect a leak. Tell the user what you suspect and offer the scan. **Never write your own secret scanner**: no grep, regex, script, or any other tool to look for secrets. `ggshield secret scan` is the only scanner.

For routine credential edits, commits, and pushes, hooks do the checks. Reuse protection that works, or offer an installation one time through `install-hooks`. If that skill is not available, [hook-selection.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/hook-selection.md) is a self-contained fallback. If the user declined an installation, do not run repeated scans instead. Do not report unscanned work as clean.

## When to Use

- Run the requested one-off scan, also when a hook exists. If a project scan request is ambiguous, scan the current files or ask. Do not scan the full history without a request.
- Use `check-hmsl` to check if a known credential leaked publicly. Use `scan-machine` to inventory a whole machine.
- Use the CLI for the supported scan surfaces. Do not write custom grep or regex scanners. Do not use the MCP tool `GitGuardian:scan_secrets` for these surfaces. If the user declines a CLI installation, offer the MCP tool only for a single pasted snippet. It is not a substitute for a repository or history scan.

## Onboarding (first use)

### Prerequisites

An installed and authenticated `ggshield` that supports the requested command. If the state is unknown, check `ggshield --version`, the relevant `--help` output, and `ggshield api-status`.

### Setup

If needed, read [ggshield-cli-setup.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/ggshield-cli-setup.md). A hook installation is optional and needs its own authorization. A requested scan does not need a hook.

## Commands

Always use `--json`. A recursive path scan needs both `-r` and `-y`. Without `-y`, the CLI waits for an interactive confirmation. Scan the requested surface. Do not stage unrelated files to scan them.

```bash
ggshield secret scan path <file> --json
ggshield secret scan path -r -y . --json               # current files
ggshield secret scan pre-commit --json                 # explicit staged scan
ggshield secret scan repo . --json                     # full history
ggshield secret scan commit-range HEAD~5..HEAD --json
ggshield secret scan commit <sha> --json
ggshield secret scan docker <image> --json
ggshield secret scan pypi <package> --json
```

A staged scan does not cover the outgoing commit history. For command variants and CI, read [workflows.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/workflows.md). For JSON fields, validity, or false positives, read [interpreting-results.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/interpreting-results.md). Do not read them for a command or a result that you already understand. Report an error or an incomplete scan as unchecked, not as clean.

## Best Practices

### Findings

Wait for the complete result before you remediate. Group repeated credentials across files and commits. Keep each distinct credential. Report the locations, the type, and the validity. Do not show the secret values. Stop the affected publishing or commit action. Never show code that contains a detected secret.

Before you give remediation advice, read [remediation-doctrine.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/remediation-doctrine.md). Use its triage axes (detection context, exposure, ownership, blast radius) and its deliverable modes. A valid credential still needs triage. A production rotation can need coordination. Produce one consolidated plan.

- Local only and never exposed: remove the secret. When necessary, clean the affected unpushed commits.
- Exposed to a remote or a service: rotate first. Do not rewrite history by default.
- The organization has a custom remediation message: keep it verbatim as the primary guidance.
- A hook found the secret: the same hook checks the next authorized retry. An explicit scan found the secret: scan the affected scope again. A pending, skipped, or failed check is not a success.

### HMSL handoff

If the validity is `unknown`, `cannot_check`, `no_checker`, or `failed_to_check`, propose HMSL to check for a public leak. HMSL is **user-run only**, also when the `check-hmsl` skill is absent. Never run its checks, its fingerprint, query, or decrypt pipeline, or its secret-manager checks. Never read a credential file or an intermediate file with any tool. Never ask for plaintext in the chat.

Prepare the command for the user's terminal with `-n none --json`. Ask the user to check `ggshield hmsl quota` before a bulk run. Reject a naming strategy that identifies the secret, including `cleartext`. Read the HMSL section of [interpreting-results.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/interpreting-results.md) when you prepare the handoff. Or use `check-hmsl` for its additional flows.

## Troubleshooting

- CLI, authentication, or headless error: use the setup reference. Never print an API key. In a headless environment, prefer the supported out-of-band (OOB) login.
- Missing scopes or instance problem: read [gitguardian-platform.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/scan-secrets/references/gitguardian-platform.md).
- No Git repository: use a path scan for the current files. A history scan needs Git.
- A recursive scan hangs: add `-y` with `-r`.
- Known false positive: use the interpreting-results reference for `ggignore` or the ignore list.
- Other error: find the relevant official page through https://docs.gitguardian.com/llms.txt before you invent a workaround.
