claude-code - 💡(How to fix) Fix [FEATURE] TypeScript interfaces as a structural enforcement mechanism for CLAUDE.md [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45241Fetched 2026-04-09 08:09:59
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×3

Code Example

Don't be sycophantic. Call me Nick, not "the user". Be direct when you disagree.

---

interface CommunicationContract {
  sycophancy: false;
  referAs: User["name"] | "you" | "your";
  neverReferAs: "the user";
  disagreement: "explicit and direct";
}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • 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.

extent analysis

TL;DR

Rewrite CLAUDE.md instructions as TypeScript interfaces to enforce constraints and prevent drift in Claude's behavior.

Guidance

  • Define a CommunicationContract interface in TypeScript to specify behavioral constraints, such as sycophancy: false and referAs: User.
  • Use type references and boolean constraints to ensure Claude treats instructions as enforceable rules rather than suggestions.
  • Replace natural language instructions in CLAUDE.md with the corresponding TypeScript interfaces to maintain consistency across sessions.
  • Test the new approach with a standalone CLAUDE.md template and a guide to ensure correct implementation.

Example

interface CommunicationContract {
  sycophancy: false;
  referAs: User["name"] |you | "your";
  neverReferAs: "the user";
  disagreement: "explicit and direct";
}

Notes

This solution assumes that Claude can reason within TypeScript semantics and that the provided example is a valid representation of the desired behavior. The effectiveness of this approach may depend on the specific use case and the complexity of the instructions.

Recommendation

Apply the workaround by rewriting CLAUDE.md instructions as TypeScript interfaces, as it provides a more structured and enforceable way to specify behavioral constraints and prevent drift in Claude's behavior.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING