# Claude Rules
[](LICENSE)
[](https://github.com/lifedever/claude-rules/stargazers)
[](https://github.com/lifedever/claude-rules/pulls)
[](https://lifedever.github.io/claude-rules/)
English | [ไธญๆ](README_CN.md)
Coding standards template library for AI coding assistants. Combine **base + language + framework** layers to generate a project-specific rules file that keeps AI-generated code clean and consistent.
## The Problem
AI coding assistants tend to mimic existing code style in legacy projects โ including bad habits. The core principle of this library:
> **Don't imitate legacy code. Refactor according to the standards.**
Every rule is a concrete, actionable directive (not vague "use proper XX"), with "Bad / Good" code comparison examples.
## Directory Structure
```
claude-rules/
โโโ base/ # Universal (required)
โ โโโ core.md # Core principles: legacy code attitude, quality metrics, naming, architecture
โ โโโ git.md # Git commit message conventions
โ
โโโ languages/ # Pick by language
โ โโโ typescript.md # No any/enum/barrel exports, as const, import type
โ โโโ javascript.md # ES2022+, JSDoc type annotations, ESM only
โ โโโ java.md # Java 17+ record/sealed/pattern matching, Optional
โ โโโ kotlin.md # Null safety, structured concurrency, sealed class
โ โโโ swift.md # guard let, async/await, actor, Protocol
โ โโโ python.md # ruff, type annotations, Protocol, uv/poetry
โ โโโ html.md # Semantic tags, accessibility, no div soup
โ โโโ css.md # Custom properties, Flexbox/Grid, BEM, modern features
โ โโโ go.md # Error wrapping, small interfaces, structured concurrency
โ โโโ rust.md # Ownership/borrowing, thiserror/anyhow, iterators, Clippy
โ
โโโ frameworks/ # Pick by framework
โโโ vue.md # script setup, ref vs reactive, composable patterns
โโโ react.md # Hooks rules, correct useEffect, state layering
โโโ swiftui.md # @Observable (not legacy ObservableObject), SwiftData
โโโ springboot.md # Layered architecture, DTO, global exception handling
โโโ tauri.md # Command design, service encapsulation, security config
```
## Three-Layer Architecture
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ base (required) โ core.md + git.md
โ Legacy code attitude / Quality metrics / โ Applies to all projects
โ Naming / Architecture โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ language (pick) โ typescript.md / java.md / ...
โ Type system / Naming conventions / โ Based on project language
โ Language-specific features โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ framework (pick) โ vue.md / react.md / ...
โ Component standards / State management / โ Based on project framework
โ Architecture patterns โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
**Rule priority**: framework > language > base (specific rules override general rules)
## Usage
### Claude Code Plugin (Recommended)
#### Install
```bash
# Step 1: Add the marketplace
claude plugin marketplace add lifedever/claude-rules
# Step 2: Install the plugin
claude plugin install init-claude-rules@claude-rules
# Step 3: Restart Claude Code
```
#### Use
Open any project in Claude Code and run:
```
/init-rules
```
The plugin will:
1. Auto-detect your project's tech stack (TypeScript, Vue, React, etc.)
2. Ask you to confirm the detected stack
3. Read the matching rule files from the plugin
4. Generate `CLAUDE.md` in your project root
#### Update
When new rules are added upstream, update the local cache:
```bash
claude plugin marketplace update claude-rules
```
Then restart Claude Code. To apply updated rules to a project that already has `CLAUDE.md`, run `/init-rules` again โ the plugin will ask before overwriting.
#### Uninstall
```bash
claude plugin uninstall init-claude-rules@claude-rules
claude plugin marketplace remove claude-rules
```
### Manual Usage
Clone this repo and concatenate the rule files you need:
```bash
git clone https://github.com/lifedever/claude-rules.git
cd claude-rules
# Example: Vue 3 + TypeScript project
cat base/core.md base/git.md languages/typescript.md frameworks/vue.md > /path/to/project/CLAUDE.md
```
The rules are plain Markdown and work with any AI coding tool. Just place the output where your tool expects:
| Tool | Target File |
|------|-------------|
| Claude Code | `CLAUDE.md` |
| Cursor | `.cursorrules` or `.cursor/rules/*.mdc` |
| Antigravity | `.antigravity/rules.md` |
| GitHub Copilot | `.github/copilot-instructions.md` |
## Design Principles
1. **Actionable** โ Every rule is directly executable by AI, no vague wording
2. **Exemplified** โ Key rules include "Bad" and "Good" code comparisons
3. **Quantified** โ Functions โค30 lines, files โค300 lines, nesting โค3 levels, parameters โค4
4. **Up-to-date** โ Uses modern APIs for each language/framework (@Observable, record, as const, etc.)
5. **Not hollow** โ Instead of "handle errors properly", specifies exactly how to handle them
## Contributing
PRs for new languages or frameworks are welcome. Please follow these guidelines:
- Rules must be concrete and actionable โ no "use appropriate/proper" phrasing
- Key rules should include code examples (bad practice + good practice)
- Recommend modern idioms โ don't document outdated APIs
- Write in English
## References
- [flyeric0212/cursor-rules](https://github.com/flyeric0212/cursor-rules) โ Cursor IDE rules template library
## License
[MIT](LICENSE)
Read the source README