0-contexts — Claude Code rule: what it does, how to install
0-contexts enforces one-way imports across bounded contexts and keeps business logic out of the shared kernel in TypeScript projects.
MIT ★ 571 updated 2026-10-29
.claude/rules/0-contexts.mdWhat 0-contexts does
This rule directs the agent to organize files by bounded context rather than technical layers. Every dependency arrow points one way toward kernel/. The kernel itself holds shared vocabulary only: types, pure helpers, typed errors, and ports under kernel/ports/. Domain decisions inside the kernel are barred.
Contexts communicate exclusively through exports registered in PUBLIC_MODULES. Cross-context violations and reentry patterns get flagged by test suites like context-boundary.arch.test.ts and context-self-reentry.arch.test.ts.
Without architecture tests in tests/architecture/ and a map in aidd_docs/memory/codebase-map.md, the rule has no automated teeth: the instructions rely on ALLOWED edges and Biome parity checks to catch invalid imports.
What it helps with
- Prevent domain decisions from creeping into the shared kernel
- Enforce a one-way dependency chain toward the kernel
- Restrict inter-context imports to declared public modules
- Align architecture boundaries with Biome lint configurations
Example prompts for the agent
- Add a new billing module following bounded context boundaries from
codebase-map.md - Review context imports and relocate shared port definitions to
kernel/ports/ - Restructure module exports so callers only import via
PUBLIC_MODULES
How to install 0-contexts
Manually: put the files in place
.claude/rules/0-contexts.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-contexts.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/0-contexts.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/0-contexts.mdManually: put the files in place
.clinerules/0-contexts.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about 0-contexts
How to install 0-contexts in Claude Code?
Add the rule text directly into .claude/rules/0-contexts.md. Claude Code reads it when editing TypeScript files matching src/**/*.ts.
What belongs inside kernel/?
Keep only shared types, pure helper functions, typed errors, and interfaces inside kernel/ports/. Business choices must stay in their owning contexts.
How does the rule enforce boundaries?
Valid edges are defined in tests/architecture/helpers.ts, while context-graph.arch.test.ts fails any import outside that list.
Source text
0-contexts.md · MIT
--- description: Apply when adding or moving a module; keeps the import chain one-way and the kernel free of business logic. paths: - "src/**/*.ts" --- # Contexts Organise by bounded context, never by layer. ## Chain - Allowed edges live in `tests/architecture/helpers.ts` (`ALLOWED`). - Arrows run one way, toward the kernel. - `presentation` and `runtime` depend on any context. - A context depending on either is `BASELINE` debt; it only shrinks. - `context-graph.arch.test.ts` fails any other edge. - `biome-context-parity.arch.test.ts` holds `biome.json` to the same data. ## Kernel - `kernel/` imports no context. - Keep only shared vocabulary: types, pure helpers, typed errors. - A port two contexts need lives in `kernel/ports/`. - A domain decision is never kernel material. ## Interior - Import only a module listed in `PUBLIC_MODULES` (`context-boundary.arch.test.ts`). - Everything else is internal. - Never leave a context to re-enter it (`context-self-reentry.arch.test.ts`). ## Adding - Pick the owning context first. - A use case fitting nowhere means the contexts are wrong. - Cross through the target's public module, in the allowed direction. - Wrong direction: the caller sits in the wrong context. - Placement is `aidd_docs/memory/codebase-map.md`, held by `codebase-map.arch.test.ts`.
© ai-driven-dev · MIT · ai-driven-dev/framework