Reverse-engineers specifications from existing code. Use when user says "document what this code does", "create specs from existing code", "I need to understand this codebase before changing it", "audit the code", "what does this feature actually do", "retrofit specs", or mentions brownfield, legacy code, or undocumented systems.
Reverse-engineers specifications from existing codebases by surveying entry points, tracing behavior, and documenting gaps between actual and intended functionality. Triggers when users request to document, audit, or understand legacy/undocumented code before making changes.
/plugin marketplace add ViktorDolezel/spec-driven-dev/plugin install viktordolezel-spec-driven-dev@ViktorDolezel/spec-driven-devThis skill inherits all available tools. When active, it can use any tool Claude has access to.
archaeology-checklist.mdcheckpoints.mdevaluations.mdgap-types.mdscripts/discover-entry-points.shscripts/validate-findings.pyRetrofit Progress:
- [ ] Discovery: survey codebase, map features
- [ ] Archaeology: trace behavior per feature
- [ ] Gaps: compare actual vs intended behavior
- [ ] Assumptions: surface hidden dependencies
- [ ] Specs: generate from findings
All outputs go in .retrofit/ directory.
Brownfield work is iterative. Use this decision tree after any phase:
After any phase:
├─ Found new entry points? → Update discovery.md, continue
├─ Archaeology reveals missed assumptions? → Add to assumptions.md
├─ Gap analysis shows incomplete findings? → Return to archaeology
├─ Need human decision? → STOP, ask user, wait for answer
└─ Phase complete and validated? → Proceed to next phase
IMPORTANT: Do not proceed to spec generation without explicit user confirmation of:
See: checkpoints.md - Human validation gates
Survey before diving deep. Create .retrofit/discovery.md:
Entry Points:
- [ ] API endpoints (grep: Route, MapGet, HttpPost)
- [ ] CLI commands (grep: Command, ArgParser)
- [ ] Background jobs (grep: Cron, Schedule, BackgroundService)
- [ ] Event handlers (grep: Subscribe, Handler, Consumer)
Feature Map:
| Feature | Entry Points | Core Files | Test Coverage |
|---------|--------------|------------|---------------|
| {name} | {endpoints} | {files} | {low/med/high}|
Priority: (security-critical, customer-facing, low-coverage first)
Trace what code actually does. Create .retrofit/features/{name}-findings.md:
Happy Path:
1. {entry point} receives {input}
2. {what happens step by step}
3. {what gets returned/stored}
Branches:
| Condition | Location | Behavior |
|-----------|----------|----------|
Business Rules Found:
- {rule}: {file:line} - explicit|implicit
Assumptions:
| Assumption | Location | Validated? | Risk |
|------------|----------|------------|------|
Compare actual vs intended. Create .retrofit/gaps.md:
| ID | Expected (from docs/tests) | Actual (from code) | Type |
|----|----------------------------|--------------------|------|
| G1 | {expected behavior} | {actual behavior} | bug|intentional|unclear |
Types:
Surface hidden dependencies. Create .retrofit/assumptions.md:
| Category | Assumption | Location | Validated? | Risk |
|----------|------------|----------|------------|------|
| data | email not null | User.cs:34 | no null check | high |
| env | server is UTC | Token.cs:12 | DateTime.Now | high |
| timing | API responds <1s | Client.cs:45 | no timeout | med |
| security | input trusted | Import.cs:23 | no sanitize | critical |
Create .retrofit/features/{name}-spec.md using findings:
# Spec: {Feature}
## Status
- Implementation: Exists (retrofitted)
- Spec Status: Draft
## Versions
| Version | Description | Status |
|---------|-------------|--------|
| v1 | Current behavior (from archaeology) | Documented |
| v2 | Target behavior (after gap fixes) | Pending approval |
## Acceptance Criteria
### AC-1: {description}
**v1 (Current)**:
Given {current precondition from archaeology}
When {action}
Then {current outcome}
**v2 (Target)** [Gap: G-{N}]:
Given {intended precondition}
When {action}
Then {intended outcome}
**Migration**: {what changes between v1 and v2}
## Known Issues
| Issue | Type | Gap | Action |
|-------|------|-----|--------|
| {description} | bug/drift/missing | G-{N} | fix code/update docs |
## Assumptions
{from assumptions phase - mark validated vs unvalidated}
When continuing from a previous session:
Check for drift:
git status # Any changes not in session log?
git diff .retrofit/ # Were findings modified?
Validate current state:
Re-orient:
Current phase: {from session log}
Completed: {features/phases done}
In progress: {current work}
Blocked on: {any blockers}
bash scripts/discover-entry-points.sh for consistent entry point discoverypython scripts/validate-findings.py <file> to validate file referencesThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.