mcpbeat Sign in

Clean Code Agent Skill

Apply clean code principles when generating or modifying implementation code. Enforces function focus, naming clarity, complexity management, error handling, and self-documenting style. Use during code generation, refactoring, or when the user mentions 'clean code', 'code quality', 'refactor this', 'simplify this', 'improve this', 'make this cleaner', 'clean this up', 'tidy this', 'coding guidelines', or 'implementation quality'. This skill governs the craft of writing individual code units -- not architecture (see architecture), not security posture (see secure-coding), and not test structure (see test-quality).

5k tokens
context cost
the whole folder, loaded on every use
2
files
instructions only
0
copies elsewhere
how many repositories repackaged it
169
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/techygarg/lattice --skill clean-code

The instruction itself

5 sections, as written by the author

Clean Code

Config Resolution

Skill support project custom. Order:

  • Look .lattice/config.yaml in repo root
  • If found, check paths.clean_code for custom doc path
  • If custom path exist, read doc and check YAML frontmatter for mode:
  • mode: override (or no mode): Custom doc full precedence. Use instead embedded default. Must be comprehensive -- sole reference.
  • mode: overlay: Read embedded ./references/defaults.md first, then apply custom doc sections on top. Custom sections replace matching sections in default (matched by heading). New sections appended after default.
  • If no config/path/file, read ./references/defaults.md
  • Language adaptation: If paths.language_idioms exist in config, read that document and adapt defaults using these sections:
  • "Error Handling" → adapt §8 (Error Handling) patterns to language idioms. Language idioms take precedence over pseudocode defaults.
  • "Type System & Object Model" → adapt §1 (Single Responsibility) cohesion guidance to language constructs (e.g., struct vs class).
  • "Naming Conventions" → adapt §4 (Meaningful Naming) patterns to language conventions.
  • "Parameter & Function Design" → adapt §2 (Small, Focused Functions) and §5 (Parameter Design) to language capabilities.
  • "Dependency Management" → adapt §9 (Test-Friendly Code) DI patterns to language idioms.

Self-Validation Checklist

STOP after each component. Verify ALL. Fix any failed check before presenting. Judgment calls → flag with options (see Ambiguity Signals).

  • SINGLE RESPONSIBILITY: Describe each function without "and"? If not → extract separate function.
  • SIZE: Each function under size threshold per loaded doc (~20 lines default)? If not → extract sub-operation into named function.
  • COMPLEXITY: Cyclomatic complexity under threshold per loaded doc (~10 default)? If not → flatten with guard clause, extract branch.
  • ABSTRACTION LEVEL: Each function operate at one level? If high-level mixed with low-level → extract detail.
  • NAMING: Function/variable name reveal intent without context? If not → rename self-documenting.
  • PARAMETERS: Parameter count under threshold per loaded doc (4 default)? If not → group into object.
  • PRIMITIVE OBSESSION: String/number/boolean clearer as named type? If so → introduce parameter object or typed wrapper.
  • ERROR HANDLING: Every fail-able operation have explicit handling with actionable message? Handled at right level?

Project-specific checks: If loaded doc (from Config Resolution) contains a Validation Checklist section (§10), apply those checks as additional project-specific validation after the checklist above.

Active Anti-Pattern Scan

After checklist, scan for these. If find, fix before present.

  • [ ] God Function: Function exceed ~30 lines doing multiple thing; description need "and" → extract focused function
  • [ ] Deep Nesting: Three+ level indentation → flatten with early return/guard clause
  • [ ] Cryptic Naming: Variable like d, tmp2, processData → rename reveal intent
  • [ ] Long Parameter Lists: Five+ parameter → group into object or split function
  • [ ] Premature Abstraction: Utility extracted from only two similar block → inline until Rule of Three with same reason to change
  • [ ] Swallowed Errors: Empty catch, generic "something went wrong," silently return null → handle explicitly
  • [ ] Comments as Deodorant: Comment explain convoluted code instead refactor → rename self-documenting; keep only "why" comment, remove "what"
  • [ ] Hidden Side Effects: Function named getX also write cache/send notification → rename or separate
  • [ ] Dead Code: Commented-out block, unused import, unreachable branch → delete (version control preserve)
  • [ ] Untestable Logic: Side effect tangled with business logic; unit test need mock I/O → push side effect to boundary, extract pure function, inject dependency

Ambiguity Signals

Multiple valid outcome. Present option rather than silently choose. See ./references/defaults.md for resolution guidance on each signal below.

  • Single Responsibility: Two tightly-coupled sequential operation may be one responsibility (pipeline), not two. "And" test catch true violation AND false positive.
  • Function Size: Near-threshold (20-30 lines) with one clear purpose -- extract may create five unclear smaller function. Present tradeoff.
  • DRY vs Premature Abstraction: Two identical block may serve different purpose and diverge. Until third instance with same reason to change, genuinely ambiguous.
  • Error Handling Strategy: Exception vs Result type vs error code depend on language idiom and team convention, not universal.

Other skills for the same job

different authors, same section of the catalogue
Git Commit
by github
vendor ×3

Execute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical grouping

799 tokens
Github Code Review
by ComeOnOliver
×3

Comprehensive GitHub code review with AI-powered swarm coordination

13k tokens
Commit Work
by softaworks
×2

Create high-quality git commits: review/stage intended changes, split into logical commits, and write clear commit messages (including Conventional Commits). Use when the user asks to commit, craft a commit message, stage changes, or split work into multiple commits.

2k tokens
Verification & Quality Assurance
by Microck
×2

Comprehensive truth scoring, code quality verification, and automatic rollback system with 0.95 accuracy threshold for ensuring high-quality agent outputs and codebase reliability.

4k tokens
Gh CLI
by christophacham
×2

GitHub CLI (gh) comprehensive reference for repositories, issues, pull requests, Actions, projects, releases, gists, codespaces, organizations, extensions, and all GitHub operations from the command line.

10k tokens
Github
by Dicklesworthstone
×2

GitHub CLI - manage repositories, issues, pull requests, actions, releases, and more from the command line.

1k tokens
Codebase Cleanup Refactor Clean
by ComeOnOliver
×2

You are a code refactoring expert specializing in clean code principles, SOLID design patterns, and modern software engineering best practices. Analyze and refactor the provided code to improve its quality, maintainability, and performance.

9k tokens
Codebase Cleanup Tech Debt
by ComeOnOliver
×2

You are a technical debt expert specializing in identifying, quantifying, and prioritizing technical debt in software projects. Analyze the codebase to uncover debt, assess its impact, and create acti

6k tokens

How to use it

Copy the folder

Take techygarg/clean-code from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.