[FEATURE] TypeScript interfaces as a structural enforcement mechanism for CLAUDE.md
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
I daily-drive Claude Code as a solo dev. My CLAUDE.md has behavioral instructions - things like "don't be sycophantic," "call me by name," "disagree when the evidence says so." In natural language, these instructions drift within a single session. Claude acknowledges them early on, then gradually reverts to defaults: agreeableness creeps back, "the user" replaces my name in thinking traces, and instructions I explicitly wrote get soft-interpreted or ignored outright. The longer the session, the worse it gets, and there's no signal that it's happening until the output is already wrong and my codebase suffers as a direct result.
The system prompt grants CLAUDE.md explicit override authority ("these instructions OVERRIDE any default behavior"), but the user-customizable CLAUDE doesn't exercise it. Natural language instructions sit in the same format as the rest of the prompt, so Claude treats them as guidance to flexibly interpret instead of constraints to hold.
Proposed Solution
TypeScript changes this. Claude already reasons within TS semantics from training data. By writing CLAUDE.md as typed interfaces, instructions become type constraints instead of suggestions.
Example:
Natural language:
Don't be sycophantic. Call me Nick, not "the user". Be direct when you disagree.
TypeScript:
interface CommunicationContract {
sycophancy: false;
referAs: User["name"] | "you" | "your";
neverReferAs: "the user";
disagreement: "explicit and direct";
}
referAs: User["name"] is a type reference binding to the User interface. sycophancy: false is a boolean constraint, not a request. Violations are type errors, not judgment calls.
I've been running this approach for about a month. Full guide and a standalone CLAUDE.md template are in the repo.
Repo: https://github.com/Nickatak/CLAUDE_OVERRIDE
Alternative Solutions
- YAML/JSON/TOML - I tried this, but Claude reads them as configuration, it's practically the same as natural language.
- More aggressive natural language ("YOU MUST", caps, repetition) - marginal improvement at best, degrades at the same rate, just starts from a slightly higher baseline. I also tried to change my verbiage, didn't work very well.
- Shorter sessions to avoid drift - works, but treats the symptom. The biggest problem is you may or may not know how many tokens you've eaten up in your context. I've noticed drift occuring around ~200k tokens.
Priority
Medium - Would be very helpful
Feature Category
Configuration and settings
Use Case Example
I built a full project with this claudefile active: https://github.com/Nickatak/bill-n-chill. The behavioral constraints (no sycophancy, direct disagreement, drift detection via name binding) held consistently across long sessions in a way that natural language CLAUDE.md instructions did not.
Additional Context
The repo includes both a standalone CLAUDE.md template you can drop in to try it out (of course, tailored to me though) and a 10-part guide (README) explaining each interface, why each field exists, and why the architecture works.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗