clean-code skill
Enforces coding standards such as single responsibility, naming clarity, and complexity management when generating or modifying implementation code.
- GitHub stars
- 211
- Files
- 2
- Last commit
- Oct 24, 2026
- License
- MIT
- Allowed tools
- —
What does the clean-code skill do?
clean-code enforces coding standards such as single responsibility, naming clarity, and complexity management when generating or modifying implementation code.
Summary generated from the skill's SKILL.md.
About the clean-code skill
Maintaining high implementation quality during the coding process is the primary function of this skill. It is designed for developers who need to ensure that every individual code unit follows strict standards for naming clarity, single responsibility, and complexity management. The skill is automatically loaded by specialized agents like code-forge, refactor-safely, and bug-fix when a user requests improvements to code quality or specific coding guidelines.
Instead of focusing on broad architecture or security, this tool governs the craft of writing specific functions and variables. It relies on a configuration system that reads .lattice/config.yaml to apply custom standards or language-specific idioms for error handling and type systems. The skill uses a self-validation checklist to monitor function size, cyclomatic complexity, and parameter counts, ensuring that code remains self-documenting and easy to test. It also performs an active scan for anti-patterns like deep nesting, cryptic naming, and swallowed errors to prevent technical debt from entering the codebase.
What an agent can do with it
- 1Enforce single responsibility in functionsAsk the agent to refactor a large function that performs multiple tasks into smaller, focused units.
- 2Reduce cyclomatic complexityRequest that the agent simplify complex conditional logic within a specific code block.
- 3Improve variable and function namingInstruct the AI to rename variables and functions so their intent is clear without extra comments.
Written from the skill's SKILL.md. Every use case is checked against a quote from it.
How to install the clean-code skill
Each command copies the skill folder into the client's skills directory. Restart the client or start a new session to load it.Install the clean-code skill in Plugin
/plugin marketplace add techygarg/lattice /plugin install lattice@lattice
Install the clean-code skill in Claude Code
~/.claude/skills/clean-code/SKILL.md
$ npx degit techygarg/lattice/skills/clean-code ~/.claude/skills/clean-codeInstall the clean-code skill in Claude Code (project)
.claude/skills/clean-code/SKILL.md
$ npx degit techygarg/lattice/skills/clean-code .claude/skills/clean-codeInstall the clean-code skill in Codex
~/.agents/skills/clean-code/SKILL.md
$ npx degit techygarg/lattice/skills/clean-code ~/.agents/skills/clean-codeInstall the clean-code skill in Gemini CLI
~/.gemini/skills/clean-code/SKILL.md
$ npx degit techygarg/lattice/skills/clean-code ~/.gemini/skills/clean-codeInstall the clean-code skill in Claude.ai
npx degit techygarg/lattice/skills/clean-code clean-code && zip -r clean-code.zip clean-code # claude.ai → Customize → Skills → + → Create skill → Upload a skill → clean-code.zip
SKILL.md
View on GitHubClean Code
Config Resolution
Projects can customize this skill's standards. Resolution order:
- Read
.lattice/config.yamlin the repo root. - If found, check
paths.clean_codefor a custom document path. - If a custom document exists at that path, read it and check its YAML frontmatter for
mode:mode: override: the custom document has full precedence. Use it instead of the embedded defaults. It must be comprehensive -- treat it as the sole reference.mode: overlay(or no mode field): read the embedded./references/defaults.mdfirst, then apply the custom document's sections on top. A custom section replaces the matching default section (matched by exact heading); new sections append after the defaults.
- If a custom path is configured but no document exists at it → tell the user which configured path is missing, then fall back to
./references/defaults.md. - If there is no config file or no
paths.clean_codekey, read./references/defaults.md. - Language adaptation: if
paths.language_idiomsis set in the config and the document exists, read it and adapt the defaults using these sections:- "Error Handling" → adapt §8 (Error Handling) patterns to the language's idioms. Language idioms take precedence over the pseudocode defaults.
- "Type System & Object Model" → adapt §1 (Single Responsibility) cohesion guidance to the language's constructs (e.g., struct vs class).
- "Naming Conventions" → adapt §4 (Meaningful Naming) patterns to the language's conventions.
- "Parameter & Function Design" → adapt §2 (Small, Focused Functions) and §5 (Parameter Design) to the language's capabilities.
- "Dependency Management" → adapt §9 (Test-Friendly Code) dependency-injection patterns to the language's idioms.
Self-Validation Checklist
STOP after generating each component. Verify ALL checks. Fix every failed check before presenting. Judgment calls → present options (see Ambiguity Signals).
- SINGLE RESPONSIBILITY: Can you describe each function without "and"? If not → extract a separate function.
- SIZE: Is each function under the size threshold from the loaded doc (~20 lines default)? If not → extract a sub-operation into its own named function.
- COMPLEXITY: Is cyclomatic complexity under the threshold from the loaded doc (~10 default)? If not → flatten with a guard clause or extract a branch.
- ABSTRACTION LEVEL: Does each function operate at one level of abstraction? If high-level logic mixes with low-level detail → extract the detail.
- NAMING: Does each function/variable name reveal intent without needing surrounding context? If not → rename to be self-documenting.
- PARAMETERS: Is the parameter count under the threshold from the loaded doc (4 default)? If not → group parameters into an object.
- PRIMITIVE OBSESSION: Would a string/number/boolean be clearer as a named type? If so → introduce a parameter object or typed wrapper.
- ERROR HANDLING: Does every fail-able operation have explicit handling with an actionable message? Is it handled at the right level?
Project-specific checks: if the loaded doc (from Config Resolution) contains a Validation Checklist section (§10 from the clean-code-refiner template), apply those checks as additional project-specific validation after the checklist above.
All checks pass → state "Passes clean-code. [next step]."
Active Anti-Pattern Scan
After the checklist, scan for each of these. Any box you can check → fix before presenting.
- God Function: a function exceeds ~30 lines doing multiple things; describing it requires "and" → extract focused functions.
- Deep Nesting: three or more levels of indentation → flatten with early returns / guard clauses.
- Cryptic Naming: variables like
d,tmp2,processData→ rename to reveal intent. - Long Parameter Lists: five or more parameters → group into an object or split the function.
- Premature Abstraction: a utility extracted from only two similar blocks → inline it until the Rule of Three (third instance with the same reason to change).
- Swallowed Errors: empty catch blocks, generic "something went wrong" messages, silent null returns → handle explicitly.
- Comments as Deodorant: a comment explains convoluted code instead of the code being fixed → rename to self-document; keep only "why" comments, remove "what" comments.
- Hidden Side Effects: a function named
getXalso writes a cache or sends notifications → rename or separate the concern. - Dead Code: commented-out blocks, unused imports, unreachable branches → delete them (version control preserves history).
- Untestable Logic: side effects tangled with business logic; unit testing requires mocking I/O → push side effects to the boundary, extract pure functions, inject dependencies.
Ambiguity Signals
Multiple valid outcomes exist. Present the options rather than silently choosing. If framework:collaborative-judgment is loaded, use its presentation format. See ./references/defaults.md for resolution guidance on each signal below.
- Single Responsibility: two tightly-coupled sequential operations may be one responsibility (a pipeline), not two. The "and" test catches true violations AND false positives.
- Function Size: near-threshold size (20–30 lines) with one clear purpose -- extraction may create five unclear smaller functions. Present the tradeoff.
- DRY vs Premature Abstraction: two identical blocks may serve different purposes and diverge independently. Until a third instance with the same reason to change appears, this is genuinely ambiguous.
- Error Handling Strategy: exception vs Result type vs error codes depends on language idiom and team convention, not on universal rules.
Files in this skill
2clean-code skill questions
How do I install the clean-code skill in Claude Code?
Run npx degit techygarg/lattice/skills/clean-code ~/.claude/skills/clean-code. Claude Code loads skills from ~/.claude/skills (all projects) or .claude/skills (one project) and uses a skill when its description matches the task.
Which clients can use the clean-code skill?
Any client that reads the Agent Skills format: Claude Code, Codex, Gemini CLI and claude.ai (upload as a ZIP). Scripts in the skill run only where the client allows code execution.
What are the default thresholds for function size and complexity?
By default, functions should be under approximately 20 lines and maintain a cyclomatic complexity under approximately 10.
How can a project customize the clean code standards?
Projects can customize standards by defining a custom document path in .lattice/config.yaml, using either 'override' mode for full precedence or 'overlay' mode to supplement defaults.