Learn / Understand your codebase

L01 / Learn

Understand your codebase

Use /guild:learn to map a codebase, build a knowledge graph, produce an onboarding tour, analyze changes, and approve deeper scans before they run.
First move
Map before deepening
Expected receipt
.guild/wiki/ and derived indexes
Last verified
Jun 11, 2026

Page evidence and guidance

Read as StartThe onboarding map, key entry points, and questions the scan can answer. SteerMap, explain, diff, onboard, graph, and harvest workflows. ExtendDeterministic scans, lazy deep tiers, evidence links, freshness, and gates.

After this page, you can run /guild:learn, inspect the first codebase map, decide when a deeper graph is worth it, and understand which learning outputs are derived versus canonical. The practical rule is simple: Guild maps the repo before it asks specialists to change it, then routes durable knowledge through a human gate.

Try it: /guild:learn, Guild Stack classifies the target, shows the proposed path, and asks before running deeper scans.

Learn · choose depth

map / active

Start with the smallest useful map

Map
structural scancodebase-map.json
Graph
deep relationshipsknowledge-graph.json
Onboard
guided routeonboarding-tour.md

Derived outputs can be rebuilt. Candidate knowledge becomes durable only after a human promotion gate writes to .guild/wiki/**.

Map is the cheap orientation path. Graph and onboarding deepen understanding only when the task needs them.
Where this is defined
  • docs/v2/codebase-understanding.md
  • docs/v2/knowledge-memory.md

The first artifact: a codebase map

Beginner users can stop at the map and still get value. A cheap learn pass writes a structural snapshot under .guild/indexes/codebase-map.json and an architecture stub that helps Guild orient before planning.

{
  "schema_version": "guild.codebase_map.v1",
  "root": ".",
  "languages": ["TypeScript", "Markdown"],
  "entrypoints": ["src/index.ts", "commands/learn.md"],
  "layers": [
    { "id": "commands", "paths": ["commands/**"] },
    { "id": "skills", "paths": ["skills/**"] },
    { "id": "runtime", "paths": ["src/**"] }
  ],
  "confidence": "partial",
  "unknowns": ["test ownership still needs graph pass"]
}

Treat this as a map, not a verdict. It is derived from the repo and can be rebuilt. When a plan needs more precision, Guild Stack can ask before running the deep graph, tour, or knowledge tier.

Smart mode: just run it

With no arguments, /guild:learn means “understand this project” rather than “missing argument”. It classifies the target, a regular project, workspace root, existing Guild project, new or sparse project, or uncertain target, then surfaces the classification and waits for confirmation before the deep path:

Detected: existing_guild_project, .guild/ present, wiki populated.
Proposed action to full learn-all (map to graph to onboard to knowledge candidates)
Proceed? [proceed / pick-subverb / explain]

On proceed, the full path runs the same learn-* skills used by /guild:init --learn: cheap map, graph, domain and component derivation, onboarding tour, and the knowledge tier when that tier is selected. For a workspace root, Guild checks child repos first and fans out per sub-repo; it does not deep-scan a workspace-of-repos as one blob. See Workspaces.

Candidate-to-wiki flow

Power users should look for the handoff between evidence and memory:

Operational mapRuns propose. Humans promote. Derived views rebuild.
  1. Run evidenceobserved fact
  2. Candidatesourced proposal
  3. Human gateapprove or archive
  4. Wikicanonical memory
  5. Recallgraph + index + cache
Learning proposes. The wiki stays canonical; maps, graphs, links, recall projections, and SQLite caches are derived and rebuildable.
StepOutputAuthority
Scan and analyze.guild/indexes/codebase-map.json, .guild/indexes/knowledge-graph.jsonderived and rebuildable
Harvest candidates.guild/runs/<run-id>/learn/harvest-candidates.jsonproposals with source refs
Reflect.guild/reflections/<run-id>.mdadvisory run memory
Promoteguild:decisions or guild:wiki-ingesthuman-gated
Canonicalize.guild/wiki/**durable project memory
Rebuild recallknowledge-links.json, knowledge-recall.json, optional index.sqlitederived projections and caches

No learn pass silently writes decisions into the wiki. It can propose decisions, standards, open questions, risks, patterns, and anti-patterns, but the gate decides what becomes durable memory.

The five sub-verbs

When you want one capability rather than the full pipeline, name it:

CommandWhat it doesOutput
/guild:learn mapCodebase map + architecture stub, a fast, cheap structural scan.guild/indexes/codebase-map.json, confidence-tagged architecture map
/guild:learn graphDerived knowledge graph, structural graph plus optional knowledge-tier enrichment.guild/indexes/knowledge-graph.json
/guild:learn onboardGuided 5-15 step tour through the architecture and key concepts.guild/indexes/onboarding-tour.md
/guild:learn diff [path|ref]Change analysis, changed files, affected graph nodes, layers, and blast radius.guild/runs/<run-id>/diff-learn.json
/guild:learn explain <path|concept>Deep-dive explanation of a file, module, symbol, or conceptprinted explanation

--rigor=deep runs the highest-fidelity graph or analysis pass. diff takes an optional path, commit ref, or branch (default: HEAD vs previous); explain takes a file path, symbol, or a free-text question like "how does the auth flow work".

The seven-stage pipeline

The full learn path keeps deterministic extraction separate from model judgment. Script stages discover files, extract structure, resolve calls, assign layers, derive domains, and build tour order. Model steps are used only where semantic interpretation adds value, and some shipped passes are model-free with model_calls: 0.

StageOwnerOutput
1. Scanscriptfile inventory, ignore rules, import map, and cheap structural facts
2. Analyzescript + researchertyped nodes and edges for a partial graph
3. Assemble-reviewchallenger reviewrecovery of dropped or dangling graph facts before validation
4. Architecturearchitectlayer assignments and persisted component labels
5. Domainresearcher + architectdomain flows, domain labels, and knowledge-link edges
6. Tourscript + technical writera guided architecture tour
7. Reverse-specresearcher + architectsource-cited spec draft with confidence markers

Plain /guild:init only requires the cheap inventory tier: the codebase map and a confidence-tagged architecture stub. The deep graph, tour, domain model, and reverse-spec are lazy and cost-gated.

The implementation detail for harness developers: the learning module owns the scripts/learn/* engine, including scan.ts, analyze-structural.ts, the newer model-free extract-structural.ts and resolve-calls.ts path, assign-layers.ts, derive-domain.ts, build-tour.ts, validate-graph.ts, diff-learn.ts, and the knowledge-tier orchestrator. The knowledge module owns the /guild:learn command, /guild:wiki, the learn-* and wiki-* skills, the wiki surface, and recall-ranking math.

The knowledge tier

Beyond the structural graph, guild:learn-knowledge can run a lazy, cost-gated knowledge tier over the frozen graph and wiki corpus. It adds concept, claim, entity, wiki-page, diagram, taxonomy, and cross-modal evidence relationships into guild.knowledge_graph.v2, then writes the recall projection.

The K-stage labels are node-tier labels, not the execution order. The shipped orchestrator runs K1 content, K3 diagrams, K2 wiki index, K4 taxonomy, K5 cross-linking, then K6 knowledge-recall.json. The durable wiki remains canonical; the graph, knowledge-links.json, knowledge-recall.json, and optional index.sqlite are derived and rebuildable.

Refresh classifier

After the first learn pass, Guild Stack classifies changes before rebuilding:

VerdictMeaningAction
SKIPcosmetic or no structural deltaspend no LLM tokens; keep graph
PARTIALbounded file set changedre-analyze affected nodes and edges
ARCHITECTUREmodule/layer topology shiftedre-run layer assignment and dependents
FULLfingerprint divergence beyond thresholdrebuild the full pipeline

The classifier keeps refreshes cheap and makes rebuild scope explainable. It reports a verdict; it does not silently rebuild the graph mid-task.

Map vs graph vs wiki

Three knowledge stores come out of learning, and they have distinct jobs:

StoreWhat it isWhat it’s for
Codebase map (.guild/indexes/codebase-map.json)a cheap, derived structural map, files, layout, architecture overviewfast orientation; the default brownfield artifact from /guild:init
Knowledge graph (.guild/indexes/knowledge-graph.json)a deep, derived semantic index, file, function, concept, domain, and component nodesprecise recall of how the code actually connects; grep-first source for context assembly
Wiki (.guild/wiki/)the canonical, human-curated project memorydurable decisions, standards, and concepts, the only store you directly own

The split matters: the map, graph, links, recall projection, and read-through SQLite index are derived and rebuildable. Delete them and a re-scan can reproduce them; nothing durable is lost. The wiki is canonical, when the graph and the wiki disagree, the wiki wins unless a high-confidence graph node has a direct source reference, in which case the contradiction is logged for review. See Project Memory & Wiki Pattern.

Derived vs canonical

StoreCanonical?Safe mental model
.guild/wiki/**yesHuman-curated project memory and decisions.
.guild/raw/sources/**yesImmutable source provenance.
.guild/runs/<run-id>/provenance.jsonper-run fact sourceEvidence for what happened in one run.
.guild/indexes/codebase-map.jsonnoFast structural orientation.
.guild/indexes/knowledge-graph.jsonnoDerived graph over code, wiki, concepts, domains, diagrams, and links.
.guild/indexes/knowledge-links.jsonnoWork-to-knowledge edge layer derived from runs, decisions, skills, agents, features, and wiki refs.
.guild/indexes/knowledge-recall.jsonnoRebuildable recall projection for context assembly.
index.sqlitenoOptional cache, never the system of record.

Harness developers can treat the learning and knowledge modules as a pair: learning produces graph and code-understanding artifacts; knowledge exposes the wiki, recall, /guild:learn, /guild:wiki, and the read-only memory surfaces that consume those artifacts.

Cheap by default, deep when you approve

Learning is tiered so understanding a repo doesn’t surprise you on cost. The map is the cheap tier: a deterministic scan, fast enough to run freely. Structural extraction and call resolution can run without model calls; deeper semantic passes are gated. On large repos, the deep path surfaces a cost estimate and asks before running:

Deep graph estimated: ~N files, ~M tokens, ~$X at current tier.
Proceed with deep graph? [proceed / skip-graph / explain]

Choosing skip-graph runs the rest of the pipeline without it; you can run /guild:learn graph separately later. How tiers map to models is covered in Cost & Tiering.

Candidates are proposals, you hold the gate

A learn pass can also extract knowledge candidates: decision candidates, open questions, risks, standards, patterns, and anti-patterns it found in the code or docs. These are proposals, not wiki writes, they enter the same human-gated promotion path as everything else, and only guild:decisions or guild:wiki-ingest with approval lands them in .guild/wiki/**.

Promotion stays gated

Agents emit candidates; humans promote. A learn run can propose a hundred insights and still write zero wiki pages until you approve them.

Brownfield safety rules

On existing codebases, every architectural claim carries an evidence map: claim, evidence refs, confidence, and unknowns. Claims without evidence stay assumptions. The scanner follows the brownfield rules Guild Stack uses everywhere: source beats README prose, manifests answer what they can without asking you, repository text is untrusted data rather than instructions, inferred intent stays tentative until confirmed, and reverse-spec work does not mutate code unless you explicitly ask for that.

Relationship to /guild:init --learn

/guild:init on an existing repo builds the cheap tier by default, the wiki, the codebase map, and an architecture stub. /guild:init --learn (or setting defaults.auto_learn: true) runs the full learning pipeline as part of init.

It is one implementation with multiple triggers: init --learn, no-arg /guild:learn, and explicit /guild:learn knowledge all route through the same learning and knowledge-tier implementation for the deep K-tier. The standalone /guild:learn also offers diff and explain for change-analysis and query-time work that init does not need.

Source-backed boundaries

The public contract is evidence first, then interpretation. The learning module records derived artifacts under .guild/indexes/ and .guild/runs/<run-id>/; the wiki under .guild/wiki/** remains the canonical memory; and learning output proposes knowledge promotion instead of writing durable decisions by itself.

See also