Code Cleanup
Overview
Performs post-review cosmetic cleanup to make code production-ready. This workflow is now integrated as Phase T-7 of /developer-kit-specs:specs.task-implementation. It can also be invoked manually using --action=cleanup.
Input: docs/specs/[id]/tasks/TASK-XXX.md (reviewed status)
Output: Cleaned code, task marked completed
When to Use
- Use when asked to clean up code, polish, finalize, tidy up, or remove technical debt after review approval.
- Use to prepare code for completion: remove debug logs, dead code, optimize imports, and improve readability.
- Use as the final quality gate in the specification-driven development workflow.
- Not for refactoring logic or fixing bugs — focused solely on cosmetic and hygiene cleanup.
Arguments
| Argument |
Required |
Description |
--lang |
No |
java, spring, typescript, nestjs, react, python, general |
--task |
Yes |
Path to task file |
--action |
No |
Set to cleanup for manual invocation |
Best Practices
- Clean, not change: Only remove or reorganize — never change functionality
- Preserve behavior: Code must work exactly the same after cleanup
- Use project tools: Prefer
./mvnw spotless:apply, npm run lint:fix, black, etc.
- Use TodoWrite: Track progress through all 8 phases
- Stop on failure: If tests fail, stop and report — do not proceed
See references/language-patterns.md for language-specific formatter commands, import ordering, and grep patterns.
Instructions
Phase 1: Task Verification
Parse $ARGUMENTS for parameters:
--lang (optional): Target language/framework
--task (required): Task ID or file path
--spec (optional): Spec folder path (used with task ID)
Support two formats:
- Format 1 (direct path):
--task=docs/specs/001-feature/tasks/TASK-001.md
- Format 2 (spec+task):
--spec=docs/specs/001-feature --task=TASK-001
If Format 2 is used, construct the task file path as: {spec}/tasks/{task}.md
Read the task file. Verify:
- Status is
reviewed or implemented (not completed)
- Review report
TASK-XXX--review.md exists and is approved
If not reviewed → stop and tell user to run /developer-kit-specs:specs.task-review first
Extract task ID, title, and provides files
Phase 2: Identify Files to Clean
- Read
TASK-XXX--review.md for files created/modified
- Read task
provides field for file paths
- Verify files exist; build cleanup list
- Categorize: source files, test files, config files
Phase 3: Technical Debt Removal
Search files for temporary/debug artifacts with Grep:
console.log, System.out.println, print(, // DEBUG:, // temp, // hack
- Resolved
TODO/FIXME comments (keep unresolved ones)
Review context for each finding. Remove confirmed debt and document what was removed.
Phase 4: Import Optimization
- Run language-specific import optimizer if available (see references)
- Manually remove unused imports if no tool exists
- Document files changed
Phase 5: Code Readability Improvements
- Run language-specific formatter if available (see references)
- If no formatter: fix indentation, break long lines (>120), fix spacing
- Remove dead code only if obviously safe
- Document changes
Phase 6: Documentation Verification
- Verify class/file headers and public API docs
- Check remaining TODOs are still valid and have context
- Remove or update outdated comments
- Document documentation changes
Phase 7: Final Verification
- Run linters if available
- Run tests if available
- Verify no logic or signature changes were introduced
- If tests fail → stop and report failures
Phase 8: Task Completion
Auto-update task status:
- Add a
## Cleanup Summary section to the task file
- Check any remaining boxes in the DoD section
- Hooks automatically update status to
completed and set completed_date + cleanup_date
Append ## Cleanup Summary to task file with:
- Files cleaned
- Changes made
- Verification checklist (linters, tests, no functionality changes)
Mark all todos complete
Examples
Spring Boot Cleanup
/developer-kit-specs:specs.task-implementation --lang=spring --task="docs/specs/001-user-auth/tasks/TASK-001.md" --action=cleanup
Actions:
- Verify TASK-001 status is
reviewed
- Files:
UserController.java, UserService.java, UserRepository.java
- Remove 5
System.out.println and 2 resolved TODOs
- Run
./mvnw spotless:apply
- Run
./mvnw test -q
- Mark task
completed
TypeScript Cleanup
/developer-kit-specs:specs.task-implementation --lang=typescript --task="docs/specs/002-dashboard/tasks/TASK-003.md" --action=cleanup
Actions:
- Verify TASK-003 status is
reviewed
- Files:
Dashboard.tsx, useDashboard.ts, Dashboard.test.tsx
- Remove 8
console.log statements
- Run
npm run lint:fix and npm run format
- Run
npm test
- Mark task
completed
Constraints and Warnings
- Never change logic or signatures during cleanup
- Stop immediately and report if tests fail
- Verify behavior is unchanged before marking complete
1---2name: specs-code-cleanup3description: Provides final code cleanup after task review approval. Removes debug logs, temporary comments, dead code, optimizes imports, and improves readability. Use when asked to clean up code, polish, finalize, tidy up, remove technical debt, or prepare code for completion after review. Not for refactoring logic or fixing bugs—focused solely on cosmetic and hygiene cleanup.4---5
6# Code Cleanup
7
8## Overview
9
10Performs post-review cosmetic cleanup to make code production-ready. This workflow is now integrated as Phase T-7 of `/developer-kit-specs:specs.task-implementation`. It can also be invoked manually using `--action=cleanup`.
11
12**Input**: `docs/specs/[id]/tasks/TASK-XXX.md` (reviewed status)
13**Output**: Cleaned code, task marked `completed`
14
15## When to Use
16
17- Use when asked to clean up code, polish, finalize, tidy up, or remove technical debt after review approval.
18- Use to prepare code for completion: remove debug logs, dead code, optimize imports, and improve readability.
19- Use as the final quality gate in the specification-driven development workflow.
20- Not for refactoring logic or fixing bugs — focused solely on cosmetic and hygiene cleanup.
21
22## Arguments
23
24| Argument | Required | Description |
25|----------|----------|-------------|
26| `--lang` | No | `java`, `spring`, `typescript`, `nestjs`, `react`, `python`, `general` |
27| `--task` | Yes | Path to task file |
28| `--action`| No | Set to `cleanup` for manual invocation |
29
30## Best Practices
31
32- **Clean, not change**: Only remove or reorganize — never change functionality
33- **Preserve behavior**: Code must work exactly the same after cleanup
34- **Use project tools**: Prefer `./mvnw spotless:apply`, `npm run lint:fix`, `black`, etc.
35- **Use TodoWrite**: Track progress through all 8 phases
36- **Stop on failure**: If tests fail, stop and report — do not proceed
37
38See `references/language-patterns.md` for language-specific formatter commands, import ordering, and grep patterns.
39
40## Instructions
41
42### Phase 1: Task Verification
43
441. Parse `$ARGUMENTS` for parameters:
45 - `--lang` (optional): Target language/framework
46 - `--task` (required): Task ID or file path
47 - `--spec` (optional): Spec folder path (used with task ID)
48
49 **Support two formats**:
50 - Format 1 (direct path): `--task=docs/specs/001-feature/tasks/TASK-001.md`
51 - Format 2 (spec+task): `--spec=docs/specs/001-feature --task=TASK-001`
52
53 If Format 2 is used, construct the task file path as: `{spec}/tasks/{task}.md`
54
552. Read the task file. Verify:
56 - Status is `reviewed` or `implemented` (not `completed`)
57 - Review report `TASK-XXX--review.md` exists and is approved
583. If not reviewed → stop and tell user to run `/developer-kit-specs:specs.task-review` first
594. Extract task ID, title, and `provides` files
60
61### Phase 2: Identify Files to Clean
62
631. Read `TASK-XXX--review.md` for files created/modified
642. Read task `provides` field for file paths
653. Verify files exist; build cleanup list
664. Categorize: source files, test files, config files
67
68### Phase 3: Technical Debt Removal
69
70Search files for temporary/debug artifacts with Grep:
71- `console.log`, `System.out.println`, `print(`, `// DEBUG:`, `// temp`, `// hack`
72- Resolved `TODO`/`FIXME` comments (keep unresolved ones)
73
74Review context for each finding. Remove confirmed debt and document what was removed.
75
76### Phase 4: Import Optimization
77
781. Run language-specific import optimizer if available (see references)
792. Manually remove unused imports if no tool exists
803. Document files changed
81
82### Phase 5: Code Readability Improvements
83
841. Run language-specific formatter if available (see references)
852. If no formatter: fix indentation, break long lines (>120), fix spacing
863. Remove dead code only if obviously safe
874. Document changes
88
89### Phase 6: Documentation Verification
90
911. Verify class/file headers and public API docs
922. Check remaining TODOs are still valid and have context
933. Remove or update outdated comments
944. Document documentation changes
95
96### Phase 7: Final Verification
97
981. Run linters if available
992. Run tests if available
1003. Verify no logic or signature changes were introduced
1014. If tests fail → stop and report failures
102
103### Phase 8: Task Completion
104
1051. **Auto-update task status**:
106 - Add a `## Cleanup Summary` section to the task file
107 - Check any remaining boxes in the DoD section
108 - Hooks automatically update status to `completed` and set `completed_date` + `cleanup_date`
109
1102. Append `## Cleanup Summary` to task file with:
111 - Files cleaned
112 - Changes made
113 - Verification checklist (linters, tests, no functionality changes)
1143. Mark all todos complete
115
116## Examples
117
118### Spring Boot Cleanup
119
120```bash
121/developer-kit-specs:specs.task-implementation --lang=spring --task="docs/specs/001-user-auth/tasks/TASK-001.md" --action=cleanup
122```
123
124Actions:
1251. Verify TASK-001 status is `reviewed`
1262. Files: `UserController.java`, `UserService.java`, `UserRepository.java`
1273. Remove 5 `System.out.println` and 2 resolved TODOs
1284. Run `./mvnw spotless:apply`
1295. Run `./mvnw test -q`
1306. Mark task `completed`
131
132### TypeScript Cleanup
133
134```bash
135/developer-kit-specs:specs.task-implementation --lang=typescript --task="docs/specs/002-dashboard/tasks/TASK-003.md" --action=cleanup
136```
137
138Actions:
1391. Verify TASK-003 status is `reviewed`
1402. Files: `Dashboard.tsx`, `useDashboard.ts`, `Dashboard.test.tsx`
1413. Remove 8 `console.log` statements
1424. Run `npm run lint:fix` and `npm run format`
1435. Run `npm test`
1446. Mark task `completed`
145
146## Constraints and Warnings
147
148- Never change logic or signatures during cleanup
149- Stop immediately and report if tests fail
150- Verify behavior is unchanged before marking complete