PreToolUse

PreToolUse is a hook for coding agents from Dokkabei97/forged-claude-code. Its token cost is not measured, scanned A, original, MIT.

A pre-tool check that scans selected Git commands and attempts to prevent secrets from being committed, along with checks for unsafe environment-file writes.

In plain words
What is it for?
Use it before Git add, commit, or push operations and before writing environment files such as `.env` files.
Why use it?
It can catch common exposed credentials, tokens, private keys, and connection strings before they enter version control.

Hook

Part of the forged-claude-code plugin — 29 skills, 14 commands, 9 agents, 2 hooks shipped together

One of 2 entries in hooks.json — they are configured in one file and arrive together.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add hooks/dokkabei97/forged-claude-code/pre-tool-use
Clone the repo
git clone --depth 1 https://github.com/Dokkabei97/forged-claude-code

Or install forged-claude-code, the plugin that ships this one along with the rest of its 29 skills, 14 commands, 9 agents, 2 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for PreToolUse

README.md
[![agentmods](https://agentmods.dev/badge/hooks/dokkabei97/forged-claude-code/pre-tool-use.svg)](https://agentmods.dev/hooks/dokkabei97/forged-claude-code/pre-tool-use)
Your own site
<a href="https://agentmods.dev/hooks/dokkabei97/forged-claude-code/pre-tool-use"><img src="https://agentmods.dev/badge/hooks/dokkabei97/forged-claude-code/pre-tool-use.svg" alt="Measured on agentmods" height="20"></a>
Per session not measured What this adds to a session before it is invoked.
When invoked not measured Not applicable: nothing here is loaded into a session.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Security

Grade A, and why

PreToolUse scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the commands this hook runs, not an audit. A hook is shell that executes on your machine at the event it names, which is why every command in it is printed with what was found.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

"command": "node -e \"const{execSync}=require('child_process');let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>{const i=JSON.parse(d);const cmd=i.tool_input?.command||'';if(/git\\s+(commit|add)/.test
hooks/hooks.json · 25 lines

How it starts

The opening of the file, as written. The whole thing — 25 lines — stays where its author put it; the contents beside it link to each section on GitHub.

{
  "PreToolUse": [
    {
      "matcher": "tool == \"Bash\" && tool_input.command matches \"git (commit|push|add)\"",
      "hooks": [
        {
          "type": "command",
          "command": "node -e \"const{execSync}=require('child_process');let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>{const i=JSON.parse(d);const cmd=i.tool_input?.command||'';if(/git\\s+(commit|add)/.test(cmd)){try{const diff=execSync('git diff --cached --diff-filter=ACM',{encoding:'utf8',timeout:10000});const patterns=[{name:'AWS Access Key',re:/AKIA[0-9A-Z]{16}/},{name:'AWS Secret Key',re:/['\\\"][0-9a-zA-Z\\/+]{40}['\\\"]/},{name:'Generic API Key',re:/['\\\"]?(api[_-]?key|apikey|api[_-]?secret)['\\\"]?\\s*[:=]\\s*['\\\"][a-zA-Z0-9_\\-]{20,}['\\\"]/i},{name:'Private Key',re:/-----BEGIN (RSA |EC |DSA )?PRIVATE KEY-----/},{name:'Generic Secret',re:/['\\\"]?(secret|password|passwd|pwd|token|auth[_-]?token|access[_-]?token)['\\\"]?\\s*[:=]\\s*['\\\"][^'\\\"]{8,}['\\\"]/i},{name:'Database URL',re:/['\\\"]?(postgres|mysql|mongodb|redis):\\/\\/[^\\s'\\\"]{10,}/i},{name:'JWT Token',re:/eyJ[a-zA-Z0-9_-]{10,}\\.eyJ[a-zA-Z0-9_-]{10,}/},{name:'Slack Token',re:/xox[bpras]-[0-9a-zA-Z-]{10,}/},{name:'GitHub Token',re:/gh[ps]_[a-zA-Z0-9]{36,}/}];const found=[];patterns.forEach(p=>{if(p.re.test(diff)){found.push(p.name)}});if(found.length>0){console.error('[Secret Scanner] BLOCKED: Potential secrets detected in staged files!');found.forEach(s=>console.error('  - '+s));console.error('[Secret Scanner] Review staged changes and remove secrets before committing.');console.error('[Secret Scanner] Use .env files for secrets and ensure they are in .gitignore');process.exit(1)}else{console.error('[Secret Scanner] No secrets detected in staged changes.')}}catch(e){if(e.status===1){console.error('[Secret Scanner] '+e.message)}}}console.log(d)})\"",
          "timeout": 15000
        }
      ],
      "description": "Scans staged files for hardcoded secrets (API keys, tokens, passwords, private 

Read the full file on GitHub · 25 lines

Same file

What else hooks.json configures

This page is one entry in a file that holds 2. Installing the file brings all of them; each is measured and scanned on its own page.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 25 lines scan A 7c2d97c9c6ac

Subscribe to this mod's changes

PreToolUse is a hook published in the GitHub repository Dokkabei97/forged-claude-code (2 stars, last pushed 6mo ago), licensed MIT. Its token cost is not measured: a hook is shell that never enters the context. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.