DeepFork — don't fork the code, fork the design
You are running a five-phase reverse-engineering pipeline. The product of each phase is a file the user keeps. Never skip Phase 0.
All outputs go to deepfork-out/<target-name>/ in the current working directory.
Phase 0 — License gate (non-negotiable)
Before cloning anything:
- Check the target's license (
gh api repos/<owner>/<repo> --jq .license.spdx_id or the LICENSE file).
- Proceed only for OSI-approved licenses (MIT, Apache-2.0, BSD, GPL/AGPL/LGPL, MPL, etc.). No license = all-rights-reserved = stop and tell the user (you may still produce the understanding report from public code, but no rebuild).
- State the rules of engagement in one line to the user:
- The blueprint describes behavior and architecture, never copies code.
- The rebuild is clean-room: written from the blueprint, not from the source.
- Copyleft targets (GPL/AGPL): warn that a rebuild closely derived from the design may carry obligations; recommend the rebuild also be open source.
- The final repo gets an
ATTRIBUTION.md crediting the original.
- Record license + rules in
deepfork-out/<target>/LICENSE-GATE.md.
Phase 1 — Acquire
git clone --depth 1 <target-url> deepfork-out/<target>/source
Note stars/age/activity in one line (context for how battle-tested the design is).
Phase 2 — Comprehend (the graph pass)
With graphify (preferred — check command -v graphify; if missing, offer: uv tool install graphifyy, or proceed to the fallback):
cd deepfork-out/<target>/source
graphify . # code-only is free & local (tree-sitter AST)
# add --backend claude-cli if the repo's docs/images matter to understanding
graphify cluster-only . # names communities, writes GRAPH_REPORT.md
graphify . --wiki # agent-crawlable wiki: index + one page per subsystem
Fallback (no graphify): build the map by hand — entry points (bin/main/exports), dependency manifest, directory tree with per-dir one-liners, and a call-graph sketch of the top 5 most-imported modules.
Then write UNDERSTANDING.md — the "most clean way to understand this repo":
- One-paragraph thesis — what this repo actually is, mechanically.
- The load-bearing pieces (graphify's god nodes): the 3-7 functions/classes everything routes through. For each: what it does, why everything depends on it.
- Subsystems (the communities): one section each — purpose, key files, how it talks to the others.
- The data flow: trace ONE representative request/call end to end, file by file.
- Surprising connections: the non-obvious couplings (graphify's analysis pass surfaces these) — these are where rebuilds go wrong.
- Honesty labels: mark each claim
[VERIFIED] (you read the code) or [INFERRED] (from the graph/structure). Verify every load-bearing claim by reading the actual code before labeling it VERIFIED.
Phase 3 — Interrogate
Answer the questions a rebuilder must know, using graphify query / path / explain (or direct reading):
- What is the core algorithm/trick, in plain words? (the thing you'd lose if you rebuilt naively)
- What do the public interfaces promise? (CLI surface, API contracts, file formats)
- Which dependencies are load-bearing vs incidental?
- What does it do at the edges — errors, concurrency, persistence?
- What would break first at 10× scale or hostile input?
Append answers to UNDERSTANDING.md § "Interrogation". Read the real code for anything still [INFERRED] that the rebuild depends on.
Phase 4 — Blueprint
Ask the user the customization question before writing (this is the whole point — their version, not a clone):
"What do you want YOUR version to do differently? (different language/stack, smaller scope, new capability, different storage, simpler/embedded, …)"
Then write BLUEPRINT.md — a spec someone could build from WITHOUT ever seeing the original source:
- Mission — what the new tool does, for whom, in 2 sentences.
- Architecture — components, responsibilities, boundaries (informed by the original's communities, improved where the surprising-connections pass showed accidental coupling).
- Core mechanisms — each described behaviorally (inputs → transformation → outputs, invariants, edge rules). Pseudocode allowed; copied code forbidden.
- Contracts — CLI/API surface, file formats, config schema.
- The user's customizations — explicit deltas from the original's design, each with rationale.
- Build order — milestones, each independently testable; test strategy per mechanism.
- Dependency decisions — what to take, what to write, what to drop (with the original's choices as evidence).
Phase 5 — Rebuild (clean-room)
- Scaffold a fresh repo (new directory, user's name, their license choice).
- Close the original source. Build from
BLUEPRINT.md only. If you must check behavior, run the original as a black box (inputs/outputs) — do not read its code during implementation.
- Build milestone by milestone, tests first for the core mechanisms.
- Ship with
ATTRIBUTION.md: "Design informed by reverse-engineering (). Implementation is original, built clean-room from a behavioral blueprint."
- Final check: diff-of-spirit — does YOUR version do the user's deltas, not just clone the original?
Guardrails
- Phase 0 always runs. Private/leaked/unlicensed code: understanding-report only, never a rebuild.
- Never paste original source into the rebuild. Behavioral description is the only thing that crosses the wall.
- If the target is enormous (>5k files), deepfork ONE subsystem the user picks from the community list.
- Keep
deepfork-out/ out of the rebuilt repo.
1---2name: deepfork3description: Reverse-engineer any open-source repo into a clean, queryable understanding and a rebuildable blueprint — then build your own customized version from the blueprint. Use when the user wants to understand how a repo works, learn its architecture, or rebuild a tool with their own changes ("how does X work", "rebuild X but with Y", "reverse engineer X", "deepfork X").4---56# DeepFork — don't fork the code, fork the design78You are running a five-phase reverse-engineering pipeline. The product of each phase is a file the user keeps. Never skip Phase 0.910All outputs go to `deepfork-out/<target-name>/` in the current working directory.1112## Phase 0 — License gate (non-negotiable)1314Before cloning anything:15161. Check the target's license (`gh api repos/<owner>/<repo> --jq .license.spdx_id` or the LICENSE file).172. **Proceed only for OSI-approved licenses** (MIT, Apache-2.0, BSD, GPL/AGPL/LGPL, MPL, etc.). No license = all-rights-reserved = **stop and tell the user** (you may still produce the *understanding* report from public code, but no rebuild).183. State the rules of engagement in one line to the user:19 - The blueprint describes **behavior and architecture**, never copies code.20 - The rebuild is **clean-room**: written from the blueprint, not from the source.21 - Copyleft targets (GPL/AGPL): warn that a rebuild closely derived from the design may carry obligations; recommend the rebuild also be open source.22 - The final repo gets an `ATTRIBUTION.md` crediting the original.234. Record license + rules in `deepfork-out/<target>/LICENSE-GATE.md`.2425## Phase 1 — Acquire2627```bash28git clone --depth 1 <target-url> deepfork-out/<target>/source29```3031Note stars/age/activity in one line (context for how battle-tested the design is).3233## Phase 2 — Comprehend (the graph pass)3435**With graphify** (preferred — check `command -v graphify`; if missing, offer: `uv tool install graphifyy`, or proceed to the fallback):3637```bash38cd deepfork-out/<target>/source39graphify . # code-only is free & local (tree-sitter AST)40# add --backend claude-cli if the repo's docs/images matter to understanding41graphify cluster-only . # names communities, writes GRAPH_REPORT.md42graphify . --wiki # agent-crawlable wiki: index + one page per subsystem43```4445**Fallback (no graphify):** build the map by hand — entry points (bin/main/exports), dependency manifest, directory tree with per-dir one-liners, and a call-graph sketch of the top 5 most-imported modules.4647Then write **`UNDERSTANDING.md`** — the "most clean way to understand this repo":48491. **One-paragraph thesis** — what this repo actually is, mechanically.502. **The load-bearing pieces** (graphify's god nodes): the 3-7 functions/classes everything routes through. For each: what it does, why everything depends on it.513. **Subsystems** (the communities): one section each — purpose, key files, how it talks to the others.524. **The data flow**: trace ONE representative request/call end to end, file by file.535. **Surprising connections**: the non-obvious couplings (graphify's analysis pass surfaces these) — these are where rebuilds go wrong.546. **Honesty labels**: mark each claim `[VERIFIED]` (you read the code) or `[INFERRED]` (from the graph/structure). Verify every load-bearing claim by reading the actual code before labeling it VERIFIED.5556## Phase 3 — Interrogate5758Answer the questions a rebuilder must know, using `graphify query / path / explain` (or direct reading):5960- What is the core algorithm/trick, in plain words? (the thing you'd lose if you rebuilt naively)61- What do the public interfaces promise? (CLI surface, API contracts, file formats)62- Which dependencies are load-bearing vs incidental?63- What does it do at the edges — errors, concurrency, persistence?64- What would break first at 10× scale or hostile input?6566Append answers to `UNDERSTANDING.md` § "Interrogation". Read the real code for anything still `[INFERRED]` that the rebuild depends on.6768## Phase 4 — Blueprint6970**Ask the user the customization question before writing** (this is the whole point — their version, not a clone):7172> "What do you want YOUR version to do differently? (different language/stack, smaller scope, new capability, different storage, simpler/embedded, …)"7374Then write **`BLUEPRINT.md`** — a spec someone could build from WITHOUT ever seeing the original source:75761. **Mission** — what the new tool does, for whom, in 2 sentences.772. **Architecture** — components, responsibilities, boundaries (informed by the original's communities, *improved* where the surprising-connections pass showed accidental coupling).783. **Core mechanisms** — each described **behaviorally** (inputs → transformation → outputs, invariants, edge rules). Pseudocode allowed; copied code forbidden.794. **Contracts** — CLI/API surface, file formats, config schema.805. **The user's customizations** — explicit deltas from the original's design, each with rationale.816. **Build order** — milestones, each independently testable; test strategy per mechanism.827. **Dependency decisions** — what to take, what to write, what to drop (with the original's choices as evidence).8384## Phase 5 — Rebuild (clean-room)85861. Scaffold a fresh repo (new directory, user's name, their license choice).872. **Close the original source.** Build from `BLUEPRINT.md` only. If you must check behavior, run the original as a black box (inputs/outputs) — do not read its code during implementation.883. Build milestone by milestone, tests first for the core mechanisms.894. Ship with `ATTRIBUTION.md`: "Design informed by reverse-engineering <original> (<license>). Implementation is original, built clean-room from a behavioral blueprint."905. Final check: diff-of-spirit — does YOUR version do the user's deltas, not just clone the original?9192## Guardrails9394- Phase 0 always runs. Private/leaked/unlicensed code: understanding-report only, never a rebuild.95- Never paste original source into the rebuild. Behavioral description is the only thing that crosses the wall.96- If the target is enormous (>5k files), deepfork ONE subsystem the user picks from the community list.97- Keep `deepfork-out/` out of the rebuilt repo.