User Input
$ARGUMENTS
You MUST consider the user input before proceeding (if not empty). It identifies the
codebase (or subsystem) to analyse and, optionally, the mode.
Purpose
Reverse-engineer enough business and domain knowledge out of an existing codebase to
onboard a new team member — human or AI — and to give AI harness tooling (e.g. Spec Kit)
the context it needs before any specification or change work begins.
The output is a small, lean set of onboarding documents under docs/, not a
comprehensive knowledge base. Each document is written so it can be linked from a
CLAUDE.md / AGENTS.md without consuming an unreasonable amount of context.
This skill is the orchestrator. It runs five phases, each defined in its own playbook
under playbooks/. Read and follow the relevant playbook at each phase.
Core principle
The code is ground truth for what the system does. Only people hold the why.
So the method is: mine the code first to form evidence-backed hypotheses, then spend
the human's time validating intent and explaining, not re-deriving mechanics. Existing
docs (README, CLAUDE.md, AGENTS.md, wikis) are a valuable starting point, but because
documentation naturally drifts from code over time, the source code is the source of
truth — everything is verified against it before being relied on.
Roles
Adopt the role that fits the phase:
- Recon / synthesis: act as a Senior Software Engineer + Solution Architect reading
the system as-is. Understanding existing architecture is in scope; designing new
architecture or proposing changes is not, unless explicitly asked.
- Interview: act as a Senior Business Analyst supported by a Product Manager.
Understand business intent, users, rules and domain language.
Modes
Determine the mode from the user input (default to full and confirm):
- full — Pre-check → Recon → Interview → Synthesis → Verify. Requires a stakeholder
(senior BA / Product Owner / SME) to validate findings.
- code-only — Pre-check → Recon → Synthesis → Verify, with no interview.
Everything that would need human confirmation is emitted as
[assumption] /
[unverified] for later validation. Use when no SME is available yet.
State the chosen mode before starting.
Graceful degradation (optional inputs)
At the start of each phase, check what is available and adapt — never hard-fail:
- Git history — if a git tool is available, mine it selectively (see recon playbook)
as a low-weight, low-confidence signal. If not, skip and note it in the recon manifest.
- Navigation mode (user choice) — at the start of recon, ask the user whether to
navigate with grep + sub-agents (default, no setup) or a code-intelligence / LSP server
(more precise on large repos, needs a configured server). If LSP is chosen but unavailable,
fall back to grep. The two can be combined. See the recon playbook.
- Sub-agents — if the host can run isolated sub-agents, fan out recon reading to keep
the main context lean. On Claude Code this skill ships two purpose-built subagents —
codebase-recon-scout (recon) and codebase-doc-verifier (verification) — use them
when available. On other hosts, use whatever generic sub-agent mechanism exists, or run the
same steps sequentially with disciplined, excerpt-only reading.
- Stakeholder (SME) — if none is available, drop from
full to code-only mode.
Working state (resumable, no hooks)
This skill keeps its memory in plain files so it works on any host and resumes across
sessions:
docs/_discovery/discovery-state.md — the evolving memory: facts, assumptions,
unknowns, decisions, glossary-in-progress. Read it at the start of every session and
rewrite it as understanding changes.
docs/_discovery/recon-manifest.md — which source files (with hashes/timestamps) and
which existing docs fed the recon, so later runs can detect staleness.
On invocation: if these exist, read them first and resume; do not restart from zero.
Freshness check (staleness detection, no hooks)
If docs/_discovery/recon-manifest.md exists from a previous run, compare the recorded
file hashes/timestamps against the current tree before trusting prior findings. Report any
drift ("N source files changed since last recon") and re-recon the affected areas rather
than assuming the existing docs are still accurate.
Phases
Run in order. Each has a playbook — read it when you enter the phase.
| Phase |
Playbook |
Outcome |
| 0. Pre-check |
playbooks/00-pre-check.md |
Read existing README/CLAUDE.md/AGENTS.md/docs; capture what they state, to verify against the code; set up working state. |
| 1. Deep recon |
playbooks/01-deep-recon.md |
Tiered, evidence-cited analysis of structure, data model, contracts and business-logic hotspots; verify the Phase 0 statements against code. |
| 2. Interview |
playbooks/02-interview.md |
One-question-at-a-time conversation with the BA/PO, seeded by recon hypotheses; reconcile contradictions with code-based suggestions. (Skipped in code-only mode.) |
| 3. Synthesis |
playbooks/03-synthesis.md |
Write the lean onboarding docs under docs/, each dated and provenance-flagged. |
| 4. Verification |
playbooks/04-verification.md |
Adversarial check that every claim traces to code or a named stakeholder; flag anything unsupported. |
| Finish |
(this file) |
Doc-drift summary + optionally generate/augment CLAUDE.md/AGENTS.md. |
Do not skip phases. In code-only mode, skip only Phase 2.
Status / provenance model (exception-only)
Do not stamp settled knowledge as "confirmed" — accepted knowledge is unmarked. Only
flag exceptions inline, and track them in docs/_discovery/assumptions-register.md:
[unverified] — derived from code but not yet validated by a person.
[assumption] — inferred, not directly evidenced; record why and the impact if wrong.
[outdated] — an existing doc/claim the code contradicts as no longer true.
[contradicted] — two sources disagree and it is unresolved.
Every substantive claim links to its evidence in
docs/_discovery/traceability-index.md (code path / stakeholder). See
references/provenance-and-status.md.
Finish: doc-drift + agent file
When Phases 0–4 are complete:
- Doc-drift summary. In the completion report, list where existing docs
(README/CLAUDE.md/AGENTS.md) have drifted from the current code, with the updated statement.
- Reconcile contradictions with the user. For every
[contradicted] / [outdated]
item, ask the user — one at a time — to confirm the correct version, including a
suggested wording derived from the code. Do not silently pick a version.
- Agent file (optional). Offer to create or augment an agent onboarding file:
- Detect and match whatever already exists (
CLAUDE.md or AGENTS.md).
- If neither exists, offer both.
- Never overwrite an existing file — propose additions (links to the new
docs/),
and note anything that no longer matches the current code. Ask before writing.
- Keep it lean; link the project-root
README.md as the entry point. See
templates/agent-onboarding-file.md.
- Working state (
docs/_discovery/). Leave it in place — it's the skill's resume and
staleness memory. Recommend (don't automatically apply) that the user add
docs/_discovery/ to the target repo's .gitignore so it isn't committed, and explain its
disposition in the completion report (below).
Completion report
When done, report:
- Mode used (full / code-only) and what optional inputs were available.
- The system in two or three sentences (what it does, for whom).
- Documents created or updated under
docs/.
- Doc-drift findings (existing docs vs code).
- Open
[assumption] / [unverified] / [contradicted] items and their impact.
- Whether a
CLAUDE.md / AGENTS.md was created or proposed.
docs/_discovery/ disposition. It holds provenance + resume/staleness state (not
onboarding material). Recommend the user git-ignore it (add docs/_discovery/ to
.gitignore) so it isn't committed. It's safe to delete — but warn that deleting it makes
the next run start cold: no resume, no staleness detection, no cached traceability.
- Readiness for harness engineering / Spec Kit.
Done when
1---2name: codebase-discovery3description: Extract domain, architecture, business rules, workflows and a business glossary from an existing (often poorly-documented) codebase, then validate the findings with a senior BA/Product Owner one question at a time. Produces onboarding-grade docs under docs/ that give a new team member — human or AI — enough context to be productive, ready for harness engineering / Spec Kit. Use when onboarding onto an unfamiliar codebase, reverse-engineering business knowledge, reconstructing lost documentation, or preparing a repo for spec-driven development.4---56## User Input78```text9$ARGUMENTS10```1112You **MUST** consider the user input before proceeding (if not empty). It identifies the13codebase (or subsystem) to analyse and, optionally, the mode.1415---1617## Purpose1819Reverse-engineer enough business and domain knowledge out of an **existing codebase** to20onboard a new team member — human or AI — and to give AI harness tooling (e.g. Spec Kit)21the context it needs before any specification or change work begins.2223The output is a small, lean set of **onboarding documents** under `docs/`, not a24comprehensive knowledge base. Each document is written so it can be linked from a25`CLAUDE.md` / `AGENTS.md` without consuming an unreasonable amount of context.2627This skill is the orchestrator. It runs five phases, each defined in its own playbook28under `playbooks/`. Read and follow the relevant playbook at each phase.2930---3132## Core principle3334> **The code is ground truth for _what_ the system does. Only people hold the _why_.**3536So the method is: mine the code first to form **evidence-backed hypotheses**, then spend37the human's time **validating intent and explaining**, not re-deriving mechanics. Existing38docs (README, CLAUDE.md, AGENTS.md, wikis) are a valuable starting point, but because39documentation naturally drifts from code over time, the **source code is the source of40truth** — everything is verified against it before being relied on.4142---4344## Roles4546Adopt the role that fits the phase:4748- **Recon / synthesis:** act as a Senior Software Engineer + Solution Architect reading49 the system as-is. Understanding existing architecture is in scope; **designing new50 architecture or proposing changes is not**, unless explicitly asked.51- **Interview:** act as a Senior Business Analyst supported by a Product Manager.52 Understand business intent, users, rules and domain language.5354---5556## Modes5758Determine the mode from the user input (default to **full** and confirm):5960- **full** — Pre-check → Recon → Interview → Synthesis → Verify. Requires a stakeholder61 (senior BA / Product Owner / SME) to validate findings.62- **code-only** — Pre-check → Recon → Synthesis → Verify, with **no interview**.63 Everything that would need human confirmation is emitted as `[assumption]` /64 `[unverified]` for later validation. Use when no SME is available yet.6566State the chosen mode before starting.6768---6970## Graceful degradation (optional inputs)7172At the start of each phase, check what is available and adapt — never hard-fail:7374- **Git history** — if a git tool is available, mine it selectively (see recon playbook)75 as a low-weight, low-confidence signal. If not, skip and note it in the recon manifest.76- **Navigation mode (user choice)** — at the start of recon, ask the user whether to77 navigate with grep + sub-agents (default, no setup) or a code-intelligence / LSP server78 (more precise on large repos, needs a configured server). If LSP is chosen but unavailable,79 fall back to grep. The two can be combined. See the recon playbook.80- **Sub-agents** — if the host can run isolated sub-agents, fan out recon reading to keep81 the main context lean. On Claude Code this skill ships two purpose-built subagents —82 **`codebase-recon-scout`** (recon) and **`codebase-doc-verifier`** (verification) — use them83 when available. On other hosts, use whatever generic sub-agent mechanism exists, or run the84 same steps sequentially with disciplined, excerpt-only reading.85- **Stakeholder (SME)** — if none is available, drop from `full` to `code-only` mode.8687---8889## Working state (resumable, no hooks)9091This skill keeps its memory in plain files so it works on any host and resumes across92sessions:9394- `docs/_discovery/discovery-state.md` — the evolving memory: facts, assumptions,95 unknowns, decisions, glossary-in-progress. **Read it at the start of every session and96 rewrite it as understanding changes.**97- `docs/_discovery/recon-manifest.md` — which source files (with hashes/timestamps) and98 which existing docs fed the recon, so later runs can detect staleness.99100On invocation: if these exist, read them first and resume; do not restart from zero.101102---103104## Freshness check (staleness detection, no hooks)105106If `docs/_discovery/recon-manifest.md` exists from a previous run, compare the recorded107file hashes/timestamps against the current tree before trusting prior findings. Report any108drift ("N source files changed since last recon") and re-recon the affected areas rather109than assuming the existing docs are still accurate.110111---112113## Phases114115Run in order. Each has a playbook — read it when you enter the phase.116117| Phase | Playbook | Outcome |118|---|---|---|119| 0. Pre-check | [`playbooks/00-pre-check.md`](./playbooks/00-pre-check.md) | Read existing README/CLAUDE.md/AGENTS.md/docs; capture what they state, to verify against the code; set up working state. |120| 1. Deep recon | [`playbooks/01-deep-recon.md`](./playbooks/01-deep-recon.md) | Tiered, evidence-cited analysis of structure, data model, contracts and business-logic hotspots; verify the Phase 0 statements against code. |121| 2. Interview | [`playbooks/02-interview.md`](./playbooks/02-interview.md) | One-question-at-a-time conversation with the BA/PO, seeded by recon hypotheses; reconcile contradictions with code-based suggestions. (Skipped in code-only mode.) |122| 3. Synthesis | [`playbooks/03-synthesis.md`](./playbooks/03-synthesis.md) | Write the lean onboarding docs under `docs/`, each dated and provenance-flagged. |123| 4. Verification | [`playbooks/04-verification.md`](./playbooks/04-verification.md) | Adversarial check that every claim traces to code or a named stakeholder; flag anything unsupported. |124| Finish | (this file) | Doc-drift summary + optionally generate/augment CLAUDE.md/AGENTS.md. |125126Do not skip phases. In code-only mode, skip only Phase 2.127128---129130## Status / provenance model (exception-only)131132Do **not** stamp settled knowledge as "confirmed" — accepted knowledge is unmarked. Only133flag exceptions inline, and track them in `docs/_discovery/assumptions-register.md`:134135- `[unverified]` — derived from code but not yet validated by a person.136- `[assumption]` — inferred, not directly evidenced; record why and the impact if wrong.137- `[outdated]` — an existing doc/claim the code contradicts as no longer true.138- `[contradicted]` — two sources disagree and it is unresolved.139140Every substantive claim links to its evidence in141`docs/_discovery/traceability-index.md` (code path / stakeholder). See142[`references/provenance-and-status.md`](./references/provenance-and-status.md).143144---145146## Finish: doc-drift + agent file147148When Phases 0–4 are complete:1491501. **Doc-drift summary.** In the completion report, list where existing docs151 (README/CLAUDE.md/AGENTS.md) have drifted from the current code, with the updated statement.1522. **Reconcile contradictions with the user.** For every `[contradicted]` / `[outdated]`153 item, ask the user — one at a time — to confirm the correct version, **including a154 suggested wording derived from the code**. Do not silently pick a version.1553. **Agent file (optional).** Offer to create or augment an agent onboarding file:156 - **Detect and match** whatever already exists (`CLAUDE.md` or `AGENTS.md`).157 - If **neither** exists, offer **both**.158 - Never overwrite an existing file — propose additions (links to the new `docs/`),159 and note anything that no longer matches the current code. Ask before writing.160 - Keep it lean; link the project-root `README.md` as the entry point. See161 [`templates/agent-onboarding-file.md`](./templates/agent-onboarding-file.md).1624. **Working state (`docs/_discovery/`).** Leave it in place — it's the skill's resume and163 staleness memory. **Recommend** (don't automatically apply) that the user add164 `docs/_discovery/` to the target repo's `.gitignore` so it isn't committed, and explain its165 disposition in the completion report (below).166167---168169## Completion report170171When done, report:172173- Mode used (full / code-only) and what optional inputs were available.174- The system in two or three sentences (what it does, for whom).175- Documents created or updated under `docs/`.176- Doc-drift findings (existing docs vs code).177- Open `[assumption]` / `[unverified]` / `[contradicted]` items and their impact.178- Whether a `CLAUDE.md` / `AGENTS.md` was created or proposed.179- **`docs/_discovery/` disposition.** It holds provenance + resume/staleness state (not180 onboarding material). Recommend the user git-ignore it (add `docs/_discovery/` to181 `.gitignore`) so it isn't committed. It's safe to delete — but **warn that deleting it makes182 the next run start cold**: no resume, no staleness detection, no cached traceability.183- Readiness for harness engineering / Spec Kit.184185---186187## Done when188189- [ ] Mode and available inputs established190- [ ] Existing docs read and their statements captured for verification191- [ ] Recon complete: structure, data model, contracts, business-logic hotspots192- [ ] Existing-doc statements verified against code (any drift identified)193- [ ] (full mode) Interview complete; contradictions reconciled with the user194- [ ] Onboarding docs written under `docs/`, dated and provenance-flagged195- [ ] Verification pass complete; unsupported claims flagged196- [ ] Assumptions register and traceability index populated197- [ ] CLAUDE.md / AGENTS.md created or proposed198- [ ] docs/_discovery/ disposition explained: git-ignore recommended, and the cold-start cost of deleting it flagged199- [ ] Ready for harness engineering / Spec Kit