PreToolUse

A pre-action check that runs before an agent uses certain command-line, file-reading, or file-search tools. It can add instructions based on the action being attempted.

In plain words
What is it for?
Enforcing rules before Bash, Read, or Glob calls, guiding source-code searches through a project graph, and adding warnings or instructions to tool use.
Why use it?
It can require the agent to follow project-specific checks before searching or changing things, reducing skipped steps.

Hook for Claude Code

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/bdfinst/agentic-dev-team/pre-tool-use
Clone the repo
git clone --depth 1 https://github.com/bdfinst/agentic-dev-team

Made for: Claude Code.

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 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Security

Grade A, and why

PreToolUse scanned grade A with 0 findings 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 2d 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/settings.json · 22 lines

How it starts

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

{
  "PreToolUse": [
    {
      "matcher": "Bash",
      "hooks": [
        {
          "type": "command",
          "command": "python3 -c \"import json,os,re,sys\nd=json.load(sys.stdin)\ncmd=str(d.get('tool_input',d).get('command','')).lower()\ntokens=set(re.split(r'[^a-z0-9._/-]+',cmd))\nsearch={'grep','egrep','fgrep','zgrep','rg','ripgrep','ack','ag'}\nfindbin={'find','fd'}\nfindflag={'-name','-iname','-regex','-path'}\nexclude=('node_modules','package.json','package-lock.json','yarn.lock','pnpm-lock.yaml','.git/','graphify-out/','dist/','build/','coverage/','.venv','__pycache__')\nhit=(bool(tokens&search) or (bool(tokens&findbin) and bool(tokens&findflag))) and not any(e in cmd for e in exclude) and os.path.isfile('graphify-out/graph.json')\nif hit:\n    print(json.dumps({'hookSpecificOutput':{'hookEventName':'PreToolUse','additionalContext':'MANDATORY: graphify-out/graph.json exists. You MUST run graphify query <question> before grepping raw source files. Only grep after graphify has oriented you, or to modify/debug specific lines. (Skipped for lockfiles/manifests, node_modules, VCS metadata, and build/coverage output.)'}}))\" 2>/dev/null || true"
        }
      ]
    },
    {
      "matcher": "Read|Glob",
      "hooks": [
        {
          "type": "command",
          "command": "HIT=$(python3 -c \"import json,sys;d=json.load(sys.stdin);t=d.get('tool_input',d);exts=('.py','.js','.ts','.tsx','.jsx','.astro','.vue','.svelte','.go','.rs','.java','.rb','.c','.h','.cpp','.hpp','.cc','.cs','.kt','.swift','.php','.scala','.lua','.sh','.md','.rst','.txt','.mdx');exclude=('graphify-out/','node_modules/','dist/','build/','coverage/','.venv/','__pycache__/','package-lock.json','yarn.lock','pnpm-lock.yaml');vals=[str(t.get('file_path') or ''),str(t.get('pattern') or ''),str(t.get('path') or '')];j=' '.join(vals).lower().replace(chr(92),'/');tails=[('.'+x.rsplit('.',1)[-1]) for v in vals if v for x in [v.lower().replace(chr(92),'/').rsplit('/',1)[-1]] if '.' in x];sys.

Read the full file on GitHub · 22 lines

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. 2d ago First seen · 22 lines scan A c684c9ead3e4

Subscribe to this mod's changes

PreToolUse is a hook published in the GitHub repository bdfinst/agentic-dev-team (277 stars, last pushed yesterday), 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 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.