acus9345

Diffcap — AI skill for Claude Code

AI community

Cap how much an AI coding agent changes before a human looks: a Claude Code PreToolUse hook (and CLI / CI check) that asks or blocks once the working tree passes N changed lines or M files, from git d.

How to install Diffcap

This entry records only its repository, not the path inside it, so there is no exact command to give. Open acus9345/diffcap and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

What Diffcap does

Cap how much an AI coding agent changes before a human looks: a Claude Code PreToolUse hook (and CLI / CI check) that asks or blocks once the working tree passes N changed lines or M files, from git diff --numstat. Cross-platform, zero dependencies.

Alternatives in AI

  • Tokentab — A CLI that reads Claude Code, Codex, and Gemini CLI session logs and works out how much they cost, by model, p 226 ★
  • Claude Code Sourcemap Learning Notebook — Reverse-engineering Claude Code's 512K+ lines of TypeScript — architecture, design decisions, and 11 transfera 160 ★
  • Cost — AI Build Cost Tracker — track how much AI costs per feature, task, and project 63 ★

README

diffcap

**Cap how much an AI coding agent changes before a human looks.** Unlike commit-time or after-edit diff-size checks (blog recipes, yurukusa's `diff-size-guard`), diffcap stops the edit *before* it lands.

Agents make reviewable changes right up until they don't. One "while I'm here" refactor later you are staring at 1,800 changed lines across 40 files. `diffcap` is a Claude Code `PreToolUse` hook that checks each edit before it happens. If the edit would push the work tree past *N changed lines or M files* since the last commit, the agent has to stop and ask you, or split the work:

$ diffcap init --write        # adds the hook to .claude/settings.json
diffcap: the work tree would reach 438 changed lines (cap 400) since the last commit. Allow this edit to src/api/client.ts anyway?
  ❯ Yes   No

The same binary is a CI or git-hook check:

$ diffcap --max-lines 400
diffcap: 612/400 ✗ lines, 9/15 files changed since HEAD  over the cap
     +401 -12  src/api/client.ts
      +88 -40  src/api/types.ts
      ...
  (not counted: package-lock.json)
$ echo $?
1

Why it's new

Today the options are a line in CLAUDE.md ("keep changes small"), which the model may ignore, or a copy-paste bash recipe. Those recipes either check the staged diff when the agent runs `git commit`, which is after the damage is done, or they print an advisory after each write (PostToolUse). `diffcap` takes a different approach:

  • Projects the size before the write. Work tree size (git diff --numstat HEAD, plus untracked files) + the estimated line delta of the pending Edit / MultiEdit / Write / NotebookEdit. The estimate reads the existing file, so a Write that rewrites a file counts changed lines, not file length, and replace_all is multiplied by the number of occurrences.
  • Three modes:
    • ask: you confirm in Claude Code.
    • deny: the agent is told to stop, summarize and checkpoint.
    • warn: context is injected fo