improve-claude-md by dexhorthy/slopfiles
npx skills add https://github.com/dexhorthy/slopfiles --skill improve-claude-md当用户提供 CLAUDE.md 文件(或要求你改进一个文件时),请按照以下原则和结构重写它。
Claude Code 会在每个 CLAUDE.md 中注入一个系统提醒,内容是:
"此上下文可能与你的任务相关,也可能不相关。除非高度相关,否则你不应回应此上下文。"
这意味着 Claude 会忽略它认为不相关的 CLAUDE.md 部分。与当前任务无关的内容越多,Claude 就越有可能忽略所有内容——包括重要的部分。
<important if="condition"> 块将 CLAUDE.md 中条件相关的部分包裹在 <important if="condition"> XML 标签中。这利用了 Claude Code 自身系统提示中使用的相同 XML 标签模式,为模型提供了一个明确的相关性信号,以突破"可能相关也可能不相关"的框架。
并非所有内容都应放在 <important if> 块中。几乎与每个任务都相关的上下文——项目标识、项目地图、技术栈——应作为纯 Markdown 保留在文件顶部。这是代理始终需要的入门上下文。
仅对某些任务重要的领域特定指导——测试模式、API 约定、状态管理、i18n——则需包裹在带有针对性条件的 <important if> 块中。
经验法则:如果与 90%+ 的任务相关,则保持原样。如果与特定类型的工作相关,则包裹起来。
不好——过于宽泛、匹配所有内容的条件:
<important if="you are writing or modifying any code">
- 使用绝对导入
- 使用函数式组件
- 使用驼峰式文件名
</important>
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
好——每条规则都有自己的狭窄触发条件:
<important if="you are adding or modifying imports">
- 使用 `@/` 绝对导入(路径别名请参见 tsconfig.json)
- 除路由文件外,避免使用默认导出
</important>
<important if="you are creating new components">
- 使用带有显式属性接口的函数式组件
</important>
<important if="you are creating new files or directories">
- 对文件和目录名使用驼峰命名法
</important>
除非额外上下文极其冗长或复杂,否则不要分割成需要代理调用工具才能发现的单独文件。
<important if> 块的整个要点在于所有内容都是内联的,但具有条件权重——代理能看到所有内容,但只关注匹配的部分。
倾向于保持文件简洁。
src/utils/example.ts 了解该模式")。不要从原始文件中删除命令。命令表是基础参考——代理需要知道有哪些可用命令,即使某些命令使用频率较低。
重写 CLAUDE.md 时,生成以下结构:
# CLAUDE.md
[项目标识一行描述——它是什么,用什么构建]
## 项目地图
[包含简要描述的目录列表]
<important if="you need to run commands to build, test, lint, or generate code">
[命令表——来自原始文件的所有命令]
</important>
<important if="<specific trigger for rule 1>">
[规则 1]
</important>
<important if="<specific trigger for rule 2>">
[规则 2]
</important>
... 更多规则,每个都有自己的块 ...
<important if="<specific trigger for domain area 1>">
[指导]
</important>
... 更多领域部分 ...
当给定一个现有的 CLAUDE.md 进行改进时:
<important if> 包装)。这是基础上下文。<important if> 块中。<important if> 块。你可以对规则进行分组,但切勿将不相关的规则归在一个宽泛的条件下。输入:
# CLAUDE.md
This is an Express API with a React frontend in a Turborepo monorepo.
## Commands
| Command | Description |
|---|---|
| `turbo build` | Build all packages |
| `turbo test` | Run all tests |
| `turbo lint` | Lint all packages |
| `turbo dev` | Start dev server |
| `turbo storybook` | Start Storybook |
| `turbo db:generate` | Generate Prisma client |
| `turbo db:migrate` | Run database migrations |
| `turbo analyze` | Bundle analyzer |
## Project Structure
- `apps/api/` - Express REST API
- `apps/web/` - React SPA
- `packages/db/` - Prisma schema and client
- `packages/ui/` - Shared component library
- `packages/config/` - Shared configuration
## Coding Standards
- Use named exports
- Use functional components with TypeScript interfaces for props
- Use camelCase for variables, PascalCase for components
- Prefer `const` over `let`
- Always use strict equality (`===`)
- Use template literals instead of string concatenation
- Write JSDoc comments for all public functions
- Use barrel exports in index.ts files
## API Development
- All routes go in `apps/api/src/routes/`
- Use Zod for request validation
- Use Prisma for database access
- Error responses follow RFC 7807 format
- Authentication via JWT middleware
## Testing
- Jest + Supertest for API tests
- Vitest + Testing Library for frontend
- Test fixtures in `__fixtures__/` directories
- Use `createTestClient()` helper for API integration tests
- Mock database with `prismaMock` from `packages/db/test`
## State Management
- Zustand for global client state
- React Query for server state
- URL state via `nuqs`
输出:
# CLAUDE.md
Express API + React frontend in a Turborepo monorepo.
## Project map
- `apps/api/` - Express REST API
- `apps/web/` - React SPA
- `packages/db/` - Prisma schema and client
- `packages/ui/` - Shared component library
- `packages/config/` - Shared configuration
<important if="you need to run commands to build, test, lint, or generate code">
Run with `turbo` from the repo root.
| Command | What it does |
|---|---|
| `turbo build` | Build all packages |
| `turbo test` | Run all tests |
| `turbo lint` | Lint all packages |
| `turbo dev` | Start dev server |
| `turbo storybook` | Start Storybook |
| `turbo db:generate` | Regenerate Prisma client after schema changes |
| `turbo db:migrate` | Run database migrations |
| `turbo analyze` | Bundle analyzer |
</important>
<important if="you are adding or modifying imports or exports">
- Use named exports (no default exports)
</important>
<important if="you are creating new components">
- Use functional components with TypeScript interfaces for props
</important>
<important if="you are adding or modifying API routes">
- All routes go in `apps/api/src/routes/`
- Use Zod for request validation
- Use Prisma for database access
- Error responses follow RFC 7807 format
- Authentication via JWT middleware
</important>
<important if="you are writing or modifying tests">
- API: Jest + Supertest
- Frontend: Vitest + Testing Library
- Test fixtures in `__fixtures__/` directories
- Use `createTestClient()` helper for API integration tests
- Mock database with `prismaMock` from `packages/db/test`
</important>
<important if="you are working with state management, stores, or URL parameters">
- Zustand for global client state
- React Query for server state
- URL state via `nuqs`
</important>
删除了什么以及原因:
未删除什么:
每周安装量
97
仓库
GitHub 星标数
32
首次出现
6 天前
安全审计
安装于
codex94
opencode93
gemini-cli93
github-copilot93
amp93
cline93
When the user provides a CLAUDE.md file (or asks you to improve one), rewrite it following the principles and structure below.
Claude Code injects a system reminder with every CLAUDE.md that says:
"this context may or may not be relevant to your tasks. You should not respond to this context unless it is highly relevant to your task."
This means Claude will ignore parts of your CLAUDE.md it deems irrelevant. The more content that isn't applicable to the current task, the more likely Claude is to ignore everything — including the parts that matter.
<important if="condition"> BlocksWrap conditionally-relevant sections of the CLAUDE.md in <important if="condition"> XML tags. This exploits the same XML tag pattern used in Claude Code's own system prompt, giving the model an explicit relevance signal that cuts through the "may or may not be relevant" framing.
Not everything should be in an <important if> block. Context that is relevant to virtually every task — project identity, project map, tech stack — should be left as plain markdown at the top of the file. This is onboarding context the agent always needs.
Domain-specific guidance that only matters for certain tasks — testing patterns, API conventions, state management, i18n — gets wrapped in <important if> blocks with targeted conditions.
The rule of thumb: if it's relevant to 90%+ of tasks, leave it bare. If it's relevant to a specific kind of work, wrap it.
Bad — overly broad conditions that match everything:
<important if="you are writing or modifying any code">
- Use absolute imports
- Use functional components
- Use camelCase filenames
</important>
Good — each rule has its own narrow trigger:
<important if="you are adding or modifying imports">
- Use `@/` absolute imports (see tsconfig.json for path aliases)
- Avoid default exports except in route files
</important>
<important if="you are creating new components">
- Use functional components with explicit prop interfaces
</important>
<important if="you are creating new files or directories">
- Use camelCase for file and directory names
</important>
Do not shard into separate files that require the agent to make tool calls to discover, unless the extra context is incredibly verbose or complex.
The whole point of <important if> blocks is that everything is inline but conditionally weighted — the agent sees it all but only attends to what matches.
Prefer to keep the file concise.
src/utils/example.ts for the pattern").Do not drop commands from the original file. The commands table is foundational reference — the agent needs to know what's available even if some commands are used less frequently.
When rewriting a CLAUDE.md, produce this structure:
# CLAUDE.md
[one-line project identity — what it is, what it's built with]
## Project map
[directory listing with brief descriptions]
<important if="you need to run commands to build, test, lint, or generate code">
[commands table — all commands from the original]
</important>
<important if="<specific trigger for rule 1>">
[rule 1]
</important>
<important if="<specific trigger for rule 2>">
[rule 2]
</important>
... more rules, each with their own block ...
<important if="<specific trigger for domain area 1>">
[guidance]
</important>
... more domain sections ...
When given an existing CLAUDE.md to improve:
<important if> wrapper). This is foundational context.<important if> block.<important if> blocks with specific conditions. You can group rules, but never group unrelated rules under one broad condition.Input:
# CLAUDE.md
This is an Express API with a React frontend in a Turborepo monorepo.
## Commands
| Command | Description |
|---|---|
| `turbo build` | Build all packages |
| `turbo test` | Run all tests |
| `turbo lint` | Lint all packages |
| `turbo dev` | Start dev server |
| `turbo storybook` | Start Storybook |
| `turbo db:generate` | Generate Prisma client |
| `turbo db:migrate` | Run database migrations |
| `turbo analyze` | Bundle analyzer |
## Project Structure
- `apps/api/` - Express REST API
- `apps/web/` - React SPA
- `packages/db/` - Prisma schema and client
- `packages/ui/` - Shared component library
- `packages/config/` - Shared configuration
## Coding Standards
- Use named exports
- Use functional components with TypeScript interfaces for props
- Use camelCase for variables, PascalCase for components
- Prefer `const` over `let`
- Always use strict equality (`===`)
- Use template literals instead of string concatenation
- Write JSDoc comments for all public functions
- Use barrel exports in index.ts files
## API Development
- All routes go in `apps/api/src/routes/`
- Use Zod for request validation
- Use Prisma for database access
- Error responses follow RFC 7807 format
- Authentication via JWT middleware
## Testing
- Jest + Supertest for API tests
- Vitest + Testing Library for frontend
- Test fixtures in `__fixtures__/` directories
- Use `createTestClient()` helper for API integration tests
- Mock database with `prismaMock` from `packages/db/test`
## State Management
- Zustand for global client state
- React Query for server state
- URL state via `nuqs`
Output:
# CLAUDE.md
Express API + React frontend in a Turborepo monorepo.
## Project map
- `apps/api/` - Express REST API
- `apps/web/` - React SPA
- `packages/db/` - Prisma schema and client
- `packages/ui/` - Shared component library
- `packages/config/` - Shared configuration
<important if="you need to run commands to build, test, lint, or generate code">
Run with `turbo` from the repo root.
| Command | What it does |
|---|---|
| `turbo build` | Build all packages |
| `turbo test` | Run all tests |
| `turbo lint` | Lint all packages |
| `turbo dev` | Start dev server |
| `turbo storybook` | Start Storybook |
| `turbo db:generate` | Regenerate Prisma client after schema changes |
| `turbo db:migrate` | Run database migrations |
| `turbo analyze` | Bundle analyzer |
</important>
<important if="you are adding or modifying imports or exports">
- Use named exports (no default exports)
</important>
<important if="you are creating new components">
- Use functional components with TypeScript interfaces for props
</important>
<important if="you are adding or modifying API routes">
- All routes go in `apps/api/src/routes/`
- Use Zod for request validation
- Use Prisma for database access
- Error responses follow RFC 7807 format
- Authentication via JWT middleware
</important>
<important if="you are writing or modifying tests">
- API: Jest + Supertest
- Frontend: Vitest + Testing Library
- Test fixtures in `__fixtures__/` directories
- Use `createTestClient()` helper for API integration tests
- Mock database with `prismaMock` from `packages/db/test`
</important>
<important if="you are working with state management, stores, or URL parameters">
- Zustand for global client state
- React Query for server state
- URL state via `nuqs`
</important>
What was removed and why:
What was NOT removed:
Weekly Installs
97
Repository
GitHub Stars
32
First Seen
6 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex94
opencode93
gemini-cli93
github-copilot93
amp93
cline93
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
116,600 周安装