cd /news/ai-agents/rules-feed-forward-hooks-feed-back · home › topics › ai-agents › article
[ARTICLE · art-180386] src=tacoda.medium.com ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Rules feed forward, hooks feed back

A developer audited the 25 rules and surrounding hooks in their coding agent's charter, finding that 86% of 118 checkable statements were enforced only by feedforward rules with no hook to catch violations. The audit concluded that no rule could be fully replaced by a hook, so 90 statements got a rule-plus-hook pairing and 28 stayed rule-only. The developer also fixed feature docs that never auto-loaded by adding a hook that injects them before Read, Edit and Write operations.

recommendation

Audit your agent's rules line by line, not file by file, and add a hook for every checkable statement while keeping the rule for the judgment a pattern can't see.

more in playbook: Working with AI coding agents
by read7 min views10 publishedDec 2, 2026

My charter is the rules and instructions my coding agent reads before it acts. In my last post, I moved its general craft into nWave, an open-source delivery framework for coding agents. That made the habitat stricter. By habitat I mean everything that shapes the agent except the model.

Then I audited what was left: 25 rules and the hooks around them. A rule works before the agent acts, and a hook works after. Most of my rules need both, and the audit showed how few of them had the second half.

A rule is feedforward. It loads into context before the agent writes anything, so it shapes the attempt. It’s also the only place the why can live, because a rule is prose and prose can explain.

A hook is feedback. It runs on what the agent just did, and it can refuse the result. When it refuses, it hands the agent a message, and the agent tries again with it.

You need both directions because each one fails where the other works. A rule can be ignored, since a model under a long context can drop a request. A hook can’t explain itself past one error message, and it only catches what a pattern can see. So the audit settled on one policy for the pair: keep the rule and add a hook. The rule carries the judgment, and the hook makes the checkable part fail loudly.

I audited the statements inside the rule files, one row per checkable line. Each row held the statement, how strict the rule says it is, its sensor (whatever checks it today), and a decision.

That came to 118 statements. Here’s how they broke down by sensor:

So 86% of what my charter told the agent was feedforward only. The agent read it, and if it got it wrong, nothing said so until a human noticed in review.

commits.md is the clearest case. It has seven iron laws, the statements the file marks as non-negotiable, and five of them had no sensor. One of those five is “no AI attribution in commits or PRs,” and the audit calls it the largest rule gap in the charter. Meanwhile, the commit-message hook checked the subject format and nothing else.

The audit had a bar for replacing a rule with a hook outright. The hook has to enforce everything the rule says, and its error message has to carry the why. If both are true, the rule file adds nothing, and you can delete it.

None of the 25 rules passed. Of the 118 statements, 90 got “rule + hook” and 28 got “keep rule only.” None got “replace with hook.” I expected that, because some things aren’t machine checkable. My “ports-and-adapters” hook is what tipped me off, because it pattern matches on implementation specific to my codebase. The hook is not an intent checker.

prohibited-patterns.md shows the split inside one file. It bans dd(), dump(), var_dump(), and print_r(), and a hook can check all four. The same rule bans a debug echo, but a pattern can’t tell a debug echo from a real one, so that line stays rule-only. The same file also says to eager-load and avoid N+1 queries. That one’s a runtime property, so no edit-time hook can see it. Its real sensor is turning on lazy- prevention in the test environment, which is a code change, not a hook.

So a single rule file holds three kinds of line. Some a hook can check, some only the rule can say, and some need a different sensor entirely. If you sort your rules by file, you miss that. Sort them by line.

My feature docs, the on-demand notes for one area of the app, carried paths: frontmatter, laid out exactly like my rules. I expected each doc to load when the agent touched a matching file. For months, none of them did, because Claude Code path-loads .claude/rules/ and nothing else.

I didn’t notice. Claude did: it saw that the charter claimed the docs auto-loaded, and that nothing loaded them.

The fix was a hook. load-feature-docs.sh runs before every Read, Edit, and Write. It matches the touched file against each doc’s paths: and injects the doc the first time it matches in a session. A doc over 9,000 characters goes in as a pointer the agent has to read, because Claude Code caps a hook’s context at 10,000 characters. make charter-hooks-test feeds it fixture payloads and checks that it loads on a match.

So a hook can deliver a rule, not only check one. Prose still needs a delivery path: something has to put the rule in front of the agent. If that something breaks, the rule is a file nobody reads.

The audit found eight conflicts, places where a rule contradicts the code or another part of the charter. Two of them are between a rule and its own hook.

security.md allows DB::raw() as long as it uses bindings. check-banned-tokens.sh bans DB::raw( outright. So the agent reads permission in the rule, then gets refused by the hook. Neither one mentions the other.

commits.md tells the agent not to run make pre-commit itself, because the git hook already runs it. The Stop hook runs make pre-commit on a dirty tree anyway.

Settle the conflict before you write the hook. Otherwise the hook enforces a rule nobody follows, and the agent learns that the charter contradicts itself. The audit ends in a list of proposed cards, each one a batch of hooks to build. Each card lists the conflicts it’s blocked on, and one card exists only to settle them.

Your codebase already breaks some of your rules. My test rule bans mocks, and tests/UseCase still has 272 mock hits, and eight migrations use cascadeOnDelete. A hook that scans whole files would block every edit to those files, and you’d turn it off.

So every new check reads only new content. On an edit, that’s the agent’s new text, and at commit it’s the added lines of the staged diff. A // charter:allow comment on one line lets a deliberate exception through and leaves a record of it. This works as a ratchet: the old code stays as it is, and every new line meets the rule.

Then pick the event by what it can see:

Today check-banned-tokens.sh runs only on agent edits, so a dd() a human types goes straight through. The proposed fix adds the same check to the git pre-commit hook, so it catches both.

Hooks can also ask instead of refuse. The rule against bypassing the git hook can’t be a hard block, because it allows a bypass on explicit user instruction. So the proposed check-git-command.sh returns ask on --no-verify, and I’d approve or deny it in the prompt.

A hook’s stderr goes straight back to the agent, so that message is the whole feedback signal. Make it name the rule.

check-commit-msg.sh does this. Its refusal says the subject doesn’t match Conventional Commits and lists the allowed types. Then it ends with See .claude/rules/commits.md. The agent gets refused and pointed back at the feedforward half in the same message. Without that last line, the agent knows it failed but not why the rule exists, and on the next edge case it guesses.

The obvious objection is the maintenance. More rules and more hooks mean more to keep current. The stricter habitat helps, because each rule now holds only what’s true here. It still drifts. Rules contradict each other, globs point at files that moved, and facts go stale.

Pruning on a cadence handles that. Ours is monthly. I think the right cadence depends on the team, the project, and how fast you’re moving, and a project that changes faster needs a shorter one. What matters is that drift and debt don’t pile up too much between passes.

The tools for pruning existed already: a lint script and two drift scanners. No gate ran any of them, and the two scanners always exited 0, so even a run that found drift reported success. A pruning tool nobody runs has the same problem as a rule with no hook. One proposed card wires them into the gate. It also gives the hooks a test target, because hooks drift too.

Pick one rule this week and sort its lines into three piles: a hook can check it, only the rule can say it, or it needs some other sensor. Write the hook for the first pile. Make it check added lines only, and make its message name the rule.

── more in #ai-agents 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/rules-feed-forward-h…] indexed:0 read:7min 2026-12-02 · —