Skip to main content
rule CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/0-contexts.md
Open on GitHub

What 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.md

The paths frontmatter field limits the files

Step 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

Similar IDE rules

All IDE rules for Agent setup: memory, context, orchestration →

From the same set80

The whole set →
09-defect 09-defect turns an observed product mismatch into a backlog defect: capture, assessment, then a confirmed write. CX Codex +1 ★ 571repo stars 06-agent-generate 06-agent-generate generates agent and subagent scaffolds across the AI coding tools configured in your project from a role prompt. CX Codex +1 ★ 571repo stars 02-challenge 02-challenge is a Claude Code skill that checks completed work against an agreed plan and returns a structured report. Its findings help decide whether to ship, revise, or rework the result. CX Codex +1 ★ 571repo stars 05-spike 05-spike turns one blocking unknown into a bounded spike: frames the question, gathers evidence, writes the outcome. CX Codex +1 ★ 571repo stars 1-conventions The 1-conventions rule sets conventions for TypeScript files under src/ and tests/, covering module structure, file names, and test tiers. Use it when adding code or tests to a project. CX Codex +1 ★ 571repo stars 05-rule-generate 05-rule-generate takes a coding rule from draft to the rule files of installed AI hosts: create, edit, publish, delete. CX Codex +1 ★ 571repo stars 07-command-generate 07-command-generate generates flat slash commands across the AI assistants enabled in your repository. Useful when you need to scaffold or edit single-step commands without manual path wiring. CX Codex +1 ★ 571repo stars 0-hexagonal The 0-hexagonal rule splits each context into four layers and keeps dependencies pointed inward. Use it when reviewing TypeScript architecture. CX Codex +1 ★ 571repo stars

Project sponsors

Companies that keep this analytics open