0-shared-modules — Claude Code rule: what it does, how to install
The 0-shared-modules rule sets a bar for moving code into shared/: callers must come from two application areas. Use it when reviewing modules under src/contexts/.
MIT ★ 571 updated 2026-10-29
.claude/rules/0-shared-modules.mdWhat 0-shared-modules does
Before creating shared/ or moving a module there, count the areas that call it with grep -rl <module> src. The earned-sharing.arch.test.ts test counts as a caller too. A single area means the module belongs closer to that code. runtime/wiring/ does not count as an application area.
Files nested inside a shared module are treated as its private steps. A promoted module follows 0-hexagonal.md; crossing a context boundary means declaring it public according to 0-contexts.md. Move code into kernel/ only after it stops being business logic. The rule targets src/contexts/**/*.ts, so check that this path matches your project layout.
What it helps with
- check whether a module has callers in enough areas to move into
shared/ - keep a single-area module close to its caller
- exclude
runtime/wiring/when counting application areas - identify when a module crossing contexts needs a public declaration
- decide whether code still belongs to business logic before moving it into
kernel/
Example prompts for the agent
- Check whether this module can move into
shared/and count its caller areas. - Review
src/contexts/and tell me where a module with one caller should live. - Check this cross-context move and list the changes it requires.
How to install 0-shared-modules
Manually: put the files in place
.claude/rules/0-shared-modules.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/0-shared-modules.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/0-shared-modules.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/0-shared-modules.mdManually: put the files in place
.clinerules/0-shared-modules.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about 0-shared-modules
How do I install 0-shared-modules in Claude Code?
Add the rule file at .claude/rules/0-shared-modules.md.
What does 0-shared-modules do?
It sets conditions for moving code into shared/: a module needs callers from two areas. It also covers context boundaries and moves into kernel/.
How does the rule define an application area?
An area is application/<subdirectory>/ or the application root. runtime/wiring/ is excluded.
Source text
0-shared-modules.md · MIT
--- description: Apply before creating or moving into a shared/ directory; sharing is earned by two calling areas. paths: - "src/contexts/**/*.ts" --- # Shared Modules - `shared/` needs callers in two areas. - One caller: move it down. - Never share for a caller not yet written. - An area is `application/<subdirectory>/` or the application root. - `runtime/wiring/` is never an area. - Count first: `grep -rl <module> src`; `earned-sharing.arch.test.ts` counts the same. - A file nested under a shared module is its private step. - A promoted module follows `0-hexagonal.md`. - Crossing a context: declare the module public (`0-contexts.md`). - Move to `kernel/` only once it stops being business logic.
© ai-driven-dev · MIT · ai-driven-dev/framework