Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/eyalgo-refactor-for-clarity
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/refactor-for-clarity
What's inside
- Skill name
refactor-for-clarity- Description
- Refactor code for clarity without changing behavior. Use when the implementation works but is harder to read, follow, or extend than it needs to be — deep nesting, unclear names, long functions, dense logic. Pairs with refactor-for-reuse (redundancy focus).
- License
- MIT
- Metadata
- version: 1.0.1
- Instructions
- 248 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# Refactor for Clarity
## Overview
Refactor code so it communicates clearly — to the next developer, and to future-you. The goal is not fewer lines — it's code that's easier to read, follow, and modify without a mental detour. Every change must pass: "Would a new team member understand this faster than the original?"
## When to Use
- After a feature is working and tests pass, but the implementation feels heavier than it needs to be
- During code review when readability or complexity issues are flagged
- When you encounter deeply nested logic, long functions, or unclear names
- When refactoring code written under time pressure
**When NOT to use:**
- Code is already clean and readable — don't refactor for the sake of it
- You don't understand what the code does yet — comprehend before you refactor
- The code is performance-critical and the "simpler" version would be measurably slower
- You're about to rewrite the module entirely — refactoring throwaway code wastes effort
- The issue is duplication, dead code, or missing extraction — use `refactor-for-reuse` instead
## The Five Principles
### 1. Preserve Behavior Exactly
Don't change what the code does — only how it expresses it. All inputs, outputs, side effects, error behavior, and edge cases must remain identical. If you're not sure a refactoring preserves behavior, don't make it.
```
ASK BEFORE EVERY CHANGE:
→ Does this produce the same output for every input?
→ Does this maintain the same error behavior?
→ Does this preserve the same side effects and ordering?
→ Do all existing tests still pass without modification?
```
### 2. Follow Project Conventions
Refactoring means making code more consistent with the codebase, not imposing external preferences. Before refactoring:
```
1. Read AGENTS.md or CLAUDE.md / project conventions
2. Study how neighboring code handles similar patterns
3. Match the project's style for:
- Import ordering and module system
- Function declaration style
- Naming conventions
- Error handling patterns
- Type annotation depth
```
Refactoring that breaks project consistency is not improvement — it's churn.
### 3. Prefer Clarity Over Cleverness
Explicit code is better than compact code when the compact version requires a mental pause to parse.
```python
# UNCLEAR: Chained ternary
label = 'New' if item.is_new else 'Updated' if item.is_updated else 'Archived' if item.is_archived else 'Active'
# CLEAR: Readable early-return function
def get_status_label(item):
if item.is_new:
return 'New'
if item.is_updated:
return 'Updated'
if item.is_archived:
return 'Archived'
return 'Active'
```
```python
# UNCLEAR: Dense one-liner accumulation
from functools import reduce
count_by_id = reduce(lambda acc, x: {**acc, x.id: acc.get(x.id, 0) + 1}, items, {})
# CLEAR: Named loop
count_by_id = {}
for item in items:
count_by_id[item.id] = count_by_id.get(item.id, 0) + 1
```
### 4. Maintain Balance
Clarity refactoring has a failure mode: over-simplification. Watch for these traps:
- **Inlining too aggressively** — removing a helper that gave a concept a name makes the call site harder to read
- **Combining unrelated logic** — two simple functions merged into one complex function is not simpler
- **Removing "unnecessary" abstraction** — some abstractions exist for extensibility or testability, not complexity
- **Optimizing for line count** — fewer lines is not the goal; easier comprehension is
### 5. Scope to What Changed
Default to refactoring recently modified code. Avoid drive-by changes to unrelated code unless explicitly asked to broaden scope. Unscoped refactoring creates noise in diffs and risks unintended regressions.
## The Refactoring Process
### Step 1: Verify Test Coverage
Before touching anything, confirm the code you're about to refactor is covered by tests. Tests are the only proof that behavior is preserved after structural changes.
If coverage is missing: invoke **`test-driven-development`** to write characterization tests first — tests that pin the current behavior before any refactoring begins. Commit them before proceeding.
If the code's behavior is unclear before writing tests: invoke **`verify-before-claim`** — open the actual files and confirm what the code does before asserting it.
### Step 2: Understand Before Touching (Chesterton's Fence)
Before changing or removing anything, understand why it exists. This is Chesterton's Fence: if you see a fence across a road and don't understand why it's there, don't tear it down. First understand the reason, then decide if the reason still applies.
```
BEFORE REFACTORING, ANSWER:
- What is this code's responsibility?
- What calls it? What does it call?
- What are the edge cases and error paths?
- Are there tests that define the expected behavior?
- Why might it have been written this way? (Performance? Platform constraint? Historical reason?)
- Check git blame: what was the original context for this code?
```From eyalgo/kensaiapp, MIT.
More from eyalgo/kensaiapp
- 0.570score
development-design
eyalgo
Architect-posture skill for ongoing work on an existing project.
SkillAFreshness: AClaude Code +9 - 0.570score
development-content
eyalgo
Content-editor-posture skill for ongoing work.
SkillAFreshness: AClaude Code +9 - 0.565score
first-what-left
eyalgo
CPO-posture skill that writes a product's first what-left file, docs/what_left.md, once the project's Agari is settled.
SkillAFreshness: AClaude Code +9 - 0.565score
product-prd
Eyal Golan
CPO-posture skill that authors a project's PRD — the product source of truth and the head of the definition sequence.
SkillAFreshness: AClaude Code +9 - 0.565score
product-srs
Eyal Golan
CTO-posture skill that authors a project's SRS — the technical source of truth, written off the settled PRD alongside the CDO's UXD.
SkillAFreshness: AClaude Code +9 - 0.565score
readme-status
eyalgo
Content-editor-posture skill that brings a product README's Status section up to what is built.
SkillAFreshness: AClaude Code +9 - 0.565score
refactor-for-optimize
eyalgo
Refactor code for performance — algorithmic complexity, data structure selection, unnecessary I/O, hot-path improvement, and memory usage.
SkillAFreshness: AClaude Code +9 - 0.561score
refactor-for-reuse
eyalgo
Refactor changed code to eliminate duplication, extract shared logic, and remove dead code.
SkillAFreshness: AClaude Code +9 - 0.560score
product-uxd
Eyal Golan
CDO-posture skill that authors a project's UXD — the experience source of truth, written off the settled PRD alongside the CTO's SRS and read by the SDD.
SkillAFreshness: AClaude Code +9 - 0.560score
experience-visual
Eyal Golan
CDO-posture skill that authors a kensaiapp instance's visual experience layer — the fence and the direction every product under that instance inherits…
SkillAFreshness: AClaude Code +9 - 0.560score
product-design
Eyal Golan
CDO-posture skill that authors a project's design language — the visual source of truth in Google's DESIGN.md format, written off the settled UXD's…
SkillAFreshness: AClaude Code +9 - 0.560score
project-agari
Eyal Golan
CPO-posture skill that declares a project's Agari (上がり) — the terminus that says when the product is complete or shipped.
SkillAFreshness: AClaude Code +9
Signals
- Stars
- 0
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- Oct 19, 2026 (11 days ago)
- Last release
- Oct 22, 2026 (7 days ago)
From GitHub (fetched Oct 24, 2026).
Details
- Version
- 1.0.1
- License
- MIT
- Repository
- github.com/eyalgo/kensaiapp
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from eyalgo
- 0.570score
development-design
eyalgo
Architect-posture skill for ongoing work on an existing project.
SkillAFreshness: AClaude Code +9 - 0.570score
development-content
eyalgo
Content-editor-posture skill for ongoing work.
SkillAFreshness: AClaude Code +9 - 0.565score
readme-status
eyalgo
Content-editor-posture skill that brings a product README's Status section up to what is built.
SkillAFreshness: AClaude Code +9 - 0.565score
refactor-for-optimize
eyalgo
Refactor code for performance — algorithmic complexity, data structure selection, unnecessary I/O, hot-path improvement, and memory usage.
SkillAFreshness: AClaude Code +9 - 0.565score
first-what-left
eyalgo
CPO-posture skill that writes a product's first what-left file, docs/what_left.md, once the project's Agari is settled.
SkillAFreshness: AClaude Code +9 - 0.561score
refactor-for-reuse
eyalgo
Refactor changed code to eliminate duplication, extract shared logic, and remove dead code.
SkillAFreshness: AClaude Code +9
Cite this page
refactor-for-clarity skill. Agent Mart. https://agentmart.dev/skills/eyalgo-refactor-for-clarity (last updated 2026-10-24)