Curious if you’ve leaned into lint / hooks to try to enforce the invariants you seek?
A recent talk from Poteto sketched some ideas here: https://m.youtube.com/watch?v=O_zcc6Xl12g
The importance of verification is well understood, but some of the ideas around API design were novel to me -
1) ban comments, they usually mean nuance was required, instead just make force the LLM to make the APIs more explicit. (Lints to ban comments at pre-commit and tell the LLM what to do instead.)
2) ban sketchy / confusing APIs from your language/framework.
I’m sure you’ve tried a bunch of this so I’d be interested in any concrete examples you can share, but it does sound like you’ve been trying to make Capabilities and strong typed APIs work, which is the right direction IMO.
I would have thought Claude hooks could prevent modifying particular bits of code though, from your list of issues above. And anything you can put in a lint will be resurfaced at the time the invariant is broken, rather than requiring the agent to remember CLAUDE.md line 336.
For any serious project I like the Hexagonal pattern of having CLI and API being two UI layers atop the same underlying Application layer, and then you can ban special-case scripting logic. I always found this architecture a bit too boilerplatey to use in small-to-medium projects but LLMs can do it well (and you can enforce the layer interfaces deterministically too).