[IMPORTANT] Use TaskCreate to break ALL work into small tasks BEFORE starting — including tasks for each file read. This prevents context loss from long files. For simple tasks, AI MUST ask user whether to skip.
Prerequisites: MUST READ before executing:
.claude/skills/shared/understand-code-first-protocol.md
.claude/skills/shared/evidence-based-reasoning-protocol.md
.claude/skills/shared/design-patterns-quality-checklist.md — Design pattern opportunities, anti-pattern detection, DRY/abstraction enforcement
docs/project-reference/domain-entities-reference.md — Domain entity catalog, relationships, cross-service sync (read when task involves business entities/models)
External Memory: For complex or lengthy work (research, analysis, scan, review), write intermediate findings and final results to a report file in plans/reports/ — prevents context loss and serves as deliverable.
Evidence Gate: MANDATORY IMPORTANT MUST — every claim, finding, and recommendation requires file:line proof or traced evidence with confidence percentage (>80% to act, <80% must verify first).
OOP & DRY Enforcement: MANDATORY IMPORTANT MUST — flag duplicated patterns that should be extracted to a base class, generic, or helper. Classes in the same group or suffix (ex *Entity, *Dto, *Service, etc...) MUST inherit a common base (even if empty now — enables future shared logic and child overrides). Verify project has code linting/analyzer configured for the stack.
Quick Summary
Goal: Simplify and refine code for clarity, consistency, and maintainability while preserving all functionality.
MANDATORY IMPORTANT MUST Plan ToDo Task to READ the following project-specific reference docs:
docs/project-reference/code-review-rules.md — anti-patterns, review checklists, quality standards (READ FIRST)
project-structure-reference.md — project patterns and structure
If files not found, search for: project documentation, coding standards, architecture docs.
Workflow:
- Identify Targets — Recent git changes or specified files (skip generated/vendor)
- Analyze — Find complexity hotspots (nesting >3, methods >20 lines), duplicates, naming issues
- Apply Simplifications — One refactoring type at a time following KISS/DRY/YAGNI
- Verify — Run related tests, confirm no behavior changes
Key Rules:
- Preserve all existing functionality; no behavior changes
- Follow platform patterns (Entity expressions, fluent helpers, project store base (search for: store base class), BEM)
- Keep tests passing after every change
Frontend/UI Context (if applicable)
When this task involves frontend or UI changes, MUST READ .claude/skills/shared/ui-system-context.md and the following docs:
- Component patterns:
docs/project-reference/frontend-patterns-reference.md
- Styling/BEM guide:
docs/project-reference/scss-styling-guide.md
- Design system tokens:
docs/project-reference/design-system/README.md
Code Simplifier Skill
Simplify and refine code for clarity, consistency, and maintainability.
Usage
/code-simplifier # Simplify recently modified files
/code-simplifier path/to/file.ts # Simplify specific file
/code-simplifier --scope=function # Focus on function-level simplification
Simplification Mindset
Be skeptical. Verify before simplifying. Every change needs proof it preserves behavior.
- Do NOT assume code is redundant — verify by tracing call paths and reading implementations
- Before removing/replacing code, grep for all usages to confirm nothing depends on the current form
- Before flagging a convention violation, grep for 3+ existing examples — codebase convention wins
- Every simplification must include
file:line evidence of what was verified
- If unsure whether simplification preserves behavior, do NOT apply it
What It Does
- Analyzes code for unnecessary complexity
- Identifies opportunities to simplify without changing behavior
- Applies KISS, DRY, and YAGNI principles
- Preserves all existing functionality
- Follows convention — grep for 3+ existing patterns before applying simplifications
Readability Checklist (MUST evaluate)
Before finishing, verify the code is easy to read, easy to maintain, easy to understand:
- Schema visibility — If a function computes a data structure (object, map, config), add a comment showing the output shape so readers don't have to trace the code
- Non-obvious data flows — If data transforms through multiple steps (A → B → C), add a brief comment explaining the pipeline
- Self-documenting signatures — Function params should explain their role; remove unused params
- Magic values — Replace unexplained numbers/strings with named constants or add inline rationale
- Naming clarity — Variables/functions should reveal intent without reading the implementation
Simplification Targets
- Redundant code paths
- Over-engineered abstractions
- Unnecessary comments (self-documenting code preferred)
- Complex conditionals that can be flattened
- Verbose patterns that have simpler alternatives
Execution
Use the code-simplifier:code-simplifier subagent:
Task(subagent_type="code-simplifier:code-simplifier", prompt="Review and simplify [target files]")
Examples
Before:
function getData() {
const result = fetchData();
if (result !== null && result !== undefined) {
return result;
} else {
return null;
}
}
After:
function getData() {
return fetchData() ?? null;
}
Workflow
Identify targets
- If no arguments:
git diff --name-only HEAD~1 for recent changes
- If arguments provided: use specified files/patterns
- Skip: generated code, migrations, vendor files
Analyze each file
- Identify complexity hotspots (nesting > 3, methods > 20 lines)
- Find duplicated code patterns
- Check naming clarity
Design Pattern Assessment (per design-patterns-quality-checklist.md)
- DRY/Abstraction: Flag duplicate patterns extractable to base class, generic, or helper
- Right Responsibility: Verify logic is in lowest appropriate layer (Entity > Service > Component)
- Pattern Opportunities: Check for creational/structural/behavioral pattern opportunities (switch→Strategy, scattered new→Factory, etc.)
- Anti-Patterns: Flag God Objects, Copy-Paste, Circular Dependencies, Singleton overuse
- Guard against over-engineering: Only recommend patterns with evidence of 3+ occurrences of the problem
Apply simplifications
- One refactoring type at a time
- Preserve all functionality
- Follow platform patterns
Verify
- Run related tests if available
- Confirm no behavior changes
Project Patterns
Backend
- Extract to entity static expressions (search for: entity expression pattern)
- Use fluent helpers (search for: fluent helper pattern in docs/project-reference/backend-patterns-reference.md)
- Move mapping to DTO mapping methods (search for: DTO mapping pattern)
- Use project validation fluent API (see docs/project-reference/backend-patterns-reference.md)
- Check entity expressions have database indexes
- Verify document database index methods exist for collections
[IMPORTANT] Database Performance Protocol (MANDATORY):
- Paging Required — ALL list/collection queries MUST use pagination. NEVER load all records into memory. Verify: no unbounded
GetAll(), ToList(), or Find() without Skip/Take or cursor-based paging.
- Index Required — ALL query filter fields, foreign keys, and sort columns MUST have database indexes configured. Verify: entity expressions match index field order, database collections have index management methods, migrations include indexes for WHERE/JOIN/ORDER BY columns.
Frontend
- Use
project store base (search for: store base class) for state management
- Apply subscription cleanup pattern (search for: subscription cleanup pattern) to all subscriptions
- Ensure BEM class naming on all template elements
- Use platform base classes (
project base component (search for: base component class), project store component base (search for: store component base class))
Constraints
- Preserve functionality — No behavior changes
- Keep tests passing — Verify after changes
- Follow patterns — Use platform conventions
- Document intent — Add comments only where non-obvious
- Doc staleness — After simplifications, cross-reference changed files against related docs (feature docs, test specs, READMEs); flag any that need updating
Related
IMPORTANT Task Planning Notes (MUST FOLLOW)
- Always plan and break work into many small todo tasks
- Always add a final review todo task to verify work quality and identify fixes/enhancements
Workflow Recommendation
IMPORTANT MUST: If you are NOT already in a workflow, use AskUserQuestion to ask the user:
- Activate
quality-audit workflow (Recommended) — code-simplifier → review-changes → code-review
- Execute
/code-simplifier directly — run this skill standalone
Next Steps
MANDATORY IMPORTANT MUST after completing this skill, use AskUserQuestion to recommend:
- "/review-changes (Recommended)" — Review all changes before commit
- "/code-review" — Full code review
- "Skip, continue manually" — user decides
Closing Reminders
MANDATORY IMPORTANT MUST break work into small todo tasks using TaskCreate BEFORE starting.
MANDATORY IMPORTANT MUST validate decisions with user via AskUserQuestion — never auto-decide.
MANDATORY IMPORTANT MUST add a final review todo task to verify work quality.
1---2name: code-simplifier-83description: [Code Quality] Simplifies and refines code for clarity, consistency, and maintainability while preserving all functionality. Focuses on recently modified code unless instructed otherwise.4---5
6> **[IMPORTANT]** Use `TaskCreate` to break ALL work into small tasks BEFORE starting — including tasks for each file read. This prevents context loss from long files. For simple tasks, AI MUST ask user whether to skip.
7
8**Prerequisites:** **MUST READ** before executing:
9
10- `.claude/skills/shared/understand-code-first-protocol.md`
11- `.claude/skills/shared/evidence-based-reasoning-protocol.md`
12- `.claude/skills/shared/design-patterns-quality-checklist.md` — Design pattern opportunities, anti-pattern detection, DRY/abstraction enforcement
13- `docs/project-reference/domain-entities-reference.md` — Domain entity catalog, relationships, cross-service sync (read when task involves business entities/models)
14
15> **External Memory:** For complex or lengthy work (research, analysis, scan, review), write intermediate findings and final results to a report file in `plans/reports/` — prevents context loss and serves as deliverable.
16
17> **Evidence Gate:** MANDATORY IMPORTANT MUST — every claim, finding, and recommendation requires `file:line` proof or traced evidence with confidence percentage (>80% to act, <80% must verify first).
18
19> **OOP & DRY Enforcement:** MANDATORY IMPORTANT MUST — flag duplicated patterns that should be extracted to a base class, generic, or helper. Classes in the same group or suffix (ex *Entity, *Dto, \*Service, etc...) MUST inherit a common base (even if empty now — enables future shared logic and child overrides). Verify project has code linting/analyzer configured for the stack.
20
21## Quick Summary
22
23**Goal:** Simplify and refine code for clarity, consistency, and maintainability while preserving all functionality.
24
25> **MANDATORY IMPORTANT MUST** Plan ToDo Task to READ the following project-specific reference docs:
26>
27> - `docs/project-reference/code-review-rules.md` — anti-patterns, review checklists, quality standards **(READ FIRST)**
28> - `project-structure-reference.md` — project patterns and structure
29>
30> If files not found, search for: project documentation, coding standards, architecture docs.
31
32**Workflow:**
33
341. **Identify Targets** — Recent git changes or specified files (skip generated/vendor)
352. **Analyze** — Find complexity hotspots (nesting >3, methods >20 lines), duplicates, naming issues
363. **Apply Simplifications** — One refactoring type at a time following KISS/DRY/YAGNI
374. **Verify** — Run related tests, confirm no behavior changes
38
39**Key Rules:**
40
41- Preserve all existing functionality; no behavior changes
42- Follow platform patterns (Entity expressions, fluent helpers, project store base (search for: store base class), BEM)
43- Keep tests passing after every change
44
45### Frontend/UI Context (if applicable)
46
47When this task involves frontend or UI changes, **MUST READ** `.claude/skills/shared/ui-system-context.md` and the following docs:
48
49- Component patterns: `docs/project-reference/frontend-patterns-reference.md`
50- Styling/BEM guide: `docs/project-reference/scss-styling-guide.md`
51- Design system tokens: `docs/project-reference/design-system/README.md`
52
53# Code Simplifier Skill
54
55Simplify and refine code for clarity, consistency, and maintainability.
56
57## Usage
58
59```
60/code-simplifier # Simplify recently modified files
61/code-simplifier path/to/file.ts # Simplify specific file
62/code-simplifier --scope=function # Focus on function-level simplification
63```
64
65## Simplification Mindset
66
67**Be skeptical. Verify before simplifying. Every change needs proof it preserves behavior.**
68
69- Do NOT assume code is redundant — verify by tracing call paths and reading implementations
70- Before removing/replacing code, grep for all usages to confirm nothing depends on the current form
71- Before flagging a convention violation, grep for 3+ existing examples — codebase convention wins
72- Every simplification must include `file:line` evidence of what was verified
73- If unsure whether simplification preserves behavior, do NOT apply it
74
75## What It Does
76
771. **Analyzes** code for unnecessary complexity
782. **Identifies** opportunities to simplify without changing behavior
793. **Applies** KISS, DRY, and YAGNI principles
804. **Preserves** all existing functionality
815. **Follows convention** — grep for 3+ existing patterns before applying simplifications
82
83## Readability Checklist (MUST evaluate)
84
85Before finishing, verify the code is **easy to read, easy to maintain, easy to understand**:
86
87- **Schema visibility** — If a function computes a data structure (object, map, config), add a comment showing the output shape so readers don't have to trace the code
88- **Non-obvious data flows** — If data transforms through multiple steps (A → B → C), add a brief comment explaining the pipeline
89- **Self-documenting signatures** — Function params should explain their role; remove unused params
90- **Magic values** — Replace unexplained numbers/strings with named constants or add inline rationale
91- **Naming clarity** — Variables/functions should reveal intent without reading the implementation
92
93## Simplification Targets
94
95- Redundant code paths
96- Over-engineered abstractions
97- Unnecessary comments (self-documenting code preferred)
98- Complex conditionals that can be flattened
99- Verbose patterns that have simpler alternatives
100
101## Execution
102
103Use the `code-simplifier:code-simplifier` subagent:
104
105```
106Task(subagent_type="code-simplifier:code-simplifier", prompt="Review and simplify [target files]")
107```
108
109## Examples
110
111**Before:**
112
113```typescript
114function getData() {
115 const result = fetchData();
116 if (result !== null && result !== undefined) {
117 return result;
118 } else {
119 return null;
120 }
121}
122```
123
124**After:**
125
126```typescript
127function getData() {
128 return fetchData() ?? null;
129}
130```
131
132## Workflow
133
1341. **Identify targets**
135 - If no arguments: `git diff --name-only HEAD~1` for recent changes
136 - If arguments provided: use specified files/patterns
137 - Skip: generated code, migrations, vendor files
138
1392. **Analyze each file**
140 - Identify complexity hotspots (nesting > 3, methods > 20 lines)
141 - Find duplicated code patterns
142 - Check naming clarity
143
1443. **Design Pattern Assessment** (per `design-patterns-quality-checklist.md`)
145 - **DRY/Abstraction:** Flag duplicate patterns extractable to base class, generic, or helper
146 - **Right Responsibility:** Verify logic is in lowest appropriate layer (Entity > Service > Component)
147 - **Pattern Opportunities:** Check for creational/structural/behavioral pattern opportunities (switch→Strategy, scattered new→Factory, etc.)
148 - **Anti-Patterns:** Flag God Objects, Copy-Paste, Circular Dependencies, Singleton overuse
149 - **Guard against over-engineering:** Only recommend patterns with evidence of 3+ occurrences of the problem
150
1514. **Apply simplifications**
152 - One refactoring type at a time
153 - Preserve all functionality
154 - Follow platform patterns
155
1565. **Verify**
157 - Run related tests if available
158 - Confirm no behavior changes
159
160## Project Patterns
161
162### Backend
163
164- Extract to entity static expressions (search for: entity expression pattern)
165- Use fluent helpers (search for: fluent helper pattern in docs/project-reference/backend-patterns-reference.md)
166- Move mapping to DTO mapping methods (search for: DTO mapping pattern)
167- Use project validation fluent API (see docs/project-reference/backend-patterns-reference.md)
168- Check entity expressions have database indexes
169- Verify document database index methods exist for collections
170
171> **[IMPORTANT] Database Performance Protocol (MANDATORY):**
172>
173> 1. **Paging Required** — ALL list/collection queries MUST use pagination. NEVER load all records into memory. Verify: no unbounded `GetAll()`, `ToList()`, or `Find()` without `Skip/Take` or cursor-based paging.
174> 2. **Index Required** — ALL query filter fields, foreign keys, and sort columns MUST have database indexes configured. Verify: entity expressions match index field order, database collections have index management methods, migrations include indexes for WHERE/JOIN/ORDER BY columns.
175
176### Frontend
177
178- Use `project store base (search for: store base class)` for state management
179- Apply subscription cleanup pattern (search for: subscription cleanup pattern) to all subscriptions
180- Ensure BEM class naming on all template elements
181- Use platform base classes (`project base component (search for: base component class)`, `project store component base (search for: store component base class)`)
182
183## Constraints
184
185- **Preserve functionality** — No behavior changes
186- **Keep tests passing** — Verify after changes
187- **Follow patterns** — Use platform conventions
188- **Document intent** — Add comments only where non-obvious
189- **Doc staleness** — After simplifications, cross-reference changed files against related docs (feature docs, test specs, READMEs); flag any that need updating
190
191## Related
192
193- `code-review`
194- `refactoring`
195
196---
197
198**IMPORTANT Task Planning Notes (MUST FOLLOW)**
199
200- Always plan and break work into many small todo tasks
201- Always add a final review todo task to verify work quality and identify fixes/enhancements
202
203---
204
205## Workflow Recommendation
206
207> **IMPORTANT MUST:** If you are NOT already in a workflow, use `AskUserQuestion` to ask the user:
208>
209> 1. **Activate `quality-audit` workflow** (Recommended) — code-simplifier → review-changes → code-review
210> 2. **Execute `/code-simplifier` directly** — run this skill standalone
211
212---
213
214## Next Steps
215
216**MANDATORY IMPORTANT MUST** after completing this skill, use `AskUserQuestion` to recommend:
217
218- **"/review-changes (Recommended)"** — Review all changes before commit
219- **"/code-review"** — Full code review
220- **"Skip, continue manually"** — user decides
221
222## Closing Reminders
223
224**MANDATORY IMPORTANT MUST** break work into small todo tasks using `TaskCreate` BEFORE starting.
225**MANDATORY IMPORTANT MUST** validate decisions with user via `AskUserQuestion` — never auto-decide.
226**MANDATORY IMPORTANT MUST** add a final review todo task to verify work quality.