Prevent AI code style drift in legacy projects. A Claude Code skill that scans your hand-written project, extracts its implicit coding conventions, and crystallizes them into enforceable rules — so every subsequent AI edit aligns with the project's existing style, not the model's pretrained biases.
When you drop an AI coding agent onto a hand-written legacy project, the model's pretraining bias makes it impose its own "mainstream" idioms. Result: two competing list-refresh patterns in one codebase, inconsistent naming, duplicated utilities. Style Drift.
- Zero-argument trigger:
/inherit-legacy-styleauto-detects whether it's a first-time scan or an incremental update. - 4-dimension meta-architecture scan: File Anatomy, State & Control Flow, Infrastructure, Error Handling — language- and framework-agnostic.
- Scale-adaptive: Small projects get full close-read; large projects get smart sampling with a budget cap.
- Signal-threshold noise reduction: Minor inconsistencies are auto-silenced into DONTs; only high-signal conflicts interrupt you for a decision.
- Enforceable: Writes rules to
.ai-style-rules.mdand hooks them into your project'sCLAUDE.mdso every future session auto-loads the constraint.
# Clone into your Claude Code skills directory
git clone https://github.com/wulinzai/inherit-legacy-style.git ~/.claude/skills/inherit-legacy-styleThen reload plugins in Claude Code (/reload-plugins) or restart the session.
/inherit-legacy-style
That's it. The skill auto-detects whether .ai-style-rules.md exists:
- Not found → Full scan mode: measures project scale, scans along 4 dimensions, resolves conflicts with you, creates the rules file.
- Found → Incremental sniff mode: checks recent Git changes for new patterns not yet recorded, appends evolution log.
A root-level .ai-style-rules.md with:
- [Golden Files] — exemplar files to imitate pixel-for-pixel
- [Naming & State-Control Rules] — concrete, checkable conventions
- [DONTs] — legacy anti-patterns that must not propagate
- Claude Code (the skill uses
Read,Glob,Grep,Bash,Edit,Writetools) - Git (recommended for incremental mode; non-Git projects fall back to file timestamps)
MIT
历史人工项目接入 AI 编程时,大模型会因预训练偏见把自己的"主流写法"强加给项目,造成代码风格漂移(Style Drift):同一个项目里出现两套列表刷新逻辑、命名割裂、工具函数重复造轮子。
- 零参数触发:
/inherit-legacy-style自动检测首次/增量模式。 - 四维元架构扫描:文件内组织、状态控制、基础设施、防御性编程——跨语言、跨技术栈通用。
- 规模自适应:小项目全量精读,大项目智能抽样+预算上限。
- 信号阈值降噪:弱信号自动入 DONTs,仅高信号冲突中断提问。
- 持久约束:规约写入
.ai-style-rules.md并挂钩到CLAUDE.md,每会话自动生效。
git clone https://github.com/wulinzai/inherit-legacy-style.git ~/.claude/skills/inherit-legacy-style在 Claude Code 中 /reload-plugins 或重启会话即可。
/inherit-legacy-style
技能自动检测 .ai-style-rules.md 是否存在:
- 不存在 → 首次全量扫描:量规模、四维扫描、冲突逐个拷问、生成规约文件。
- 已存在 → 增量嗅探:读取 Git 近期改动,比对既有规约,仅追加演进日志。
项目根目录 .ai-style-rules.md,包含三大板块:
- [Golden Files] 金牌标杆文件 — 值得像素级模仿的真实文件路径
- [强制命名与状态控制规约] — 可执行、可对照的明确规则
- [DONTs] 禁止模仿的遗留反面教材 — 不应再扩散的坏味道
- Claude Code(使用 Read、Glob、Grep、Bash、Edit、Write 工具)
- Git(增量模式推荐;非 Git 项目退化为文件时间戳比对)
MIT