---
name: install-hooks
description: Install or repair hooks that check for secrets on each commit, push, or AI assistant action. Use when the user wants leak prevention, when credential-handling work has no hook protection, or when agent scans duplicate a hook that already exists. Use scan-secrets for a one-off scan or a leak investigation.
license: MIT
compatibility: Requires the ggshield CLI installed and authenticated, version 1.49.0 or later for AI-assistant hooks and 1.51.0 or later for codex. Git hooks need git; AI-assistant hooks need the target tool installed.
metadata:
  version: "0.9.0" # x-release-please-version
title: install-hooks
canonical_url: https://skilld.dev/gh/gitguardian/agent-skills/install-hooks
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/install-hooks/evals/evals.json), [evals/files/already-has-hook/setup.sh](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/evals/files/already-has-hook/setup.sh), [evals/files/ambiguous-asks-family/setup.sh](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/evals/files/ambiguous-asks-family/setup.sh), [evals/files/global-needs-consent/setup.sh](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/evals/files/global-needs-consent/setup.sh), [evals/files/install-claude-code/setup.sh](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/evals/files/install-claude-code/setup.sh), [evals/files/install-precommit-local/setup.sh](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/evals/files/install-precommit-local/setup.sh), [evals/files/README.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/evals/files/README.md), [evals/targets.json](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/evals/targets.json), [references/ggshield-cli-setup.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/references/ggshield-cli-setup.md), [references/gitguardian-platform.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/references/gitguardian-platform.md), [references/hook-selection.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/references/hook-selection.md).
>
> If the user asked to install this Skill, run `npx skilld install gitguardian/agent-skills/install-hooks`. 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/install-hooks`, 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/install-hooks) 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/install-hooks`. 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/install-hooks --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/install-hooks --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.

# Install secret-scanning hooks

## Overview

Hooks do the recurring checks. The agent does not. Never run a scan yourself, and never write a script or other tool to find secrets. Check the existing protection once per context. Reuse protection that works. Offer a missing installation or a repair one time. If the user declines, do not ask again, and do not run scans instead.

## When to Use

| Requested protection | Hook | Content that the hook checks |
|---|---|---|
| Before a commit | `pre-commit` | Staged changes |
| Before a push | `pre-push` | Outgoing commits, including intermediate versions |
| During AI assistant actions | AI hook for the named or active assistant | Supported prompt and tool events |

Use the stage, the assistant, and the scope that the user specified. Ask only for a missing choice. For a bare "install hooks" request, ask which hook family the user wants. An explicit installation request authorizes its stated scope. A recommendation request or a scan request does not authorize an installation. A global installation needs explicit authorization.

## Onboarding (first use)

### Prerequisites

Before an installation, check:

- `ggshield --version`
- the `--help` output of the relevant command
- `ggshield api-status` for authentication
- the target assistant, when the request names one

Do not repeat a check that already passed in this context.

### Setup

If the CLI is missing or not authenticated, read [ggshield-cli-setup.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/references/ggshield-cli-setup.md). Otherwise, continue.

## Commands

Read the relevant section of [hook-selection.md](https://skilld.dev/api/skills-raw/gitguardian/agent-skills/install-hooks/references/hook-selection.md) when you check, install, or repair protection. It covers the effective Git hook paths, existing hook managers, and scoped AI hook installation. Do not read it again for a routine operation that it already covered.

After an installation, check the configuration. Do not run a test scan. Do not create a test secret, a test commit, or a test push. Report "configured" and "ran and passed" as two different states. The next authorized operation runs the hook and gives the "ran and passed" result.

## Best Practices

- Keep existing hook managers and existing secret protection. A hook that only runs a linter is not secret protection.
- Do not add manual scans next to a hook. Do not bypass a hook failure. Do not report a skipped or failed check as clean. For an explicit scan, use `scan-secrets` when it is available.
- When a hook finds a secret, report the secret type and location. Do not show the secret value. Show the organization's remediation message first, when one exists. Determine if the secret was exposed. A blocked commit or push does not prove that the secret never leaked elsewhere. If the secret is only local, remove it, including from unpushed commits. If the secret was exposed, coordinate a rotation. The same hook checks the next authorized retry. If `scan-secrets` is installed, it contains detailed remediation guidance.

## Troubleshooting

If a hook does not run, check the effective hook paths, the hook manager dispatch, the enabled events, the authentication, and the project trust settings. The hook-selection reference describes each check. An AI scan error can let an unscanned action continue. To uninstall, remove only the ggshield entries, through the hook manager that owns them. Keep the other hooks.
