clean-code

A set of practical coding rules for keeping code simple, focused, and readable. It covers naming, small functions, avoiding repetition, and not building unrequested features.

In plain words
What is it for?
Use it when writing or reviewing code, fixing bugs, or implementing features while following principles such as single responsibility, DRY (avoid repeating logic), and KISS (keep solutions simple).
Why use it?
It reduces unnecessary complexity and makes code easier to understand, change, and review.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/misonl/ling/clean-code
Any agent
npx skills add MisonL/Ling --skill clean-code
Clone the repo
git clone --depth 1 https://github.com/MisonL/Ling

Made for: Claude Code, Codex.

Per session 31 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,190 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00031 $0.02190
Opus 5 $0.00015 $0.01095
Sonnet 5 $0.00006 $0.00438
Haiku 4.5 $0.00003 $0.00219

Measured yesterday against content hash fd97018c5767, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

clean-code scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/skills/clean-code/SKILL.md · 211 lines

How it starts

The opening of the file, as written. The whole thing — 211 lines — stays where its author put it; the contents beside it link to each section on GitHub.

整洁代码 - 务实的 AI 编码标准

Clean Code(整洁代码)是核心技能—— 保持简洁、直接并专注于解决方案


核心原则

原则 规则
SRP 单一职责(Single Responsibility)—— 每个函数/类只做一件事
DRY 不要重复(Don't Repeat Yourself)—— 提取重复项并复用
KISS 保持简单(Keep It Simple)—— 采用能跑通的最简单方案
YAGNI 你不会需要它(You Aren't Gonna Need It)—— 不构建未被要求的功能
Boy Scout 离开时让代码比你来时更整洁

命名规则

元素 规范
变量(Variables) 揭示意图:userCount 而非 n
函数(Functions) 动词 + 名词:getUserById() 而非 user()
布尔值(Booleans) 提问形式:isActive, hasPermission, canEdit
常量(Constants) SCREAMING_SNAKE:MAX_RETRY_COUNT

准则: 如果需要注释解释命名,请直接重命名。


函数规则

规则 描述
短小(Small) 最多 20 行,理想 5-10 行
专注(One Thing) 只做一件事,并把它做好
层次(One Level) 每个函数只包含一个抽象层级
参数少(Few Args) 最多 3 个参数,优先 0-2 个
无副作用(No Side Effects) 不要产生预期之外的输入状态改变

代码结构

模式 应用建议
卫语句(Guard Clauses) 针对边缘情况及早返回
扁平化优先(Flat > Nested) 避免深度嵌套(最多 2 层)
组合(Composition) 将短小函数组合使用
就近原则(Colocation) 相关代码尽量放近

AI 编码风格

场景 行动建议
用户要求功能 直接编写实现
用户报告问题 修复,不做多余解释
需求不明确 先询问,不做假设

反模式(Anti-Patterns)

[FAIL] 错误模式 [OK] 推荐修复
每一行都写注释 删除显而易见的注释
为单行逻辑封装 helper 直接内联
为 2 个对象写工厂模式 直接实例化
只有 1 个函数的 utils.ts 代码放在被使用处
“First we import...” 直接写代码
深度嵌套 使用卫语句
使用魔术数字 使用具名常量
万能函数 按职责拆分

[CRITICAL] 编辑任何文件前(先思考)

修改文件前先问自己:

提问 为什么
谁引用了这个文件? 修改可能会破坏它们
这个文件引用了谁? 接口可能需要变更
有哪些测试覆盖了这里? 测试可能会失败
这是共享组件吗? 可能影响多个地方

快速检查:

File to edit: UserService.ts
+-- Who imports this? -> UserController.ts, AuthController.ts
+-- Do they need changes too? -> Check function signatures

[CRITICAL] 准则: 同一任务内同时编辑该文件与所有受影响的依赖文件。 [CRITICAL] 禁止: 遗留断裂引用或缺失更新。

Read the full file on GitHub · 211 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 211 lines · 31 tokens per session scan A fd97018c5767

Subscribe to this mod's changes

clean-code is a skill published in the GitHub repository MisonL/Ling (9 stars, last pushed 5mo ago), licensed MIT. It adds 31 tokens to every session and 2,190 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

next-cache-components-adoption

Turn on Cache Components in a Next.js app and resolve the blocking routes it surfaces. Use when the user wants to enable, adopt, or migrate to Cache Components, flip the cacheComponents flag, work through a flood of blocking-prerender / instant validation errors, run the cache-components-instant-false codemod, or…

vercel/next.js · 95 tokens

babysit-pr

Babysit a GitHub pull request after creation by continuously polling review comments, CI checks/workflow runs, and mergeability state until the PR is merged/closed or user help is required. Diagnose failures, retry likely flaky failures up to 3 times, auto-fix/push branch-related issues when appropriate, and keep…

openai/codex · 114 tokens

imagegen

Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output…

openai/codex · 113 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens

next-cache-components-optimizer

Drive a Next.js route to instant navigation by setting up an agentic loop, under Cache Components / PPR, on initial load (hard navigation) and client-side navigation (soft navigation). Encode the goal as a failing @next/playwright instant() e2e and work it to green, one verified route at a time; the shipped test then…

vercel/next.js · 170 tokens