CLAUDE.md with decision matrices, Bash hooks, and agentic workflow blocks reduces configuration time 50% and retry costs 30%.
The Technique — Three CLAUDE.md Patterns That Work
Claude Code's CLAUDE.md isn't just a project readme—it's the control center for your agentic coding workflow. Developers who treat it as a config file rather than documentation are seeing 50% faster setup and 30% fewer retry cycles. Here are three patterns that deliver immediately.
1. Decision Matrices for Migration Tasks
When migrating codebases, Claude Code often makes inconsistent choices. A decision matrix in CLAUDE.md eliminates ambiguity.
## Migration Decision Matrix
When migrating from Library A to Library B:
- If file imports `old_lib.utils`: rewrite to `new_lib.helpers`
- If file uses `old_lib.connect()`: replace with `new_lib.session()`
- If file has `old_lib.Config`: map to `new_lib.Settings`
- If uncertain: stop and ask user before proceeding
This pattern reduced migration errors by 40% in documented cases. It gives Claude Code explicit guardrails instead of relying on its training data.
2. Bash Hooks for Cost Control
Claude Code executes shell commands autonomously, which can spiral costs. Bash hooks let you intercept and validate commands before they run.
#!/bin/bash
# .claude/hooks/pre-exec.sh
# Block expensive operations
if [[ "$1" == "docker build"* ]] || [[ "$1" == "npm install --production"* ]]; then
echo "Blocked: $1 — requires manual approval"
exit 1
fi
# Log command for audit
logger "[Claude Code] Executing: $1"
Teams using this pattern cut their Anthropic bill by 50%. The hook runs before every shell execution, giving you a safety net against runaway commands.
3. Agentic Workflow Blocks
Define reusable task sequences that Claude Code can invoke with a single command.
## Workflows

### /deploy-staging
1. Run `npm run build`
2. Run `npm test`
3. If tests pass: `git tag staging-$(date +%Y%m%d)`
4. Run `npm run deploy:staging`
5. Verify health endpoint returns 200
6. If health check fails: rollback to previous tag
### /code-review
1. Diff current branch against main
2. Check for TODO/FIXME comments
3. Verify test coverage > 80%
4. Flag any direct database calls in controllers
5. Summarize findings as bullet list
Combine with /loop for long-horizon tasks. The agentic workflow block turns Claude Code from a question-answer tool into a process executor.
Why It Works — Token Economics and Context
Claude Code operates within a context window. Every ambiguous instruction costs tokens in clarification requests. Decision matrices pre-empt those questions, saving 8-15% of tokens per task according to community benchmarks.
Bash hooks work because Claude Code's default behavior is to execute commands greedily. By adding guardrails, you force the agent to ask permission before expensive operations, reducing wasted compute.
Agentic workflow blocks exploit Claude Code's /loop and multi-step reasoning. Instead of prompting step-by-step, you define the entire pipeline once. The agent executes it deterministically, with rollback logic built in.
How To Apply It — Step-by-Step
Create
.claude/hooks/directory withpre-exec.shandpost-exec.shscripts. Start with the cost control hook above.Add a decision matrix to your root
CLAUDE.mdfor the most error-prone task in your project (migration, refactoring, or dependency updates).Define 2-3 workflow blocks using the
/prefix convention. Test each withclaude -p "run /deploy-staging".Monitor retry frequency with
claude --statsbefore and after. Expect a 30-50% reduction in retries within the first week.Iterate by reviewing the agent's logs (
~/.claude/logs/) to see where it still gets confused, then tighten your decision matrix or add new hooks.
As Anthropic refines Claude Code's hook API in Q4 2026, expect native support for conditional rollback logic—but these patterns work today.
Source: harnishsavsani.medium.com
Originally published on gentic.news

Top comments (0)