PreToolUse

PreToolUse is a hook for Claude Code from go-to-k/cdkd. Its token cost is not measured, scanned A, a copy of SessionStart, Apache-2.0.

A set of checks that runs before an AI coding agent uses tools such as Bash, Edit, Write, and NotebookEdit. It executes project scripts that check branch rules, markers, merges, integrations, and reviews.

In plain words
What is it for?
It is for enforcing repository policies before shell commands and file edits run, including branch protection, integration checks, schema migration checks, and pull-request review gates.
Why use it?
It helps stop tool actions that violate the project's workflow rules. These checks can catch unsafe branch changes or missing approval markers before work proceeds.

Hook for Claude Code

One of 5 entries in settings.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/go-to-k/cdkd/pre-tool-use
Clone the repo
git clone --depth 1 https://github.com/go-to-k/cdkd

Made for: Claude Code.

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/go-to-k/cdkd/pre-tool-use.svg)](https://agentmods.dev/hooks/go-to-k/cdkd/pre-tool-use)
Your own site
<a href="https://agentmods.dev/hooks/go-to-k/cdkd/pre-tool-use"><img src="https://agentmods.dev/badge/hooks/go-to-k/cdkd/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 0 findings. Scan, not verified.
Origin 45% copy Near-identical to another mod 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 yesterday.

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.

Origin

This is a copy

45% identical to SessionStart — 242 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

.claude/settings.json · 247 lines

How it starts

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

{
  "PreToolUse": [
    {
      "matcher": "Bash",
      "hooks": [
        {
          "type": "command",
          "command": "${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/branch-gate.sh",
          "timeout": 10,
          "statusMessage": "Checking current branch..."
        },
        {
          "type": "command",
          "command": "${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/main-tree-branch-gate.sh",
          "timeout": 10,
          "statusMessage": "Checking main-tree branch-switch policy..."
        },
        {
          "type": "command",
          "command": "${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/post-merge-orphan-push-gate.sh",
          "timeout": 10,
          "statusMessage": "Checking for already-merged PR on this branch..."
        },
        {
          "type": "command",
          "command": "${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/check-gate.sh",
          "timeout": 10,
          "statusMessage": "Checking /check marker..."
        },
        {
          "type": "command",
          "command": "${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/integ-destroy-gate.sh",
          "timeout": 10,
          "statusMessage": "Checking integ-destroy marker..."
        },
        {
          "type": "command",
          "command": "${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/integ-local-gate.sh",
          "timeout": 10,
          "statusMessage": "Checking integ-local marker..."
        },
        {
          "type": "command",
          "command": "${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/integ-broad-gate.sh",
          "timeout": 10,
          "statusMessage": "Checking integ-broad marker..."
        },
        {
          "type": "command",
          "command": "${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/integ-schema-migration-gate.sh",
          "timeout": 10,
          "statusMessage": "Checking integ-schema-migration marker..."
        },
        {
          "type": "command",
          "command": "${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/pr-review-gate.sh",
          "timeo

Read the full file on GitHub · 247 lines

Same file

What else settings.json configures

This page is one entry in a file that holds 5. 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. yesterday Changed · +6 lines 79d381df0bd6
  2. 5d ago First seen · 241 lines scan A ca5a3206c87d

Subscribe to this mod's changes

PreToolUse is a hook published in the GitHub repository go-to-k/cdkd (132 stars, last pushed today), licensed Apache-2.0. 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. It is 45% identical to SessionStart, differing in 242 lines, and is treated as a copy.