QuestionQ65

Claude Code Configuration & Workflows

Your team has three requirements for how Claude Code should behave in your project:

  1. Claude must never modify files in the db/migrations/ directory.
  2. Claude should prefer your custom logging module over console.log.
  3. All TypeScript files must be auto-formatted with Prettier after every edit.

All three requirements are currently written as instructions inside your project's CLAUDE.md file. During a complex refactoring session, a developer discovers that Claude edited a migration file, violating requirement #1.

How should you restructure these requirements across Claude Code's configuration mechanisms?

Explanation

CLAUDE.md content is loaded into the model's context as advisory guidance, so the model can still deviate from it—especially during long, complex sessions—which is exactly why the migration file was edited despite the instruction. Claude Code's official documentation distinguishes deterministic enforcement layers from contextual guidance: permission rules (permissions.deny in settings.json) are evaluated by the Claude Code harness itself and block a matching tool call (e.g., Edit(./db/migrations/**)) before it can run, giving a guaranteed hard boundary, whereas CLAUDE.md is explicitly documented as 'not a hard security boundary.' The hooks documentation further states that for static path-based blocking you should 'use the permission system rather than a hook to enforce a hard allow or deny,' since hooks are best-effort while permission rules are deterministic and enforced with no LLM judgment involved. Meanwhile, the logging-module preference is a stylistic convention well-suited to CLAUDE.md, where the model can apply judgment. The Prettier formatting requirement is a repeatable, deterministic post-edit action, which is the standard use case for a PostToolUse hook (matching the Edit/Write tools) that invokes Prettier on the changed file—Claude Code's hooks guide gives this exact pattern as a canonical example. This mapping—hard restriction to permissions.deny, soft preference to CLAAUDE.md, deterministic automation to a PostToolUse hook—correctly addresses the demonstrated compliance failure by moving the safety-critical rule to an enforcement mechanism that cannot be bypassed by the model's behavior.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!