Top 200 ReposEXPLORER
Browse agents, categories and pages
Back to results
Planned, not doneThe source describes an intention, not a finished result.

Inspect Every Git Commit for Secrets and Injection Flaws

Overview

A git pre-commit hook pipes the staged diff into Claude Code in non-interactive mode twice, once looking for leaked secrets and once for injection flaws, and stops the commit when either pass reports a finding.

Problem or Objective

More in Coding and Code Review

AI Agents and Models

Tools and Integrations

Tools
Claude Code · Git
Prerequisites
Claude Code installed and signed in on each developer machine, and a git repository where you can add a pre-commit hook.

How It Works

Install Claude Code and sign in. In your repository, write a pre-commit hook script that takes the staged changes with git diff --cached and pipes them into claude -p, so Claude reads the diff from standard input. Run two separate passes with short, strict prompts: the first lists anything that looks like an API key, password, token or private key, with file and line; the second lists places where user input reaches a database query, shell command, file path or HTML without escaping. Ask each pass to print the word CLEAN when it finds nothing, and have the script stop the commit when either output is anything else. Read the findings, fix real problems or explain a false alarm to yourself, and commit again. Keep the prompts in the repository so the whole team runs the same checks, and keep your normal tests and code review in place.

Implementation Workflow

Steps assembled from the agents, tools and prompt of this entry. Adapt them to your own setup.

  1. Choose the agentSet up Claude Code.
  2. Connect the toolsConnect the tools this workflow relies on: Claude Code, Git.
  3. Check the prerequisitesClaude Code installed and signed in on each developer machine, and a git repository where you can add a pre-commit hook.
  4. Gather your detailsCollect what the prompt asks for: Repository name, Extra patterns your team uses, Files where fake keys are allowed.
  5. Run the starter promptPaste the starter prompt below into Claude Code and adapt it to your case.
  6. Check against the documentationCompare what you get with the documentation at code.claude.com before you rely on it.

Practical Starter Prompt: Check a staged diff for leaked secrets

Fill the fields to adapt the prompt. Empty fields stay as visible [placeholders].

Preview
You are a strict security checker for the [Repository name] repository. The input is a git diff of staged changes. List every line that adds something that looks like a secret: API keys, passwords, tokens, private keys, connection strings with credentials, or values matching [Extra patterns your team uses]. For each one, print the file, the line and the kind of secret, but never repeat the secret itself. Ignore placeholders in [Files where fake keys are allowed]. If you find nothing, print only the word CLEAN. Do not change any file.

Call this from a pre-commit hook with git diff --cached piped into claude -p, and run a second pass with an injection-flaw prompt. The hook stops the commit on any output other than CLEAN; you read the findings and decide whether to fix or recommit.

Expected Results and Benefits

This is a suggested workflow, not a reported result. The points below are what the cited documentation says the tools can do.

This is a suggested workflow, not a reported outcome. The Claude Code docs document the -p flag for non-interactive runs, piping data in through standard input, and wrapping such a call in a script as a project-specific linter or reviewer that reads a git diff. No cited page measures how many secrets or injection flaws such a check finds or misses, so its accuracy is untested here.

Limitations and Considerations

The diff, including any secret it contains, is sent to the model provider when Claude reads it, so rotate any key the check finds even if you never push the commit. A model can miss problems and raise false alarms; treat this as an extra layer next to tests, code review and any dedicated secret scanner you already use. Each commit makes two model calls, which costs time and API usage. Piped input is capped at 10MB, so very large diffs need to be split. Results depend on your setup and were not independently reproduced by Top 200 Repos.

GitHub Repositories

AI Agent Repository

Source code of the agent that does the work.

Official Website

The official site of the main tool or project in this use case.

Visit Website (opens in a new tab)code.claude.com

Related Videos

About anthropics/claude-code

About anthropics/claude-code

Independent creators. Listing a video implies no endorsement, sponsorship or partnership.

Sources

  1. Run Claude Code programmatically - Claude Code Docs (opens in a new tab)

    Project documentation · code.claude.com · Undated · Source checked 26 Nov 2026, 17:27 UTC

    What this source supports
    • Add the -p (or --print ) flag to any claude command to run it non-interactively.
    • Non-interactive mode reads stdin, so you can pipe data in and redirect the response out.
    • You can wrap a non-interactive call in a script to use Claude as a project-specific linter or reviewer.
    • Piped stdin is capped at 10MB.
  2. anthropics/claude-code README (opens in a new tab)

    Project documentation · github.com · Undated · Source checked 25 Nov 2026, 11:59 UTC

    What this source supports
    • Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows -- all through natural language commands.
Report a problem

More with Claude Code

Planned, not done

Create Custom Store Tools Instead of Paying for Subscriptions

Use Claude Code to write small in-house tools for an online shop, such as a reply helper for support mail or a margin report, as an alternative to paying for separate apps, with testing before you rely on them.

code.claude.comanthropics/claude-code
Reported by source

Answer technical questions by letting async agents run experiments

Simon Willison sends research questions to cloud coding agents such as Claude Code for web and Codex Cloud, which write and run experiments in a dedicated repo and open a PR.

simonwillison.net · 6 Nov 2025anthropics/claude-code, openai/codex
Planned, not done

Structure Repeated Browser Research Into Evidence Tables

Give Claude Code the open-source Browser Use CLI with a local browser, ask the same research questions across a short list of pages, and keep every answer as a sourced table row.

github.comanthropics/claude-code, browser-use/browser-use

View all: Claude Code