ggshield secret scan ai-hook
Description
Scan AI tool interactions for secrets.
ggshield secret scan ai-hook [OPTIONS]
This command is invoked automatically by the ggshield AI hooks installed in your coding assistant; it is not meant to be run manually. It reads a hook event from stdin as JSON, processes it, and outputs a JSON response to stdout that blocks the action if secrets are detected.
To install the hook for your AI coding assistants, run ggshield machine setup.
Options
--source-uuid TEXT: Identifier of the custom source in GitGuardian. If used, incidents will be created and visible on the dashboard. Requires the 'scan:create-incidents' scope.--filename-only: Send only the file name (not the full path) to GitGuardian, so incidents record just the filename.--all-secrets: Do not ignore any secret. Possible ignore-reason is shown as well.--instance URL: URL of the instance to use.--with-incident-details: Display full details about the dashboard incident if one is found (JSON and SARIF formats only). Requires the 'incidents:read' scope.-b,--banlist-detector DETECTOR: Exclude results from a detector.--ignore-known-secrets: Ignore secrets already known by GitGuardian dashboard.--exclude PATTERNS: Do not scan paths that match the specified glob-like patterns.--exit-zero: Return a 0 (non-error) status code, even if incidents are found. An error status code will still be returned for other errors, such as connection errors. This option can also be set with theGITGUARDIAN_EXIT_ZEROenvironment variable.--show-secrets: Show secrets in plaintext instead of hiding them.-o,--output PATH: Redirect ggshield output to PATH.--format [text|json|sarif]: Format to use for the output.--json: Shorthand for--format json.
This command supports all ggshield global options.
How it works
This command is called automatically by AI coding tools (Cursor, Claude Code, Codex, Copilot CLI, VS Code, and Mistral Vibe) when ggshield is installed as a hook. It is not intended to be called manually. Use ggshield machine setup to set up the hooks.
Exit codes
In normal operation, this command always returns exit code 0. The block or allow decision is communicated through a JSON payload in stdout, which the AI coding tool uses to display feedback in its UI.
If ggshield does not recognize the calling AI coding tool, it cannot scan or answer in the tool's format. It prints a warning on stderr, writes nothing on stdout, and exits as secret.ai_hook_failure_policy says:
0: allow the action (allow, the default).2: block the action (block).
It exits with 1 if the input is not a hook event.
When scanning cannot run
When ggshield cannot scan an interaction, for example because it is not authenticated or the GitGuardian API returns an error, secret.ai_hook_failure_policy decides the outcome:
allow(default): the interaction runs, and the AI coding tool shows a warning with the fix, such asggshield auth login.block:ggshieldblocks the interaction and shows the same warning. Lifecycle events, which have nothing to scan, still run.
The GITGUARDIAN_AI_HOOK_FAILURE_POLICY environment variable overrides the setting. See Configuration.
See also
- Secret scanning for AI coding tools: Installation guide and usage details.