AIDive

वीडियो पैक

Claude Code के पाँच रूल्स जो वह छोड़ नहीं सकता: hooks, deny list और lint config

7 मिनट पढ़ें

TL;DR और निष्कर्ष

हमने अपनी छोटी TypeScript invoicing API (Claude Code 2.1.294, Opus 5.5, auto mode) पर Claude Code को असली features दिए और नतीजे को copy-paste detector, typecheck और टेस्ट से जाँचा। फिर हर रूल के लिए एक enforcer लगाया: एक hook या एक setting, CLAUDE.md की कोई पंक्ति नहीं।

  • पाँचों रूल्स CLAUDE.md में गद्य के रूप में लिखे होने पर feature A (credit notes) ने उनमें से कोई नहीं तोड़ा: 0 clones, 45 टेस्ट पास (34 baseline और 11), कोई टेस्ट नहीं मिटा और कोई config नहीं छुआ गया।
  • कोई रूल न लिखने पर feature B1 (recurring schedules और एक CSV export) ने 3 exact clones छोड़े। invoice body parser को schedule parser में कॉपी किया गया, और एक handler का lookup boilerplate दूसरे handler में। Typecheck हरा था और 47 टेस्ट पास हुए। दूसरे चरण B2 ने तीनों clones वैसे ही छोड़ दिए।
  • enforcers लगाकर हमने वही prompts दोबारा चलाए। clone hook schedules handler पर चला (jscpd को 1 clone मिला, baseline 0) और Claude ने साझा check को एक method में ले जाया। new-file hook ने schedule modules के लिए तीन permission prompts उठाए, जिनका जवाब हाँ रहा, और एक utils फ़ाइल के लिए, जिसका जवाब ना रहा, और कुछ नहीं लिखा गया। enum और interface वाले prompt पर Claude ने कुछ edit नहीं किया और lint config तथा hook का नाम बताया। stop hook ने shell command से किए गए rename को "Rule 4: tests fail. Not done yet." कहकर ठुकराया और Claude ने दो अपेक्षाएँ ठीक कीं। tsconfig.json पर shell command को harness ने अस्वीकृत किया।
  • हर enforcer को हाथ से बनाया खराब edit भी दिया गया: clone, lint उल्लंघन, red build और मिटाया गया टेस्ट, सब ठुकराए गए।

निष्कर्ष: पहले stop hook लगाएँ, फिर deny list, जो छोटी है। throwaway prototype पर यह सब छोड़ दें। hook वही लागू करता है जो एक tool call दिखा सके। कोई abstraction सही है या नहीं, यह आपका फ़ैसला रहता है।

स्रोतों पर आधारित संश्लेषण

CLAUDE.md context है, enforced configuration नहीं। Claude Code के memory docs कहते हैं कि CLAUDE.md और rules context के रूप में लोड होते हैं, enforced configuration के रूप में नहीं s2। best practices पेज दूसरी तरफ़ से यही कहता है: CLAUDE.md दिशानिर्देशों के लिए है, और Claude तय कर सकता है कि कोई लागू नहीं होता। अनिवार्य व्यवहार hook, deny rule या managed setting में रहता है s1।

इससे निर्देश दो तरह के हो जाते हैं। पहली तरह में आप एक पंक्ति लिखते हैं और मॉडल उसे पढ़ता है: एक prompt, CLAUDE.md, एक skill। दूसरी तरह में आप एक check configure करते हैं और harness उसे चलाता है: एक hook, एक deny rule, एक managed setting s1। इस pack के पाँचों रूल्स दूसरी तरह के हैं।

Exit 2 हर hook event पर अलग काम करता है। PostToolUse पर, exit 2 stderr को Claude को दिखाता है, भले tool पहले ही चल चुका हो s3। PostToolUse की चेतावनी को Claude तक पहुँचने के लिए exit 2 करना होगा, क्योंकि exit 0 करने वाले hook का stderr कभी देखा नहीं जाता s3। PreToolUse पर, exit 2 call को रोक देता है, भले hook ने allow decision print किया हो s3। Stop पर, exit 2 stop को रोकता है, और command जो कुछ stderr पर print करे वह Claude को इस कारण के रूप में लौटता है कि वह अभी खत्म नहीं कर सकता s1।

Stop hook को एक guard चाहिए और उस पर एक सीमा है। Stop hooks को stop_hook_active मिलता है, जो तब true होता है जब Claude पहले से किसी stop hook की वजह से जारी है, इसलिए ऐसी शर्त पर रुकने से बचने के लिए उसे जाँचें जो कभी हल नहीं होगी s3। documented guard उसके true होने पर 0 से exit करता है s18। Claude Code लगातार 8 continuations की सीमा भी लगाता है, जिसे CLAUDE_CODE_STOP_HOOK_BLOCK_CAP से बढ़ाया जाता है s3। 2.1.143 का changelog कहता है कि लगातार 8 blocks के बाद turn अब एक चेतावनी के साथ खत्म होता है s19।

PreToolUse के चार decisions हैं। PreToolUse hook अपना decision hookSpecificOutput में चार नतीजों के साथ लौटाता है: allow, deny, ask या defer s3। इस pack का new-file hook ask कहता है, जो आपको permission prompt के रूप में loop में वापस लाता है। जिस PreToolUse hook का timeout हो जाए वह call को नहीं रोकता। 2.1.295 से आप उसे रोकने वाला बनाने के लिए onFailure: "block" सेट कर सकते हैं s3 s19।

matcher का एक अंधा कोना है। Edit|Write matcher सिर्फ़ Edit और Write tools पर चलता है, Bash पर नहीं s18। Bash से किए गए edits 2.1.269 से bashEditDiffEnabled setting के पीछे PostToolUse hook में tool_response.bashEditDiff के रूप में पहुँच सकते हैं s3 s19।

Deny rules: Edit(path) इस्तेमाल करें, और सीमा जानें। Write(path) deny rule मेल नहीं खाता। Edit(path) इस्तेमाल करें, जो सभी built-in file-editing tools को कवर करता है s4। Deny rules उस Python या Node script को भी कवर नहीं करते जो फ़ाइल को खुद खोलती है s4।

Path-scoped rules, और frontmatter का जाल। path-scoped rule तब लोड होता है जब Claude किसी मेल खाती फ़ाइल पर Read, Write या Edit इस्तेमाल करता है s2। 2.1.288 से पहले केवल Read उन्हें लोड करता था s19। अगर markers के बीच का YAML parse न हो, तो Claude Code frontmatter को अनदेखा करता है और रूल को ऐसे लोड करता है मानो उसमें paths हो ही नहीं, यानी वह हर जगह लागू होता है s2।

jscpd सिर्फ़ exact clones पकड़ता है। npx jscpd . के रूप में चलाने पर वह clones के लिए scan करता है। डिफ़ॉल्ट runs सिर्फ़ exact clones बताते हैं, और नाम बदले या लगभग मिलते clones वैकल्पिक हैं s20। डिफ़ॉल्ट न्यूनतम clone आकार 50 tokens है s20। हमारा hook उसे 30 tokens और 4 lines पर ले आता है। हमारे टेस्ट में, अलग लाइनों और उसी व्यवहार वाली दोबारा लिखी गई लगभग-कॉपी पकड़ी नहीं गई।

हर edit पर gates क्यों, लंबी CLAUDE.md क्यों नहीं। SlopCodeBench ने पाया कि सबसे अच्छा agent 14.8% checkpoints पास करता है। यह pass rate है, slop का हिस्सा नहीं। संरचनात्मक क्षरण 77% trajectories में और verbosity 75.5% में बढ़ती है s6। Agent का कोड 473 open-source Python repositories के मुकाबले 2.3 गुना ज़्यादा verbose और 2.0 गुना ज़्यादा क्षरित है s6। स्पष्ट गुणवत्ता मार्गदर्शन शुरुआती verbosity और क्षरण को एक तिहाई तक घटाता है, बिगड़ने की दर पर असर डाले बिना s6। मार्गदर्शन शुरुआत में मदद करता है। हर edit पर लगा gate ढलान पर काम करता है।

वह stop hook जो "कुछ नहीं करता"। "Claude is ignoring stop hooks" नाम का एक Hacker News thread एक ऐसी script दिखाता है जो cat पर exit 0 के साथ खत्म होती थी। harness ने कभी कुछ नहीं रोका, क्योंकि रोकने के लिए stderr पर कारण के साथ exit 2 चाहिए s8।

hook क्या नहीं परख सकता। CLAUDE.md के रूल्स न माने जाने पर Claude Code का एक issue PreToolUse hooks को आंशिक अस्थायी उपाय कहता है। hook वही लागू करता है जो एक tool call दिखा सके। "क्या यह सही abstraction है?" इसे hook तय नहीं कर सकता, और अगर आप hook बंद कर दें तो व्यवहार लौट आता है s7।

कोड

इंस्टॉल नोट: settings.json को .claude/settings.json में रखें, चारों hook scripts को .claude/hooks/ में, domain.md को .claude/rules/domain.md में, और eslint.config.js को repo root में। eslint, typescript-eslint और jscpd को devDependencies के रूप में जोड़ें। दो baseline फ़ाइलें बनाएँ: .claude/jscpd-baseline (clones की गिनती) और .claude/test-baseline (पास होते टेस्टों की संख्या)। hooks jq इस्तेमाल करते हैं, और stop hook pnpm typecheck और pnpm test बुलाता है, इसलिए वे scripts आपके package.json में होनी चाहिए।

settings फ़ाइल में रूल 5 की deny list (tsconfig.json, vitest.config.ts, eslint.config.js और .claude/**) और रूल्स 1 से 4 की hook entries हैं। इसे .claude/settings.json में रखें।

settings.json

{
  "permissions": {
    "deny": [
      "Edit(tsconfig.json)",
      "Edit(vitest.config.ts)",
      "Edit(eslint.config.js)",
      "Edit(.claude/**)"
    ]
  },
  "hooks": {
    "PreToolUse": [
      { "matcher": "Write", "hooks": [ { "type": "command", "command": "bash \"$CLAUDE_PROJECT_DIR/.claude/hooks/new-file-ask.sh\"", "timeout": 10 } ] }
    ],
    "PostToolUse": [
      { "matcher": "Edit|Write", "hooks": [ { "type": "command", "command": "bash \"$CLAUDE_PROJECT_DIR/.claude/hooks/no-clone.sh\"", "timeout": 60 } ] },
      { "matcher": "Edit|Write", "hooks": [ { "type": "command", "command": "bash \"$CLAUDE_PROJECT_DIR/.claude/hooks/lint-edit.sh\"", "timeout": 60 } ] }
    ],
    "Stop": [
      { "hooks": [ { "type": "command", "command": "bash \"$CLAUDE_PROJECT_DIR/.claude/hooks/done-check.sh\"", "timeout": 120 } ] }
    ]
  }
}

settings.json on GitHub

रूल 1, लिखने से पहले दोबारा इस्तेमाल करें। Edit|Write पर एक PostToolUse hook। यह .ts फ़ाइल के हर edit के बाद src/ पर jscpd चलाता है, clones की गिनती की तुलना baseline से करता है, और गिनती बढ़ने पर जुड़वाँ कोड की जगह के साथ 2 से exit करता है। इसे .claude/hooks/no-clone.sh में रखें।

no-clone.sh

#!/usr/bin/env bash
# PostToolUse hook (matcher: Edit|Write). Rule 1: reuse before you write.
# Runs the copy-paste detector on src/ after every edit. A clone that was not
# there at the baseline blocks with the twin's location (exit 2 -> stderr reaches Claude).
set -u
INPUT=$(cat)
FILE=$(printf '%s' "$INPUT" | jq -r '.tool_input.file_path // empty')
case "$FILE" in *.ts) ;; *) exit 0 ;; esac
cd "$(printf '%s' "$INPUT" | jq -r '.cwd')" || exit 0
BASE=$(cat .claude/jscpd-baseline 2>/dev/null || echo 0)
OUT=$(mktemp -d)
npx --no-install jscpd src --min-lines 4 --min-tokens 30 --reporters json --output "$OUT" --silent >/dev/null 2>&1
COUNT=$(jq '.statistics.total.clones // 0' "$OUT/jscpd-report.json" 2>/dev/null || echo 0)
if [ "$COUNT" -gt "$BASE" ]; then
  echo "Rule 1 (reuse before you write): jscpd found $COUNT clone(s), baseline is $BASE. A helper you just wrote already exists:" 1>&2
  jq -r '.duplicates[] | "  \(.firstFile.name):\(.firstFile.start)-\(.firstFile.end)  ==  \(.secondFile.name):\(.secondFile.start)-\(.secondFile.end)"' "$OUT/jscpd-report.json" 1>&2
  echo "Import and reuse the existing one; do not keep both." 1>&2
  rm -rf "$OUT"; exit 2
fi
rm -rf "$OUT"; exit 0

no-clone.sh on GitHub

रूल 2, ऐसा कोई module नहीं जो किसी ने माँगा न हो। Write पर एक PreToolUse hook। जब path src/ के अंदर हो और फ़ाइल अभी मौजूद न हो, तो यह कारण के साथ ask कहता है, और Claude Code permission prompt दिखाता है। इसे .claude/hooks/new-file-ask.sh में रखें।

new-file-ask.sh

#!/usr/bin/env bash
# PreToolUse hook (matcher: Write). Rule 2: no module nobody asked for.
# Creating a file that does not exist yet under src/ becomes a permission prompt:
# the human says yes or no, the model does not decide alone.
set -u
INPUT=$(cat)
FILE=$(printf '%s' "$INPUT" | jq -r '.tool_input.file_path // empty')
CWD=$(printf '%s' "$INPUT" | jq -r '.cwd')
case "$FILE" in "$CWD"/src/*) ;; *) exit 0 ;; esac
[ -e "$FILE" ] && exit 0
REL=${FILE#"$CWD"/}
jq -cn --arg r "Rule 2: new module under src/ ($REL). One new file needs a reason: approve only if the task asked for it, otherwise put the code in the module it belongs to." \
  '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"ask",permissionDecisionReason:$r}}'

new-file-ask.sh on GitHub

रूल 3, conventions lint हैं। Edit|Write पर एक PostToolUse hook जो edit हुई .ts फ़ाइल पर ESLint चलाता है और किसी भी error पर 2 से exit करता है। यह सिर्फ़ lint करता है, कभी ठीक नहीं करता। इसे .claude/hooks/lint-edit.sh में रखें।

lint-edit.sh

#!/usr/bin/env bash
# PostToolUse hook (matcher: Edit|Write). Rule 3: conventions are lint, not prose.
# Runs ESLint on the file that was just edited; a violation is a lint error at the
# exact line, every edit (exit 2 -> stderr reaches Claude). Lint only, never --fix.
set -u
INPUT=$(cat)
FILE=$(printf '%s' "$INPUT" | jq -r '.tool_input.file_path // empty')
case "$FILE" in *.ts) ;; *) exit 0 ;; esac
cd "$(printf '%s' "$INPUT" | jq -r '.cwd')" || exit 0
if ! npx --no-install eslint --no-warn-ignored "$FILE" 1>&2; then
  echo "Rule 3: the conventions above are enforced by eslint.config.js; fix the file, do not change the config." 1>&2
  exit 2
fi
exit 0

lint-edit.sh on GitHub

यह जो lint rules चलाता है: interface की जगह type, कोई enum नहीं, कोई any नहीं, src/domain/ में कोई I/O या store imports नहीं, और handlers में कोई सीधे store imports नहीं। फ़ाइल को repo root में रखें।

eslint.config.js

// Conventions as lint rules. Run on every edited file by .claude/hooks/lint-edit.sh.
import tseslint from "typescript-eslint";

export default [
  {
    files: ["src/**/*.ts", "test/**/*.ts"],
    languageOptions: { parser: tseslint.parser },
    plugins: { "@typescript-eslint": tseslint.plugin },
    rules: {
      "no-restricted-syntax": [
        "error",
        { selector: "TSInterfaceDeclaration", message: "Use `type`, never `interface` (project convention)." },
        { selector: "TSEnumDeclaration", message: "Use a const object or a union type, never `enum` (project convention)." },
      ],
      "@typescript-eslint/no-explicit-any": "error",
    },
  },
  {
    files: ["src/domain/**/*.ts"],
    rules: { "no-restricted-imports": ["error", { patterns: [
      { group: ["node:fs", "node:http", "fs", "http"], message: "src/domain has no I/O." },
      { group: ["../store/*", "../http/*", "**/store/*", "**/http/*"], message: "src/domain imports nothing from store or http." },
    ] }] },
  },
  {
    files: ["src/http/handlers/**/*.ts"],
    rules: { "no-restricted-imports": ["error", { patterns: [
      { group: ["../../store/*", "**/store/*"], message: "Handlers reach the store through the app context only." },
    ] }] },
  },
];

eslint.config.js on GitHub

conventions के शब्द एक path-scoped rule फ़ाइल में रहते हैं। यह तभी लोड होती है जब Claude src/domain/ को छुए। YAML header वैध रखें, वरना रूल हर जगह लोड होगा। इसे .claude/rules/domain.md में रखें।

domain.md

---
paths:
  - "src/domain/**"
---
# src/domain: pure functions, nothing else

- No I/O here: no `node:fs`, no `node:http`, nothing from `src/store/` or `src/http/`.
- `type`, never `interface`; const objects or union types, never `enum`; no `any`.
- Money is an integer number of cents; reuse `money.ts` (`assertCents`, `formatCents`, `sum`) instead of writing a new helper.
- One new file needs a reason the task gives. No class, factory or generic helper for one caller.
These conventions are checked by ESLint on every edit (`.claude/hooks/lint-edit.sh`).

domain.md on GitHub

रूल 4, पूरा होने का मतलब है checks पास होना। stop_hook_active guard वाला एक Stop hook। यह typecheck और टेस्ट चलाता है, पास होते टेस्टों की संख्या की तुलना .claude/test-baseline से करता है, और कुछ भी red होने या कोई टेस्ट गायब होने पर फ़ेल हुए output के साथ 2 से exit करता है। इसे .claude/hooks/done-check.sh में रखें।

done-check.sh

#!/usr/bin/env bash
# Stop hook. Rule 4: done means the checks passed.
# Refuses the end of the turn while typecheck or tests are red, or while the test
# count dropped under the baseline (a suite made green by deleting tests is red).
set -u
INPUT=$(cat)
# Guard: when Claude Code is already continuing because of this hook, let it stop.
[ "$(printf '%s' "$INPUT" | jq -r '.stop_hook_active')" = "true" ] && exit 0
cd "$(printf '%s' "$INPUT" | jq -r '.cwd')" || exit 0
# Nothing changed since the last commit: nothing to check.
[ -z "$(git status --porcelain -- src test 2>/dev/null)" ] && exit 0
LOG=$(mktemp)
if ! pnpm --silent typecheck > "$LOG" 2>&1; then
  echo "Rule 4: typecheck fails. Not done yet." 1>&2; tail -30 "$LOG" 1>&2; rm -f "$LOG"; exit 2
fi
if ! pnpm --silent test > "$LOG" 2>&1; then
  echo "Rule 4: tests fail. Not done yet." 1>&2; grep -v '^\s*$' "$LOG" | tail -30 1>&2; rm -f "$LOG"; exit 2
fi
BASE=$(cat .claude/test-baseline 2>/dev/null || echo 0)
COUNT=$(grep -oE 'Tests +[0-9]+ passed' "$LOG" | grep -oE '[0-9]+' | head -1)
rm -f "$LOG"
if [ -n "$COUNT" ] && [ "$COUNT" -lt "$BASE" ]; then
  echo "Rule 4: $COUNT tests passed, the baseline is $BASE. A test disappeared; restore it." 1>&2; exit 2
fi
exit 0

done-check.sh on GitHub

सोमवार को यह करें

  • claude --version चलाएँ और जाँचें कि आप 2.1.288 या बाद के version पर हैं, ताकि path-scoped rules Write और Edit पर लोड हों s19।
  • eslint, typescript-eslint और jscpd को devDependencies के रूप में install करें, और जाँचें कि jq आपके PATH पर है।
  • पहले done-check.sh कॉपी करें, अपनी मौजूदा पास होते टेस्टों की संख्या के साथ .claude/test-baseline बनाएँ, और .claude/settings.json में Stop entry जोड़ें।
  • अपने compiler config, test config, lint config और .claude/** के लिए Edit(...) पंक्तियों वाली permissions.deny list जोड़ें। Write(...) पंक्तियाँ न लिखें।
  • eslint.config.js कॉपी करें, अछूते repo पर npx eslint src चलाएँ, और hook जोड़ने से पहले जो मिले उसे ठीक करें या baseline में रखें।
  • npx jscpd src --min-lines 4 --min-tokens 30 चलाएँ, clones की गिनती .claude/jscpd-baseline में लिखें, फिर no-clone.sh और new-file-ask.sh जोड़ें।
  • domain.md को .claude/rules/ में कॉपी करें, path को अपने फ़ोल्डरों के अनुसार बदलें, और जाँचें कि YAML header parse होता है।
  • जिस हरकत के लिए हर रूल लिखा गया था उसे दोहराएँ और इनकार को पढ़ें। फिर एक फ़ाइल हाथ से edit करके साबित करें कि रूल चलता है।

मापन

हमारा run: 34 टेस्ट वाली एक छोटी TypeScript invoicing API, Claude Code 2.1.294, Opus 5.5, auto mode, 2026-11-07। Clones jscpd से --min-lines 4 --min-tokens 30 पर गिने गए।

Setup दिए गए Features jscpd को मिले Clones पास होते टेस्ट क्या चला
CLAUDE.md में गद्य के रूप में रूल्स A: credit notes (1 min 21 s) 0 45 (34 baseline + 11) चलाने को कुछ नहीं। कोई रूल नहीं टूटा
कोई रूल नहीं लिखा B1: recurring schedules और CSV export (2 min 27 s) 3 47 (34 + 13) कुछ install नहीं था। 3 नए modules, 14 फ़ाइलें बदलीं
कोई रूल नहीं लिखा B2: cancel endpoint और दो CSV exports (लगभग 1 min 30 s) 3, वही 55 कुछ install नहीं था। Claude ने src/http/csv.ts निकालकर दोबारा इस्तेमाल किया
Enforcers चालू, live replay फिर B1, फिर enum refactor, एक जल्दबाज़ी का rename, एक hook हटाना और एक tsconfig बदलाव अंत में 0 54 Clone hook एक बार (1 clone, baseline 0), 3 new-file prompts और 1 ठुकराया गया, lint hook की कभी ज़रूरत नहीं पड़ी, stop hook एक बार, deny एक बार
Enforcers चालू, mechanical test हाथ से बनाए खराब edits baseline पर 0, formatCents की 5-लाइन कॉपी चिपकाने के बाद 1 एक टेस्ट मिटाने के बाद 34 में से 33 Clone hook, new-file ask, lint hook (4 errors), stop hook (build red, टेस्ट गिनती baseline से कम)

mechanical test का ब्योरा। अछूते repo पर ESLint config ने 0 समस्याएँ दीं। node:fs import, एक interface, एक enum और एक any वाली फ़ाइल पर lint-edit.sh ने 4 errors उनकी लाइनों पर बताए और 2 से exit किया। clone hook ने domain/money.ts:21 == http/views.ts:5 बताया। src/ के नीचे ऐसे path ने जो मौजूद नहीं था कारण के साथ ask लौटाया। stop hook ने कहा "Rule 4: 33 tests passed, the baseline is 34. A test disappeared; restore it." दोबारा लिखी गई लगभग-कॉपी jscpd से नहीं पकड़ी गई।

आगे बढ़ें

हमने पाँच से जो बाहर रखा, और हर एक कहाँ फ़िट बैठता है।

Git hooks और Lefthook। वही checks चलाने के लिए git hook या pipeline gate एक वैध जगह है। वह commit के समय चलता है, Claude के edit करते समय नहीं, इसलिए feedback देर से आता है। यह इस pack से अलग setup है। अगर आपकी suite मिनटों लेती है, तो तेज़ हिस्सा stop hook में रखें और बाकी अपनी pipeline में ले जाएँ।

Agent-level prompt hooks। जो hooks किसी मॉडल से edit परखवाते हैं वे deterministic नहीं हैं, इसलिए वे पाँच में नहीं हैं। जिस रूल को आप command से जाँच सकते हैं, वह script में रहता है।

Review commands। /simplify और /code-review हाथ से चलाए जाते हैं। वे उपयोगी हैं, पर review आपके हाथ में रहता है, और उनमें से कोई enforcement नहीं है।

Vendor की incident संख्याएँ। हर pull request पर incident दरों की vendor रिपोर्टें एक correlation संकेत हैं, Claude Code के लिए विशिष्ट नहीं और हमारे कोड पर मापी हुई नहीं। हमने उनका इस्तेमाल नहीं किया। इस pack की हर संख्या ऊपर लिंक किए स्रोतों या हमारे अपने run से आती है।

तैयार ruleset। anti-slop repo एक vendored Oxlint ruleset है, जिसमें 18 सामान्य rules और 5 Effect rules हैं। उसे vendor करने के लिए बनाया गया है, कोई आधिकारिक npm package नहीं है s10। यह रूल का अच्छा नमूना है: ठीक उसी लाइन पर lint error, हर बार।

गद्य वाले रूल्स। CLAUDE.md रूल्स के संग्रह किसी convention के शब्दों के लिए उपयोगी हैं। उन्हें path-scoped rule फ़ाइलों में रखें, और गारंटी का काम किसी check को करने दें।

FAQ

क्या deny rule उस Python script को रोकता है जो फ़ाइल लिखती है? नहीं। Deny rules उस Python या Node script को कवर नहीं करते जो फ़ाइलें खुद खोलती है s4। जिसके पास चाबियाँ हैं वह अब भी फ़ाइल को हाथ से edit कर सकता है। deny list agent के built-in edit tools और साफ़ दिखते shortcuts को रोकती है।

मेरा stop hook कभी क्यों नहीं रोकता? पहले exit code जाँचें। रोकने के लिए stderr पर कारण के साथ exit 2 चाहिए। जो script cat पर exit 0 के साथ खत्म हो वह कभी नहीं रोकती s8। फिर guard जाँचें: अगर stop_hook_active true है, तो hook को 0 से exit करना चाहिए। सीमा भी लगातार 8 blocks के बाद turn खत्म कर देती है s3।

क्या Edit|Write matcher Bash edits पकड़ता है? नहीं। वह सिर्फ़ Edit और Write tools पर चलता है, Bash पर नहीं s18। 2.1.269 से, Bash command से बदली फ़ाइलों का diff bashEditDiffEnabled के पीछे Bash tool result में जोड़ा जा सकता है s19। हमारा stop hook फिर भी नतीजा पकड़ लेता है, क्योंकि वह turn के अंत में typecheck और टेस्ट चलाता है।

shell command से बनी फ़ाइलों का क्या? इस तरह बनी फ़ाइल Write tool call नहीं होती, इसलिए new-file hook उसे कभी नहीं देखता। अगर उस पर नज़र रखनी हो तो Bash matcher जोड़ें, या turn के अंत में git status देखें।

क्या hook edit को वापस लेता है? नहीं। PostToolUse hook tool के बाद चलता है, जो पहले ही चल चुका होता है। exit 2 के साथ वह stderr Claude को दिखाता है s3। फिर Claude फ़ाइल ठीक करता है। किसी कार्रवाई को होने से पहले सिर्फ़ PreToolUse hook और deny list रोकते हैं।

फ़ाइलें