Analyze a specific directory (e.g. frontend/, backend/, e2e/) and generate .claude/rules/ markdown files for it. Use when asked to create rules, analyze a folder for Claude Code, or set up domain memory for a specific part of the codebase.
Analyze a directory and generate .claude/rules/ files for Claude Code domain memory.
Generalized agents fail because they're "amnesiacs with a tool belt." Each session starts with no grounded sense of where we are.
Solution: Domain Memory - persistent structured representation containing:
Rules files distill domain knowledge into quick-reference format.
User asks to:
Read root CLAUDE.md and target directory CLAUDE.md. Pull down what's already documented. We don't want to duplicate everything, but the main CLAUDE.md still have to keep core overview of the application.
Scan the target directory to detect which concerns exist. Only generate rule files for concerns that are actually present.
Check planning board and tasks under /.tasks/ for decisions, gotchas, and patterns related to each detected concern.
Globpattern: ".task-board/done/*.md"
Use tasks older than #150
Create focused .md files only for detected concerns.
Scan for these patterns to detect which concerns exist:
| Concern | Detection Signals | Rule File |
|---------|-------------------|-----------|
| auth | **/auth/**, AuthContext, AuthProvider, login, logout, session, token, OAuth, EasyAuth | auth.md |
| data | **/models/**, cosmosdb, database, mongoose, prisma, orm, migrations, Container | data.md |
| api | **/routes/**, **/controllers/**, router.get, router.post, express.Router, endpoints | api.md |
| validation | **/validators/**, zod, yup, joi, schema, .parse(, .safeParse( | validation.md |
| state | useQuery, useMutation, QueryClient, zustand, redux, recoil, Context.Provider | state.md |
| components | **/ui/**, **/components/**, .tsx files with Props interfaces, forwardRef | components.md |
| styling | tokens.css, theme, tailwind, styled-components, css modules, design system files | styling.md |
| charts | d3, recharts, chart.js, victory, **/charts/**, <svg, useEffect with DOM manipulation | charts.md |
| forms | **/forms/**, useForm, handleSubmit, <input, <form, form validation patterns | forms.md |
| calculations | **/calculation*, pure functions returning numbers, financial formulas, Math. heavy files | calculations.md |
| llm | openai, langchain, anthropic, agent, tool calls, completion, langfuse | llm.md |
| errors | **/errors/**, AppError, ErrorBoundary, errorHandler, custom error classes | errors.md |
| testing | *.spec.ts, *.test.ts, fixtures, beforeEach, describe(, it(, expect( | testing.md |
| middleware | **/middleware/**, app.use(, request/response interceptors, next() | middleware.md |
| services | **/services/**, business logic classes, dependency injection patterns | services.md |
| onboarding | wizard, onboarding, setup, multi-step flows, Step*.tsx | onboarding.md |
| integrations | Third-party SDK imports, API clients, webhooks, external service calls | integrations.md |
For each concern in matrix:
1. Glob for folder patterns (**/auth/**, **/models/**, etc.)
2. Grep for keyword patterns (AuthContext, useQuery, etc.)
3. If matches found → concern is DETECTED
4. If no matches → skip this concern
Threshold: A concern is detected if:
# [Concern] Rules
## Stack
[One line: key libs/frameworks for this concern]
## Structure
- `/path` - Purpose
- `/path` - Purpose
## Patterns
- Established pattern 1
- Established pattern 2
## Decisions
- Choice X because Y
## Gotchas
- Problem → Solution
## Commands
- `pnpm <command>` - What it does
Not every file needs all sections - include only what's relevant.
backend/Detection results:
middleware/auth.ts, routes/authRoutes.tsconfig/cosmosdb.ts, models/*.tsroutes/*.ts, controllers/*.tsvalidators/*.ts, zod importsservices/*.tsservices/calculationService.tsservices/importAgentService.ts, openai importserrors/AppError.ts, middleware/errorHandler.tsmiddleware/*.tsGenerated files:
backend/.claude/rules/
├── auth.md
├── data.md
├── api.md
├── validation.md
├── services.md
├── calculations.md
├── llm.md
├── errors.md
└── middleware.md
components/Detection results:
ui/**, cards/**, layout/**styles/tokens.csscharts/*.tsx, d3 importsforms/*.tsxsystem/ErrorBoundaryGenerated files:
components/.claude/rules/
├── components.md
├── styling.md
├── charts.md
├── forms.md
└── errors.md
e2e/Detection results:
*.spec.ts, fixturesGenerated files:
e2e/.claude/rules/
├── testing.md
└── auth.md
| Section | Source |
|---------|--------|
| Stack | package.json deps for this concern |
| Structure | Folder layout for this concern only |
| Patterns | Code analysis + task-board history |
| Decisions | Task-board "decided to..." entries |
| Gotchas | Task-board "had issues with..." entries |
| Commands | package.json scripts for this concern |
CLAUDE.md (no duplication)backend/.claude/rules/data.md# Data Rules
## Stack
CosmosDB (NoSQL), @azure/cosmos SDK
## Structure
- `/config/cosmosdb.ts` - Connection, container getters
- `/models/` - Document type definitions
## Patterns
- Containers: `users` (partition: /id), `portfolios` (partition: /userId)
- Documents are denormalized (snapshots store full account data)
- Use singleton pattern for database instance
## Decisions
- Denormalized snapshots for historical accuracy (accounts change over time)
- Co-locate user data by userId partition for fast queries
## Gotchas
- Date strings "dd.MM.yyyy" don't sort correctly in CosmosDB
- Always sort dates in JS using `compareDatesAsc` from dateUtils.ts
- Zod strips unknown fields - add to schema or they're dropped
## Commands
- `pnpm --filter backend seed` - Seed demo data
- `pnpm --filter backend seed:reset` - Reset database
components/.claude/rules/charts.md# Charts Rules
## Stack
D3.js for all visualizations
## Structure
- `/charts/AreaChart` - Single line/area
- `/charts/StackedAreaChart` - Multiple stacked areas
- `/charts/DonutChart` - Pie/donut charts
## Patterns
- SVG-based, responsive via viewBox
- Data prop: `{ date: string, value: number }[]`
- Colors from design tokens (--muted-sage, --pale-blue, etc.)
- Tooltips via D3 mouse events
## Gotchas
- D3 selections in useEffect with cleanup
- Don't mix D3 DOM manipulation with React state
- Mobile: increase touch targets for tooltips
e2e/.claude/rules/testing.md# Testing Rules
## Stack
Playwright
## Structure
- `/tests/*.spec.ts` - Test files
- `/tests/fixtures.ts` - Shared helpers, constants
## Patterns
- `PROTECTED_PAGES` array for auth-required pages
- `login()` helper handles demo authentication
- `clearAuthState()` between tests
## Decisions
- Integration + E2E only, no unit tests
- Sanity checks over comprehensive coverage
- Test user flows, not implementation details
## Gotchas
- Demo login has rate limiting (5 req/min)
- Always clearAuthState() in beforeEach
- Mobile tests use fixtures/mobile-viewports.ts
## Commands
- `pnpm test:e2e` - Run all tests
- `pnpm test:e2e --ui` - Interactive mode
npx skills add andersnygaard/rule-making-skill下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer