CLAUDE.md "main session must not write code" rule is not enforced — no hook prevents direct Write/Edit of code files
Environment: Claude Code CLI, Windows 11, Sonnet 5, with a global ~/.claude/CLAUDE.md "model economy" rule set installed.
Rule (user-defined, in CLAUDE.md): "Main session must not write code — it writes a clear file+function-level spec, has it implemented, and verifies the result by testing/reading. Exception: a touch of ≤~20 lines in a single file." Code writing should by default be delegated to an external coder model (Codex) via mcp__pal__clink.
Expected behavior: Before writing a code file over ~20 lines, the main session should either follow the rule itself and delegate to Codex, or be blocked by a hook if one exists for this purpose.
Actual behavior: In this session, the main session (me) wrote a ~100-line Python script (run_all.py, a YouTube download/transcription pipeline) directly with the Write tool — ignoring the CLAUDE.md rule. No technical safeguard intervened until the user noticed and asked about it.
Root cause: The require-agent-model hook installed in this setup only checks that Agent tool calls specify a model parameter — there is no hook that checks Write/Edit calls against the CLAUDE.md "main session doesn't write code" rule. This rule currently relies entirely on the model's own instruction-following, with no technical enforcement.
Suggestion: A PreToolUse hook could inspect Write/Edit calls (by target file extension — .py, .js, .ts, etc. — and line-count threshold) and warn/block when such a CLAUDE.md rule is defined for the project/user — or at minimum, this limitation (that CLAUDE.md rules without a hook are "best effort" only) should be documented explicitly.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗