clean-code
Use when a diff, branch or PR needs review or a gate verdict, code needs refactoring, or a requirement needs implementing cleanly. Triggers: "코드 리뷰", "이 브랜치 리뷰해줘", "PR 리뷰", "리팩토링", "어떻게 구현해?", "review this branch", "code review".
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- clean-code
- license
- MIT
- metadata
- { "version": "2.1.0" }
- scenarios
- [ "quality gate: does this diff meet the acceptance criteria?", "refactor this function — it's too long", "how should I implement this requirement cleanly?", "이 PR 품질 게이트 통과 가능한지 봐줘", "이 코드 리팩토링해줘", "이 요구사항 어떻게 구현하면 깔끔할까?" ]
- description
- Use when a diff, branch or PR needs review or a gate verdict, code needs refactoring, or a requirement needs implementing cleanly. Triggers: "코드 리뷰", "이 브랜치 리뷰해줘", "PR 리뷰", "리팩토링", "어떻게 구현해?", "review this branch", "code review".
- compatibility
- { "optional": [ "sequential-thinking" ], "recommended": [ "think-tool" ], "remote_mcp_note": "think-tool이 있으면 코드 스멜 탐지와 리팩토링 우선순위 판단이 더 정확해집니다. Claude 설정 → MCP Servers에서 remote SSE 엔드포인트를 추가하세요." }
02 资源文件 8
- 参考文档references/code-smells.md3.5 KB
- 参考文档references/comments-formatting.md3.0 KB
- 参考文档references/error-handling.md3.6 KB
- 参考文档references/functions-and-methods.md3.4 KB
- 参考文档references/modes.md5.7 KB
- 参考文档references/naming-conventions.md2.9 KB
- 参考文档references/review-framework.md4.2 KB
- 参考文档references/testing-principles.md3.6 KB
03 SKILL.md 正文
Clean Code
Code that communicates intent, minimizes surprises, and welcomes change — judged in gate mode, written in implement mode, against the same six dimensions.
Mode Map
Pick the mode from the stage you were called in and the output the caller asks for.
| Mode | Chosen when | Interactive | Headless (teams / harness stage) |
|---|---|---|---|
| Gate / review | stage is gate, review or critique; asked to judge or review a diff; or the required output asks for a verdict (accept, pass, verified) |
Findings table + verdict, before/after snippets for each fix | Judge only; fill the caller's verdict fields per Process G5; edit nothing; ask nothing |
| Implement | stage is implement; asked how to build a stated requirement; or the required output asks for changed_files |
Present the ordered steps, then write the code if asked | Follow the steps and edit the files; return what the caller asks (e.g. changed_files, checks); ask nothing |
- A refactor request is implement mode with "behaviour unchanged" as the requirement: pin current behaviour with tests (step I2), then restructure.
- A caller's required output always overrides this skill's Output Template. When nobody can answer, an open point becomes a recorded assumption, never a question.
When to Use / When Not to Use
| Use | Skip |
|---|---|
| Quality gate or PR review of a diff | Architectural layer decisions (use clean-architecture) |
| Refactoring legacy code | Domain modeling (use domain-driven-design) |
| Implementing a stated requirement others will maintain | Performance optimization (profile first) |
| Naming variables, functions, classes | Infrastructure or deployment config |
The Six Dimensions
Names · Functions · Comments & formatting · Error handling · Unit tests · Smells. Patterns, examples and the quick diagnostic: references/review-framework.md. Severity rubric and worked examples of both modes: references/modes.md.
Process
Gate / review mode
- G1 Fix the bar. List the acceptance items you judge against (from the caller, the PR, or the request). None supplied → blocking is reserved for correctness defects; say so. Interactive with no caller acceptance: look up the spec the change claims — issue refs in commit messages (Closes/Fixes #N, ticket keys), a spec/plan path the user names, a docs/ file matching the issue number or branch name. Read it; its items become the acceptance list and its out-of-scope lines count too. None found or the ref dangles → say so in the output and continue as above; never ask. Caller-supplied acceptance or headless: skip the lookup, read nothing beyond the diff.
- G2 Read the diff, dimension by dimension. For each of the six dimensions, check the changed lines and the code they call. Read every comment the change added: one that states behaviour the code does not have is a finding. Run any check you can run (tests, linters) and keep what it printed.
- G3 Record findings. One row per defect:
file:line, dimension, severity (blocking / major / minor — rubric in references/modes.md), verdictfail, the acceptance item it threatens (required when blocking), and the concrete fix. A dimension checked clean gets onepassrow with its line range. Unclear intent → a findingassumption: … — what would settle it, blocking if an acceptance item turns on it. Scope finding: a changed behaviour no spec item asks for, or one the spec puts out of scope — quote the spec line; blocking if the spec explicitly excludes it, major otherwise. - G4 Verdict. FAIL iff any blocking finding; otherwise PASS, majors and minors listed. A 0–10 score is never the verdict.
- G5 Map onto the caller's contract when one is given (teams
gate:accept,match_pct,checks,gaps,observations,reason):- each blocking finding → one
gaps[]entry"<id> <file>:<line> — <severity> — threatens <acceptance> — <fix>"; - each major/minor finding → one
observations[]entry in the same shape; accept: falseiff any blocking finding;- every other required field is still filled as the caller defines it —
match_pct(0–100, share of acceptance met),checks(what you ran or read → what it showed),reason,evidence. Dropping the 0–10 score is not a reason to drop or zero them.
- each blocking finding → one
- G6 Interactive only: add before/after snippets for each fix; give a 0–10 score only if asked (rubric in references/review-framework.md).
Implement mode
Each step names what it leaves in the tree. Worked example: references/modes.md.
- I1 Pin the requirement. List the behaviours, the acceptance items and the error cases. Ambiguity → write the assumption into the handoff. Leaves: case list + assumptions (handoff / notes).
- I2 Cases first. Derive cases with expected results (
develop:test-masterreference mode) and write the test file FIRST, before any implementation file — even when no test runner is available here; the test file is still the first artifact. Where a runner applies, run them and watch them fail for the predicted reason (develop:test-driven-development); otherwise leave the RED proof to the test stage. Leaves: test file path + test names, RED output (or "not run"). - I3 Structure. Decide the file/module and the public surface — only what the requirement names is exported; one responsibility per module. Leaves: paths + exported symbols.
- I4 Names. Domain words from the requirement; predicates for booleans; named constants for every literal with meaning. Leaves: symbol names.
- I5 Function boundaries. One thing per function, one level of abstraction, under ~20 lines, ≤3 parameters, no flag arguments, guard clauses for errors. Leaves: function list.
- I6 Error handling. Typed errors carrying context; no null returns, no empty catch, no silent default; wrap third-party calls. Leaves: error type(s) + a test asserting each.
- I7 GREEN, then tidy. Make the tests pass; remove duplication, magic numbers and "what" comments. Leaves: passing test output.
- I8 Self-gate. Run gate mode G2–G4 over your own diff; fix every blocking and major finding. Leaves: no blocking findings.
In an implement stage these steps are how you do the work: edit the files, then return
the caller's shape (changed_files = files you actually changed, checks = test output).
Returning the steps instead of the code is a failed stage.
Output Template
Used when no caller fixes the output shape (inside a contract, Process G5 / the implement stage note apply instead).
Gate / review
| ID | file:line | Dimension | Severity | Verdict | Threatens | Fix |
|---|---|---|---|---|---|---|
| F1 | path:line | errors | blocking | fail | A2 … | … |
| P1 | path:start-end | names | — | pass | — | — |
Verdict: PASS | FAIL — <n> blocking (<ids>); assumptions: <list or none>.
Implement
| # | Step | What to do | Leaves in tree (path / symbol / test) | Check |
|---|---|---|---|---|
| I1 | Pin requirement | … | … | every acceptance item has a case |
Then: files changed, test command → output.
What Claude Does / What You Do
| Claude | You |
|---|---|
| Gate, headless: judges the diff, records findings with file:line, fills the caller's verdict fields; asks nothing | — |
| Gate, interactive: same findings + verdict, before/after snippets, a score only if asked | Share the diff and acceptance; confirm business intent behind code flagged assumption |
Implement, headless: follows I1–I8, edits files, returns changed_files + checks; asks nothing |
— |
| Implement, interactive: presents the steps, then writes the code and tests | State the requirement; approve the steps; merge after review |
Reference Files
- review-framework.md — six dimensions, quick diagnostic, optional score
- modes.md — severity rubric, finding/gaps examples, implement walkthrough
- naming-conventions.md
- functions-and-methods.md
- comments-formatting.md
- error-handling.md
- testing-principles.md
- code-smells.md
Related Skills
develop:test-master— case lists with expected results (reference mode) for step I2develop:test-driven-development— the RED proof for step I2develop:clean-architecture— architectural layer structure and dependency ruledevelop:domain-driven-design— domain modeling and ubiquitous language
04 同仓库更多 Skills
diagram
Use when something must be drawn as a checked figure, not Mermaid: page layout, B-tree, lock timeline, ER, benchmark chart, architecture, sequence. SVG + PNG. Triggers: "도식화해줘", "그림으로 그려줘", "책에 넣을 그림", "시퀀스 다이어그램", "draw this as a figure".
test-master
Use when writing, improving, or auditing tests, or writing case specs with expected results from a spec. Triggers: "테스트 작성", "테스트 케이스 작성", "test case writing", "단위 테스트", "커버리지 분석", "test plan", "defect report".
sre-engineer
Use when setting up production reliability practices. Triggers on: "SLO 정하고 싶어", "에러 버짓", "알람 피로", "반복 작업(toil) 줄이기", "golden signals dashboard", "burn-rate alert". Not for active incidents or chaos tests.
sql-pro
Use when someone needs help writing or rewriting SQL — authoring complex joins, CTEs, window functions, or recursive queries — or designing a schema from scratch, normalizing an existing one, or migrating queries between database dialects.
spring-boot-engineer
Use when building or extending a Spring Boot 3.x Java backend — REST, Spring Security, JPA, WebFlux, Actuator. Triggers on: "Spring Boot API", "스프링 시큐리티 설정", "JPA 연동". Not for service decomposition or query tuning.
spec-driven-development
Use when a feature should be specified before it is coded — stories, acceptance criteria, tasks, a per-criterion check. Triggers: "스펙 먼저", "명세부터 쓰고 구현", "수용 기준 먼저", "spec first", "spec-driven development".