codebase-teach
Original:🇺🇸 English
Translated
Analyzes project bounded contexts, extracts business rules and domain knowledge, writes ai-context/features/<context>.md files, and produces a teach-report.md with documentation coverage metrics. Trigger: /codebase-teach, teach codebase, extract domain knowledge, update feature docs.
4installs
Sourcefearovex/claude-config
Added on
NPX Install
npx skill4agent add fearovex/claude-config codebase-teachTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →codebase-teach
Analyzes bounded contexts from the project's source tree, extracts domain knowledge per context, writesfiles, and producesai-context/features/<context>.mdwith coverage metrics.teach-report.md
Triggers: , teach codebase, extract domain knowledge, update feature docs, analyze bounded contexts
/codebase-teachPurpose
codebase-teachai-context/features/memory-updatememory-initProcess
Step 0 — Load project context (non-blocking)
This step is non-blocking: any failure (missing file, unreadable file) MUST produce at most an INFO-level note. This step MUST NOT produce or .
status: blockedstatus: failed- Read — tech stack, versions, key tools.
ai-context/stack.md - Read — architectural decisions and rationale.
ai-context/architecture.md - Read — naming patterns, code conventions.
ai-context/conventions.md - Read the project's (at project root) and extract the
CLAUDE.mdsection.## Skills Registry
For each file:
- If absent: log
INFO: [filename] not found — proceeding without it. - If present: extract or
Last updated:date. If date is older than 30 days: logLast analyzed:NOTE: [filename] last updated [date] — context may be stale. Consider running /memory-update or /project-analyze.
Also read project config file ( at project root) if it exists, and extract if present:
config.yamlteach_max_files_per_context- If present:
max_files = teach_max_files_per_context - If absent: (default)
max_files = 10
Log: or
"File cap per context: [max_files] (source: config.yaml)""File cap per context: 10 (default)"Step 1 — Scan bounded contexts
Identify bounded context candidates by scanning the project directory tree at depth ≤ 2 under these root directories (in order):
- — subdirectories at depth 1 (e.g.,
src/,src/auth/)src/payments/ - — subdirectories at depth 1
app/ - — subdirectories at depth 1
features/ - — subdirectories at depth 1
domain/ - — existing feature file names (each file stem is treated as a context name)
ai-context/features/
Exclusion rules — skip directories named: , , , , , , , , , , ,
sharedutilscommonlibtypeshookscomponents__tests__testtestsnode_modules.gitCross-reference with existing feature files:
Read the directory (if it exists) and list all files, excluding files whose names begin with (e.g., ).
ai-context/features/.md__template.mdFor each detected context candidate, build a record:
{ slug: kebab-case of directory name, dir_path, existing_feature_file: bool }Slug convention: lowercase the directory name; replace spaces and underscores with hyphens. Example: → , → .
UserProfileuser-profileauth_serviceauth-serviceIf no context candidates are found:
- Log:
"No bounded context directories detected." - Write with a Summary noting "No bounded context directories detected" and a recommendation to run
teach-report.mdfirst./memory-init - Stop here.
If does not exist:
ai-context/features/- Log:
"INFO: ai-context/features/ not found — feature files will be created if possible." - Note in : "ai-context/features/ was absent at run time. Recommend running /memory-init to scaffold the directory before re-running /codebase-teach."
teach-report.md - Continue processing (the skill creates the directory and files as needed).
Output:
context_list = [{ slug, dir_path, existing_feature_file: bool }, ...]Log each context found:
"Detected context: [slug] — [dir_path] (feature file: [exists|absent])"Step 2 — Read key files per context (sequential)
Process contexts one at a time. For each context in :
context_list-
Enumerate implementation files in(recursive), filtering for file extensions:
dir_path,.ts,.tsx,.js,.jsx,.py,.java,.kt,.rb,.go,.ex,.exs,.cs,.rs,.php.swift- Prioritize files by recency (most recently modified first)
- Exclude files matching: ,
*.test.*,*.spec.*,test_*,*_test.*,*.d.ts*.min.*
-
Apply file cap: read at mostfiles. If total enumerated >
max_files, log:max_files"[slug]: [total] files found — sampling [max_files] (cap applied)" -
For each file to read:
- Attempt to read the file
- If the file is binary or unreadable: skip it; record in with reason
skipped_files - If readable: extract the following signals:
- Business rules: explicit conditional constraints (if/when/unless logic that enforces domain rules)
- Invariants: assertions or validation guards that are always enforced
- Data model entities: class/struct/interface/type names with their key fields
- Integration points: imports of external services, APIs, or infrastructure adapters
-
Accumulate:
context_knowledge = { slug, rules[], invariants[], entities[], integrations[], files_read[], skipped[] }
Step 3 — Write ai-context/features/<slug>.md
ai-context/features/<slug>.mdFor each context processed in Step 2:
If does not exist (or is absent):
ai-context/features/<slug>.mdai-context/features/- Create the directory if needed
- Write a new file using the six-section structure below
- All AI-generated sections receive markers
[auto-updated]
If already exists:
ai-context/features/<slug>.md- Read the entire file
- Identify ...
<!-- [auto-updated]: codebase-teach ... -->blocks<!-- [/auto-updated] --> - Overwrite content only inside blocks
[auto-updated] - Preserve byte-for-byte all content outside any block
[auto-updated] - If no block exists for a section, append the section at the end of the file inside a new
[auto-updated]block[auto-updated]
Six-section feature file structure:
markdown
# [Context Name] — Domain Knowledge
Last updated by: codebase-teach
Last run: YYYY-MM-DD
---
## Domain Overview
<!-- [auto-updated]: codebase-teach — last run: YYYY-MM-DD -->
[AI-extracted 2–4 sentence summary of what this bounded context does and its primary responsibilities]
<!-- [/auto-updated] -->
---
## Business Rules and Invariants
<!-- [auto-updated]: codebase-teach — last run: YYYY-MM-DD -->
[AI-extracted explicit conditional constraints and always-true invariants from the source]
- Rule: [description]
- Invariant: [description]
<!-- [/auto-updated] -->
---
## Data Model Summary
<!-- [auto-updated]: codebase-teach — last run: YYYY-MM-DD -->
Key entities detected:
| Entity | Key Fields |
|--------|-----------|
| [Name] | [field1, field2, ...] |
<!-- [/auto-updated] -->
---
## Integration Points
<!-- [auto-updated]: codebase-teach — last run: YYYY-MM-DD -->
External dependencies and integration touchpoints:
- [service/API name]: [what it is used for]
<!-- [/auto-updated] -->
---
## Decision Log
<!-- [auto-updated]: codebase-teach — last run: YYYY-MM-DD -->
<!-- Append new AI-detected decisions below. Human entries above this marker are preserved. -->
<!-- [/auto-updated] -->
---
## Known Gotchas
<!-- [auto-updated]: codebase-teach — last run: YYYY-MM-DD -->
<!-- Append new AI-detected gotchas below. Human entries above this marker are preserved. -->
<!-- [/auto-updated] -->_template.md_Step 4 — Evaluate coverage and write teach-report.md
teach-report.mdCoverage calculation:
documented_contexts = count of contexts that have an ai-context/features/<slug>.md file after Step 3
total_contexts = count of contexts in context_list
coverage_pct = (documented_contexts / total_contexts) * 100 (0 if total_contexts == 0)
gap_list = contexts in context_list where existing_feature_file was false before Step 3
AND no file was created in Step 3Write in the project working directory root (same level as ). Overwrite if it exists.
teach-report.mdanalysis-report.mdmarkdown
# Teach Report — [Project Name]
Last run: YYYY-MM-DD
Skill: codebase-teach
## Summary
Contexts detected: [total_contexts]
Contexts documented: [documented_contexts]
Coverage: [coverage_pct]%
## Coverage
[coverage_pct]% — [documented_contexts] of [total_contexts] contexts documented.
## Gaps
Contexts detected in code but not documented in ai-context/features/:
- [context-slug] — [dir_path]
[If no gaps: "None — all detected contexts are documented."]
## Files Read
### [context-slug]
- [file path] — sampled
- [file path] — sampled
- [file path] — SKIPPED: [reason]
[Repeat for each context]
## Sections Written / Updated
- ai-context/features/[context].md — [created|updated] — sections: [list of sections written]If was absent at run time, append to the Summary section:
ai-context/features/Note: ai-context/features/ was absent at run time. Recommend running /memory-init to scaffold the directory before re-running /codebase-teach.
Rules
- MUST NOT modify ,
ai-context/stack.md,ai-context/architecture.md,ai-context/conventions.md, orai-context/known-issues.mdai-context/changelog-ai.md - MUST NOT modify any file under
docs/ - MUST NOT be invoked automatically by any other skill — user-initiated only
- MUST skip any file or directory whose name begins with in
_ai-context/features/ - MUST preserve all human-authored content outside markers when updating existing feature files
[auto-updated] - MUST process contexts sequentially — never in parallel
- MUST apply the cap (default 10) to every context
teach_max_files_per_context - MUST list skipped files in under the "Files Read" section for the relevant context
teach-report.md - MUST complete without error even when no bounded context directories are detected
- MUST write on every successful run
teach-report.md - marker format:
[auto-updated]...<!-- [auto-updated]: codebase-teach — last run: YYYY-MM-DD -->— consistent with<!-- [/auto-updated] -->conventionproject-analyze
Output
teach-report.md
(mandatory — written to project root on every run)
teach-report.mdRequired sections:
| Section | Content |
|---|---|
| Summary | Contexts detected, documented, coverage % |
| Coverage | Percentage and ratio |
| Gaps | Contexts found in code but undocumented (or "None") |
| Files Read | Per-context list of files sampled and skipped |
| Sections Written / Updated | Per-feature-file: created or updated, which sections |
ai-context/features/<context>.md
(one per bounded context)
ai-context/features/<context>.mdWritten or updated during Step 3. Six sections with markers on all AI-generated content.
[auto-updated]