Skip to content

Define priority when language-specific rules conflict with common rules #236

@peterxiemin

Description

@peterxiemin

Problem

Currently, rules/common/ and language-specific directories (e.g., rules/golang/, rules/python/) are both loaded into ~/.claude/rules/. Language-specific files state they "extend" common rules, but there is no defined behavior when they conflict.

Example

common/coding-style.md marks immutability as CRITICAL — "ALWAYS create new objects, NEVER mutate existing ones." However, this directly conflicts with idiomatic patterns in several languages:

  • Go: Idiomatic Go mutates struct pointers (func (s *Server) SetName(...))
  • C/C++: Performance-sensitive code requires in-place mutation
  • Python: Standard library APIs use in-place mutation (list.sort(), dict.update())
  • Rust: Ownership system already guarantees safety; enforcing immutability is redundant

When Claude loads both rule files, it receives contradictory instructions with no defined priority, leading to unpredictable behavior.

Suggestion

A few possible approaches (not mutually exclusive):

  1. Explicit priority rule: State in rules/README.md that language-specific rules take precedence over common rules when they conflict (specific > general)
  2. Override markers in common: Tag rules in common that may be overridden by language-specific files (e.g., "This rule can be overridden by language-specific rules")
  3. Scope common rules more carefully: Ensure common rules only contain truly universal principles, and move language-sensitive guidance (like immutability) into language-specific files where the nuance can be expressed properly

References

  • rules/common/coding-style.md — Immutability section
  • rules/README.md — "Language directories extend the common rules"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions