tool-call-hygiene
Choose between Bash and dedicated Claude Code tools (Grep/Glob/Read/Edit) and edit files efficiently. Triggers on intent to grep/find/cat/sed/rg, multiple sequential reads, session-start context restore, codebase discovery, or multiple sequential Edits to one file.
- License 许可
- MIT
- 所属仓库
- muratovv/ai-hats
- 最近更新
- 2026-11-05
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- tool-call-hygiene
- ai_hats
- { "type": "skill", "schema_version": 1 }
- license
- MIT
- description
- Choose between Bash and dedicated Claude Code tools (Grep/Glob/Read/Edit) and edit files efficiently. Triggers on intent to grep/find/cat/sed/rg, multiple sequential reads, session-start context restore, codebase discovery, or multiple sequential Edits to one file.
02 资源文件 5
- 脚本hooks/bypass_journal.py35 B
- 脚本hooks/bypass_journal.sh35 B
- 参考文档hooks/test_runners.json35 B
- 脚本hooks/tool_call_hygiene_guard.sh15.7 KB
- 参考文档references/examples.md801 B
03 SKILL.md 正文
Tool-Call Hygiene
Decide between Bash and dedicated Claude Code tools. Batch and parallelize.
When to Use
- About to call Bash for anything a dedicated tool expresses —
grep/rg/find/ls -R/cat/head/tail/sed/awkand equallybat/fd/eza/git grep - Restoring context at session start (multiple Reads/Greps/Globs)
- Initial codebase exploration (>3 tool calls planned)
- Noticing 5+ similar sequential calls
- About to make 3+ Edits to the same existing file (consider one Write)
Conventions
Forbidden Bash anti-patterns
The test is whether a dedicated tool expresses the operation, not whether
the binary appears below. A newer or fancier spelling of a listed row (bat
for cat, fd for find, eza -R for ls -R, git grep for grep,
sed -n '10,40p' for head) is the same violation.
| ❌ Bash | ✅ Use instead | Why |
|---|---|---|
grep -rn PATTERN path/ |
Grep tool | Native, faster, no shell parse |
rg PATTERN path/ |
Grep tool | Same — Grep wraps ripgrep |
find . -name "*.py" |
Glob tool | Glob handles patterns natively |
ls -R dir/ |
Glob tool | Recursive listing without shell |
cat path/file.md (known path) |
Read tool | Numbered output, no truncation surprises |
head -50 file / tail -100 file |
Read with offset/limit |
Same data, paginated cleanly |
sed -i 's/A/B/' file |
Edit tool | Edit checks uniqueness; prevents silent multi-replace |
awk -i ... / inline rewrite |
Edit / Write | See above |
When the right column is not on offer
The right column assumes the tool exists in this session. Not every session carries every tool, and a tool you do not have is not a tool you are refusing to use — there the left column is the correct call.
Establish absence, never assume it. It counts as absent when it is missing from your available tool set, or when calling it comes back no such tool available. It does NOT count as absent because a search returned nothing, the pattern got awkward, or the shell felt faster — those are reasons to fix the query, not to abandon the tool.
A fallback tightens the budget. Raw output arrives unstructured and costs the context a dedicated tool would have saved, so batch what you would have issued singly, scope each command tighter than the tool call it replaces, and treat a run of one-off shell searches as the smell Batching and parallelism below already names.
Bash is appropriate for: git, pytest, build commands, multi-stage pipes that have no dedicated alternative, anything reading shell-only state (env vars, processes, exit codes).
Batching and parallelism
- Session-entry: independent context reads → a single parallel tool block, never one-by-one.
- Parallel by default: any independent calls → single batch.
- Combine shell checks: merge with
&&(e.g.git status && git log --oneline -5). - 5-call threshold: 5+ similar sequential calls → STOP, batch or use a more targeted tool.
- Discovery budget: initial codebase exploration ≤ 3–5 tool calls; broader →
Agent(Explore).
Edit efficiency
- New file → Write, not a sequence of Edits — building a fresh file with incremental Edits wastes turns.
- 3+ Edits to the same existing file → STOP; plan all changes and Write it once.
- Edit is surgical: targeted, isolated changes to existing files. Read → plan all edits → execute in the fewest operations.
For ❌/✅ worked examples → references/examples.md.
Anti-Patterns
- Reaching for
rg/grepfrom Bash when Grep tool fits. - Sequential Reads when reads are independent — always parallel.
- Drilling into a codebase via shell
ls/findinstead of oneAgent(Explore)call.
04 同仓库更多 Skills
tool-evaluation-protocol
Time-bounded protocol for evaluating new tools, libraries, or methodologies before adoption. Use when evaluating a candidate dependency for the project, researching a methodology (e.g. ML/LLM frameworks, testing approaches), or following up on a hype-driven recommendation.
systematic-debugging
4-phase bug-fix protocol (evidence, pattern, hypothesis, verify). Use when investigating any error, failure, or unexpected behavior, handling bug reports from users or monitoring, or diagnosing test failures with non-obvious causes.
skill-template
Canonical template and validation guide for ai-hats skills. Use when creating a new skill, reviewing an existing one for structural compliance, or deciding which pattern fits a new behavior.
skill-optimization
Audit and refactor library components to eliminate redundancy and staleness. Use during periodic library maintenance, after adding multiple new skills or rules, when a role's token budget is too high, or after retrospectives identify component issues.
silent-fallback-gate
PreToolUse hook — refuses an Edit or Write that adds an inert broad except. Use when a Python edit was blocked for a silent fallback.
retro-to-framework
Convert an observation about agent behavior — from a retrospective or from a single incident — into a framework-level change (hook, rule, skill, skill update). Use after a retrospective identifies problems that are not project-specific, after an incident where an agent misapplied a component it had read, when CLAUDE.md band-aids accumulate (more than 3 per-project rules that could be generic), or when the same problem recurs across multiple projects.