codedocs
Use this skill when generating AI-agent-friendly documentation for a git repo or directory, answering questions about a codebase from existing docs, or incrementally updating documentation after code changes. Triggers on codedocs:generate, codedocs:ask, codedocs:update, "document this codebase", "generate docs for this repo", "what does this project do", "update the docs after my changes", or any task requiring structured codebase documentation that serves AI agents, developers, and new team members.
engineering documentationcodebaseonboardingarchitectureai-agentcode-understandingWhat is codedocs?
Use this skill when generating AI-agent-friendly documentation for a git repo or directory, answering questions about a codebase from existing docs, or incrementally updating documentation after code changes. Triggers on codedocs:generate, codedocs:ask, codedocs:update, "document this codebase", "generate docs for this repo", "what does this project do", "update the docs after my changes", or any task requiring structured codebase documentation that serves AI agents, developers, and new team members.
codedocs
codedocs is a production-ready AI agent skill for claude-code, gemini-cli, openai-codex, and 1 more. Generating AI-agent-friendly documentation for a git repo or directory, answering questions about a codebase from existing docs, or incrementally updating documentation after code changes.
Quick Facts
| Field | Value |
|---|---|
| Category | engineering |
| Version | 0.2.0 |
| Platforms | claude-code, gemini-cli, openai-codex, mcp |
| License | MIT |
How to Install
- Make sure you have Node.js installed on your machine.
- Run the following command in your terminal:
npx skills add AbsolutelySkilled/AbsolutelySkilled --skill codedocs- The codedocs skill is now available in your AI coding agent (Claude Code, Gemini CLI, OpenAI Codex, etc.).
Overview
Codedocs generates structured, layered documentation for any git repository or code
directory - documentation designed to be consumed by AI agents first and human developers
second. Instead of flat READMEs that lose context, codedocs produces a docs/ tree with
an architecture overview, per-module deep dives, cross-cutting pattern files, and a
manifest that tracks what has been documented and when. Once docs exist, the skill answers
questions from the docs (not by re-reading source code), and supports incremental updates
via targeted scope or git-diff detection.
Tags
documentation codebase onboarding architecture ai-agent code-understanding
Platforms
- claude-code
- gemini-cli
- openai-codex
- mcp
Related Skills
Pair codedocs with these complementary skills:
Frequently Asked Questions
What is codedocs?
Use this skill when generating AI-agent-friendly documentation for a git repo or directory, answering questions about a codebase from existing docs, or incrementally updating documentation after code changes. Triggers on codedocs:generate, codedocs:ask, codedocs:update, "document this codebase", "generate docs for this repo", "what does this project do", "update the docs after my changes", or any task requiring structured codebase documentation that serves AI agents, developers, and new team members.
How do I install codedocs?
Run npx skills add AbsolutelySkilled/AbsolutelySkilled --skill codedocs in your terminal. The skill will be immediately available in your AI coding agent.
What AI agents support codedocs?
This skill works with claude-code, gemini-cli, openai-codex, mcp. Install it once and use it across any supported AI coding agent.
Maintainers
Generated from AbsolutelySkilled
SKILL.md
Codedocs
Codedocs generates structured, layered documentation for any git repository or code
directory - documentation designed to be consumed by AI agents first and human developers
second. Instead of flat READMEs that lose context, codedocs produces a docs/ tree with
an architecture overview, per-module deep dives, cross-cutting pattern files, and a
manifest that tracks what has been documented and when. Once docs exist, the skill answers
questions from the docs (not by re-reading source code), and supports incremental updates
via targeted scope or git-diff detection.
Activation Banner
At the very start of every codedocs invocation, before any other output, display this ASCII art banner:
██████╗ ██████╗ ██████╗ ███████╗██████╗ ██████╗ ██████╗███████╗
██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗██╔═══██╗██╔════╝██╔════╝
██║ ██║ ██║██║ ██║█████╗ ██║ ██║██║ ██║██║ ███████╗
██║ ██║ ██║██║ ██║██╔══╝ ██║ ██║██║ ██║██║ ╚════██║
╚██████╗╚██████╔╝██████╔╝███████╗██████╔╝╚██████╔╝╚██████╗███████║
╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚═════╝ ╚═════╝╚══════╝Follow the banner immediately with the active sub-command and target path, e.g.:
codedocs:generate · src/ → docs/
When to use this skill
Trigger this skill when the user:
- Wants to generate documentation for a codebase, repo, or directory
- Asks "what does this project do" or "explain this codebase"
- Needs onboarding docs for new team members joining a project
- Wants AI-agent-readable documentation for a repo
- Asks a question about a codebase that already has codedocs output
- Needs to update existing docs after code changes or a new feature
- Wants to document only a specific module or subdirectory
- Asks to refresh docs based on recent git commits or a diff
Do NOT trigger this skill for:
- Writing standalone technical documents (RFCs, ADRs, runbooks) - use
internal-docs - API reference docs for external consumers - use
technical-writing - README creation for open-source packaging - use
open-source-management
Key principles
Docs-first answers - Once codedocs output exists, always answer questions from the docs before falling back to source code. The docs are the cached, structured knowledge layer. Only read source code when docs are missing, stale, or insufficient for the specific question.
Language-agnostic detection - Detect the tech stack from manifest files (package.json, Cargo.toml, go.mod, requirements.txt, pyproject.toml, composer.json, pom.xml, build.gradle, Gemfile, mix.exs, etc.) and directory conventions. Never assume a specific language.
Modules map to code, patterns cut across - Module docs correspond to distinct code directories or bounded contexts (auth, api, database). Pattern docs capture cross-cutting concerns (error handling, testing strategy, logging conventions) that span multiple modules. This split prevents duplication and matches how developers think about code.
Manifest-driven incremental updates - The
.codedocs.jsonmanifest tracks every documented module, its source path, and the git SHA at documentation time. Updates use this manifest to know what changed, what to re-scan, and what to skip.Output is configurable, structure is not - The output directory (default
docs/) is configurable. The internal structure (OVERVIEW.md, INDEX.md, .codedocs.json, modules/, patterns/) is fixed. Consistency across repos means any agent or developer knows where to look.Coverage is a first-class metric - Documentation that covers 40% of a codebase is often worse than none - it gives a false sense of completeness. Always run coverage verification before presenting the plan. Target 70%+ for mid-size repos. Report coverage percentage in OVERVIEW.md and the manifest. See
references/coverage-strategy.mdfor targets.Go deep, not just wide - For large repos, top-level modules are just the starting point. Any module with 15+ source files must be analyzed for sub-modules. Scan recursively through the full directory tree - a huge repo should generate 30-80 doc files, not 8-12.
Core concepts
Output structure - Codedocs always produces the same directory tree. OVERVIEW.md is the
entry point covering architecture, tech stack, project structure tree, and module map.
GETTING_STARTED.md is the authoritative local development guide with every runnable command
in the repo. INDEX.md is the file-to-module lookup table. The modules/ directory contains one
markdown file per major code module (with optional sub-module directories for large modules).
The patterns/ directory contains cross-cutting concern docs. The .codedocs.json manifest
tracks metadata, coverage stats, and SHAs for incremental updates. See
references/output-structure.md for the full spec.
Four sub-commands - The skill exposes four operations: generate for full or scoped
documentation creation, ask for docs-first Q&A, update for incremental refresh, and
status for coverage reporting. Each has its own workflow and parameters. See the common
tasks below and the corresponding reference files for detailed workflows.
Sub-modules - When a module directory has 15+ source files with distinct internal groupings,
it is split into sub-modules. The parent module doc becomes an index; sub-module docs live at
modules/<parent>/<child>.md. This keeps docs focused and prevents any single file from
becoming an unreadably long catch-all.
Coverage verification - Before presenting the generation plan, codedocs computes what
percentage of source files are covered by the proposed module set. If below target, it
expands the scan to find additional modules. Coverage is tracked in the manifest and reported
in OVERVIEW.md. See references/coverage-strategy.md.
Discovery phase - Before writing any docs, the generate command runs a discovery phase: scan the directory tree, identify the tech stack from manifest files, map module boundaries from directory structure and import graphs, and detect cross-cutting patterns from shared utilities and conventions. This phase produces the plan that drives doc generation.
Staleness detection - The update command compares the current git SHA against the SHA
recorded in .codedocs.json for each module. Modules with changed files since last
documentation are flagged as stale. The --diff flag uses git diff to identify exactly
which files changed, enabling surgical updates to only the affected module docs.
Common tasks
1. Generate full codebase documentation
Command: codedocs:generate [path] [--output docs/]
Workflow:
- Discover - Scan the target path (default: repo root). Identify language/framework from manifest files. Map directory structure to candidate modules. Detect entry points (main files, index files, route definitions, CLI entry points).
- Plan - Present the user with a proposed doc plan: list of modules to document, patterns detected, estimated scope, and coverage percentage. Confirm before proceeding if the plan is large or ambiguous.
- Write OVERVIEW.md - Architecture summary, tech stack, annotated project structure tree, entry points, key concepts, and module map with one-line descriptions.
- Write GETTING_STARTED.md - Full local development guide: prerequisites, installation, environment setup, dev server, test commands, build commands, lint/format, database workflow, common dev tasks, and how to reproduce CI locally. Sourced from package.json scripts, Makefile targets, CI config, and any existing README setup sections.
- Write module docs - For each module: purpose, public API/exports, internal structure, dependencies (what it imports), dependents (what imports it), and key implementation notes.
- Write pattern docs - For each cross-cutting pattern: description, where it appears, conventions to follow, and examples from the codebase.
- Write manifest - Create
.codedocs.jsonwith module list, source paths, git SHA, generation timestamp, coverage stats, and config. Seereferences/output-structure.md.
See references/generate-workflow.md for the complete discovery heuristics, module
boundary detection logic, and OVERVIEW.md template.
2. Ask a question about the codebase
Command: codedocs:ask "<question>"
Workflow:
- Check for docs - Look for
.codedocs.jsonin the output directory. If missing, suggest runningcodedocs:generatefirst. - Route the question - Determine which doc file(s) are relevant. Architecture questions go to OVERVIEW.md. Module-specific questions go to the relevant module doc. Cross-cutting questions go to pattern docs.
- Read docs first - Load the relevant doc file(s) and attempt to answer from them.
- Fall back to source - If the docs don't contain enough detail, read the relevant
source files. Flag in the response: "Note: this answer required reading source code -
consider running
codedocs:updateto capture this in the docs." - Cite sources - Always cite which doc file or source file the answer came from.
See references/ask-workflow.md for the question routing logic and fallback strategy.
3. Update docs incrementally (targeted scope)
Command: codedocs:update --scope path/to/module
Workflow:
- Read manifest - Load
.codedocs.jsonto find the existing module mapping. - Re-scan the scoped path - Run the discovery phase only on the specified path.
- Diff against existing docs - Compare the new discovery against the current module doc. Identify new exports, removed functions, changed dependencies.
- Update the module doc - Rewrite only the sections that changed.
- Update OVERVIEW.md - If the module's one-line description or dependency graph changed, update the module map in OVERVIEW.md.
- Update manifest - Bump the git SHA and timestamp for the updated module.
4. Update docs from git diff
Command: codedocs:update --diff [base..head]
Workflow:
- Get changed files - Run
git diff --name-only base..head(default: last documented SHA from manifest to HEAD). - Map files to modules - Using the manifest's source path mappings, determine which documented modules contain changed files.
- Re-generate affected modules - For each affected module, re-run the module doc generation workflow.
- Detect new modules - If changed files are in directories not yet documented, flag them as new module candidates and prompt the user.
- Update manifest - Bump SHAs for all updated modules.
See references/update-workflow.md for the diff detection logic and new module handling.
5. Generate docs for a specific subdirectory
Command: codedocs:generate path/to/subdir [--output path/to/subdir/docs/]
Same workflow as full generation but scoped to a subdirectory. The output defaults to a
docs/ folder inside the specified path. Useful for monorepos where each package needs
its own documentation.
6. Check documentation coverage
Command: codedocs:status
Workflow:
- Read manifest - Load
.codedocs.json. If missing, suggest runningcodedocs:generate. - Compute coverage - Count total source files in the repo vs files covered by documented modules.
- Detect staleness - For each module, compare the manifest SHA against the latest git commit SHA on that module's source path.
- Find gaps - List directories in the repo not covered by any module doc.
- Report - Print a structured status report: coverage percentage, stale modules, gap directories, and recommendations.
See references/coverage-strategy.md for coverage targets, the status report format, and
strategies for improving coverage on large repos.
Anti-patterns / common mistakes
| Mistake | Why it's wrong | What to do instead |
|---|---|---|
| Re-reading source code when docs exist | Wastes context window and time; docs are the structured cache | Always check for .codedocs.json first; read docs before source |
| Documenting every file individually | Creates noise; most files are internal implementation details | Document at the module level; only call out key files within a module |
| Skipping the discovery/plan phase | Jumping straight to writing produces unstructured, incomplete docs | Always run discovery first; present the plan to the user for approval |
| Hardcoding language assumptions | Breaks on polyglot repos or unfamiliar stacks | Detect from manifest files; handle multiple languages in one repo |
| Ignoring the manifest on updates | Leads to full re-generation when only one module changed | Always read .codedocs.json to scope updates to changed modules only |
| Mixing module docs and pattern docs | Cross-cutting concerns documented in one module become invisible | Use the patterns/ directory for anything that spans 2+ modules |
| Writing docs without git SHA tracking | Makes incremental updates impossible; no way to know what's stale | Always populate the manifest with per-module git SHAs |
| Stopping at top-level directories | A huge repo generates only 8-12 files; most of the codebase is invisible | Run the full recursive census (Step 3), verify coverage, and scan deeper |
| One flat doc for a 50-file module | The doc is too long to be useful; every question returns the same giant file | Split modules with 15+ files into sub-modules (modules/<parent>/<child>.md) |
| Not checking coverage before presenting plan | Low-coverage plans look complete but leave most of the repo undocumented | Always run Step 6 (coverage verification) before showing the plan |
| Skipping INDEX.md | AI agents can't map a specific file to its module doc | Always generate INDEX.md as part of the output |
| Skipping GETTING_STARTED.md | Developers and agents can't run the project without hunting through package.json and README | Always generate GETTING_STARTED.md; source commands from scripts, Makefile, and CI config |
| Copying README verbatim into GETTING_STARTED.md | READMEs are often incomplete or outdated; the guide adds no value | Extract commands from README but expand with context, fill gaps, and verify against actual scripts |
Gotchas
Manifest SHA drift causes phantom staleness - If the repo has uncommitted changes when
codedocs:generateruns, the recorded git SHA doesn't match the working tree. Subsequentcodedocs:updateruns see all files as stale and attempt full re-generation. Run codedocs against a clean working tree or committed state where possible.Coverage counts source files, not lines - A large 2,000-line file and a small 50-line config file each count as one source file for coverage. A 70% coverage score can hide an undocumented core module if it happens to be split into many small files. Review the gap directory list in
codedocs:statusrather than trusting the percentage alone.Sub-module splitting creates orphaned parent docs - When a module with 15+ files is split into sub-modules, the parent
modules/<name>.mdshould become an index pointing to sub-modules. If you createmodules/api/routes.mdandmodules/api/middleware.mdbut leave the originalmodules/api.mdintact unchanged, agents get conflicting information from two sources about the same code.Polyglot repos confuse module boundary detection - A repo with both a Python backend and a TypeScript frontend may have overlapping directory names (
utils/,types/,config/) at different levels. The discovery phase can conflate these into one module. Explicitly verify module boundaries during the plan phase for monorepos or polyglot projects.GETTING_STARTED.md sourced only from README - READMEs are often incomplete or outdated. Commands listed in
package.jsonscripts,Makefiletargets, and CI config files frequently include critical developer workflows not mentioned in the README. Always cross-check all three sources when generating GETTING_STARTED.md.
References
For detailed workflows and schemas, read the relevant file from references/:
references/generate-workflow.md- Complete discovery heuristics, recursive census, multi-level module boundary detection, sub-module splitting, coverage verification, tech stack identification, and all output templates (OVERVIEW.md, module doc, pattern doc, INDEX.md). Load when running codedocs:generate.references/ask-workflow.md- Question routing logic, doc-first resolution strategy, source code fallback rules, and citation format. Load when running codedocs:ask.references/update-workflow.md- Diff detection logic, manifest-driven scoping, new module detection, and OVERVIEW.md sync rules. Load when running codedocs:update.references/output-structure.md- Complete.codedocs.jsonmanifest schema (v1.1 with coverage stats and sub-modules), directory layout spec including sub-module directories and INDEX.md, and file format guidelines. Load when creating or validating output.references/coverage-strategy.md- Coverage targets by repo size, the codedocs:status report format, prioritization framework for large repos, and coverage improvement strategies. Load when running codedocs:status or when coverage is below target.
Only load a references file if the current task requires deep detail on that topic.
References
ask-workflow.md
Ask Workflow
Complete reference for the codedocs:ask command - question routing, doc-first
resolution strategy, source code fallback, and citation format.
Pre-flight Check
Before answering any question:
- Look for
.codedocs.jsonin the expected output directory (default:docs/) - If missing, respond: "No codedocs found. Run
codedocs:generatefirst to create documentation, then ask your question again." - If found, read the manifest to understand what's documented and when it was last updated.
Question Routing
Route the user's question to the most relevant doc file(s):
Architecture / overview questions
Signals: "how does this project work", "what's the architecture", "tech stack", "what does this repo do", "system overview", "getting started"
Route to: OVERVIEW.md
Module-specific questions
Signals: mentions a specific directory, file, feature area, function name, class name, or module name that maps to an entry in the manifest's module list
Route to: modules/<module-name>.md
Disambiguation: If the question mentions something that could map to multiple modules, check the manifest's source path mappings. If still ambiguous, read the OVERVIEW.md module map to determine the best match. If truly ambiguous, read both module docs.
Cross-cutting / pattern questions
Signals: "how does error handling work", "testing strategy", "logging", "auth flow", "configuration", "database access patterns" - anything that spans modules
Route to: patterns/<pattern-name>.md
Dependency / relationship questions
Signals: "what depends on X", "what does X import", "how are modules connected", "dependency graph"
Route to: Start with OVERVIEW.md module map, then read relevant module
docs for their Dependencies and Dependents sections.
Broad / unclear questions
Signals: Vague questions like "explain the code" or "how does everything work together"
Route to: OVERVIEW.md first. If the user needs more depth, suggest
specific modules to drill into.
Doc-First Resolution Strategy
This is the core principle of codedocs:ask. Follow this resolution order strictly:
Level 1: Docs only (preferred)
Read the routed doc file(s). If the answer is fully contained in the docs:
- Answer the question
- Cite the doc file: "Source:
docs/modules/auth.md" - Done
Level 2: Docs + light inference
If the docs contain most of the answer but require minor inference (connecting two documented facts, applying a documented pattern to a specific case):
- Answer with the inference clearly stated
- Cite the doc files used
- Done
Level 3: Docs insufficient, source code needed
If the docs don't contain enough detail to answer the question:
- Identify which source files would have the answer (use the module doc's Internal Structure section to locate them)
- Read the minimum source files needed
- Answer the question
- Add a staleness flag: "Note: this answer required reading source code
beyond what's in the docs. The following files contain details not yet
captured:
<file list>. Consider runningcodedocs:update --scope <module-path>to capture this."
Level 4: Question outside documented scope
If the question is about code that isn't documented at all (no matching module in the manifest):
- Check if the code exists in the repo
- If yes, answer from source and flag: "This code is not yet documented by
codedocs. Run
codedocs:generateorcodedocs:updateto add it." - If no, tell the user the code doesn't exist in this repo
Staleness Awareness
When answering, check the manifest's last_updated timestamp and git SHA for
the relevant module:
- If the documented SHA matches the current HEAD for that module's files, the docs are fresh - answer with confidence
- If files have changed since the documented SHA, warn: "Note: the docs for
this module were generated at commit
<sha>but the code has changed since. The answer may be outdated. Runcodedocs:update --scope <path>to refresh."
To check staleness without a full git operation, compare the manifest SHA
against git log -1 --format=%H -- <module-path>.
Citation Format
Always cite sources in answers:
From docs:
Source: `docs/modules/auth.md`From multiple docs:
Sources: `docs/OVERVIEW.md`, `docs/modules/auth.md`From source code (fallback):
Source: `src/auth/middleware.ts` (not in docs - consider updating)From both:
Sources: `docs/modules/auth.md`, `src/auth/middleware.ts:42` (detail not in docs)Multi-Turn Q&A
When the user asks follow-up questions in the same session:
- Keep track of which doc files are already loaded in context
- Don't re-read files already loaded unless the question requires a fresh look
- If the conversation is getting deep into a single module, suggest: "For more detail on this module, I can read the source code directly. Want me to?"
coverage-strategy.md
Coverage Strategy
Reference for measuring, improving, and maintaining documentation coverage - how to ensure a large or complex repo is comprehensively documented, not just partially skimmed.
Why coverage matters
Documentation that covers 40% of a codebase is often worse than no documentation: it gives a false sense of completeness and fails the most common question ("where is this?"). Codedocs targets meaningful coverage, not perfection - the goal is that any developer or AI agent can navigate to the right place without reading raw source code.
Running codedocs:status
Command: codedocs:status
Read .codedocs.json and produce a coverage report:
Codedocs Status
===============
Project: <name>
Generated: <date>
Last updated: <date> (commit <sha>)
Updates applied: <N>
Coverage: <N>% (<documented>/<total> source files)
Documented modules (<count>):
- <module-name> (<path>) - <N> files - last updated <date>
- ...
Undocumented areas (<count> directories, <N> files):
- <path> - <N> files [suggestion: add as module or fold into <nearest-module>]
- ...
Stale modules (<count>):
- <module-name> - documented at <sha>, code changed since
- ...
Patterns: <count> documented
- <pattern-name> - last updated <date>
Recommendation: <action based on coverage and staleness>Coverage targets
| Repo size (source files) | Target coverage | Acceptable minimum |
|---|---|---|
| < 50 | 95% | 85% |
| 50-200 | 85% | 75% |
| 200-500 | 75% | 65% |
| 500-1000 | 65% | 55% |
| 1000+ | 55% | 45% (focus on domain modules) |
For very large repos (1000+ files), prioritize coverage by importance:
- Domain modules (business logic) - aim for 90%+ coverage
- API/interface layers - aim for 85%+ coverage
- Infrastructure/platform code - aim for 60%+ coverage
- Utility libraries - aim for 50%+ coverage (often self-explanatory)
- Generated code - exclude from coverage calculation
How to improve coverage
When below target after initial generate
Run the gap analysis - List all directories in the census not covered by any module doc. Sort by file count (highest first).
Batch small undocumented directories - Directories with 1-2 files that are clearly related to a larger documented module should be mentioned in that module's doc rather than getting their own doc.
Create module docs for significant gaps - For uncovered directories with 3+ files, create new module docs. Use the standard module doc template.
Use --exhaustive flag -
codedocs:generate --exhaustivelowers the minimum file threshold to 1 and documents every directory with at least one source file. Useful for repos with many small-but-important modules. Output will be larger but more complete.Group orphan files - Source files not in any directory (directly in
src/or repo root) get documented in a specialmodules/root.mdmodule.
When a module doc is too long (50+ lines of Internal Structure)
Split the module into sub-modules:
- Identify the distinct sub-directories or groupings within the module
- Create
modules/<parent>/directory - Move the parent doc to
modules/<parent>.md(keep it as an index) - Create
modules/<parent>/<child>.mdfor each sub-module - Update
INDEX.mdto point files to their sub-module doc - Update
.codedocs.jsonto addsub_modulesentries
When coverage is high but docs are shallow
Coverage percentage measures file coverage, not depth. Signs of shallow docs:
- Module docs with empty "Implementation Notes" everywhere
- Pattern docs with only one example
- Dependency/Dependent tables with 0-1 entries
- No "Getting Started" section in OVERVIEW.md
For shallow docs, re-read the source files for each module and enrich:
- Add real function/method names to Public API
- Add actual file paths to Internal Structure
- Fill in concrete dependency relationships
- Add working code examples to pattern docs
Prioritization framework for large repos
When a repo is too large to document exhaustively in one session, use this priority order:
Tier 1: Always document first (core understanding)
- Entry points (main files, route definitions, CLI commands)
- Modules that are imported by 3+ other modules (high fan-in = central)
- Modules that import 5+ other modules (high fan-out = integration points)
- Authentication, authorization, and security modules
- Public API surface (what external callers use)
Tier 2: Document second (operational understanding)
- Database and persistence layer
- Background jobs and async processing
- Configuration and feature flags
- Error handling and logging infrastructure
- Core domain/business logic modules
Tier 3: Document when time allows (implementation details)
- Internal utilities and helpers
- Test infrastructure and fixtures
- Build tooling and scripts
- Third-party integration adapters
- UI components (when not the primary focus)
Tier 4: Mention but don't deep-dive
- Generated code (proto files, ORM migrations, GraphQL schemas)
- Vendor/dependency overrides
- One-off scripts
Maintaining coverage over time
After new features are added
Run codedocs:update --diff after each significant feature. This:
- Detects new directories not yet in the manifest
- Flags stale modules whose files changed
- Suggests new module docs for new feature directories
Set a reminder to run codedocs:status at the start of each sprint to catch
coverage drift before it accumulates.
Coverage budget
Define a coverage budget in .codedocs.json:
"config": {
"coverage_budget": {
"minimum_percentage": 70,
"alert_on_drift": 5
}
}With a budget set, codedocs:update will warn if coverage drops below
minimum_percentage or if a single update causes coverage to drop by more
than alert_on_drift percentage points (e.g., a module was deleted but its
doc wasn't cleaned up).
Staleness budget
A module doc is "stale" when the git SHA recorded in the manifest no longer
matches the latest commit on that module's source path. In codedocs:status,
modules stale for more than 30 days are flagged as high priority for update.
Coverage anti-patterns
| Anti-pattern | Effect | Fix |
|---|---|---|
| Stopping at top-level directories | Only 5-10 modules documented for a 200-file repo | Run deep scan (Step 3-4 of generate-workflow) |
One giant module doc for src/ |
Doc is too long to be useful; everything is in one place | Split into sub-modules |
| Skipping small but critical modules | Core utilities undocumented; patterns can't be explained | Lower threshold to 2 files; document them |
| Counting generated files in coverage | Inflated coverage %; real logic is underdocumented | Exclude generated files from census |
| Never running status | Coverage drifts silently over months | Run codedocs:status weekly or in CI |
| Documenting file names but not behavior | High file coverage, zero explanatory value | Every module doc must describe what, why, and how |
generate-workflow.md
Generate Workflow
Complete reference for the codedocs:generate command - discovery heuristics,
module boundary detection, tech stack identification, sub-module splitting, coverage
verification, and output templates.
Discovery Phase
Step 1: Tech stack identification
Scan the repo root (and target path) for manifest files. Each file reveals language, framework, and dependency information:
| Manifest file | Language/Platform | Key info to extract |
|---|---|---|
package.json |
JavaScript/TypeScript | dependencies, scripts, main/module entry |
tsconfig.json |
TypeScript | paths, baseUrl, project references |
Cargo.toml |
Rust | dependencies, workspace members, bin targets |
go.mod |
Go | module path, dependencies |
requirements.txt / pyproject.toml / setup.py |
Python | dependencies, entry points |
composer.json |
PHP | autoload paths, dependencies |
pom.xml / build.gradle |
Java/Kotlin | modules, dependencies |
Gemfile |
Ruby | gems, groups |
mix.exs |
Elixir | deps, applications |
CMakeLists.txt / Makefile |
C/C++ | targets, includes |
Package.swift |
Swift | targets, dependencies |
.csproj / .sln |
C#/.NET | project references, packages |
For monorepos, check for workspace definitions:
package.jsonwithworkspacesfieldCargo.tomlwith[workspace]sectiongo.workfilepnpm-workspace.yamllerna.jsonnx.jsonturbo.json
Record: primary language, framework (if detectable from dependencies), build tool, and test framework.
Step 2: Entry point detection
Entry points are the starting locations for understanding code flow. Detect them by checking (in priority order):
- Explicit main files -
main.ts,main.go,main.rs,__main__.py,Main.java,Program.cs - Index/entry exports -
index.ts,index.js,lib.rs,__init__.py,mod.rs - Framework entry points -
app.ts(Express/Fastify),pages/orapp/(Next.js),src/App.tsx(React),manage.py(Django),config/routes.rb(Rails) - CLI entry points -
bin/directory,scriptsin package.json,[tool.poetry.scripts]in pyproject.toml - Config-defined entries -
mainormodulefield in package.json,[lib]in Cargo.toml
Step 3: Full recursive directory census
Before detecting module boundaries, build a complete census of the repo. Walk the entire directory tree (excluding ignore paths) and record every directory with its file count. This census drives both module detection and coverage verification.
Census format:
<path> | <source file count> | <depth>
src/ | 3 | 1
src/auth/ | 8 | 2
src/auth/strategies/ | 4 | 3
src/api/ | 22 | 2
src/api/routes/ | 11 | 3
src/api/middleware/ | 6 | 3
...What to count as source files: .ts, .js, .py, .go, .rs, .java,
.kt, .rb, .ex, .exs, .cs, .cpp, .c, .swift, .php. Exclude
lock files, config files (.json, .yaml, .toml unless they define code),
test files (unless include_test_files: true), and generated files.
Step 4: Multi-level module boundary detection
Modules are the primary unit of documentation. Apply these heuristics in layers, from coarsest to finest, collecting all candidates before deduplicating.
Layer 1: Monorepo packages (highest priority)
Each workspace package is its own top-level module. For each package:
- Record the package root as a module boundary
- Recurse into the package to find sub-modules (apply Layer 2-4 within it)
Layer 2: Top-level structural directories
Inside each package (or the repo root if not a monorepo), scan the first two levels of directories for structural modules:
Explicit source roots: src/, lib/, app/, pkg/, cmd/
- Every direct child directory of these roots with 2+ source files is a module candidate
Framework convention directories (these are themselves modules):
- Express/Fastify/Hapi:
routes/,controllers/,middleware/,services/,models/ - Next.js:
app/(orpages/),components/,lib/,server/ - Django/Flask:
views/,models/,serializers/,urls/ - Rails:
app/models/,app/controllers/,app/services/ - Spring:
controller/,service/,repository/,config/ - Go: every directory containing
.gofiles is a package (and a module candidate) - Rust: every directory containing
mod.rsorlib.rs
Domain/feature directories - Any directory 1-3 levels deep whose name
suggests a domain concept: auth, billing, users, products, orders,
notifications, search, analytics, admin, api, core, shared,
common, utils, helpers, hooks, store, context, types
Layer 3: Deep scanning for large modules
For every module candidate from Layer 2 that has 15+ source files OR contains subdirectories with 3+ files each, recursively scan inside it to find sub-modules. Apply this rule:
If a module contains a subdirectory with 3+ source files and a distinct purpose (different name from parent, has its own index/exports), that subdirectory becomes a sub-module documented in
modules/<parent>/<child>.md.
Examples of when to split:
src/api/with 22 files splits intoapi/routes,api/middleware,api/validatorssrc/components/with 30 files splits intocomponents/ui,components/forms,components/layoutsrc/utils/with 18 files splits intoutils/string,utils/date,utils/http
Examples of when NOT to split:
src/auth/with 8 files - document as one module even with 2-3 subdirssrc/config/with 5 files - too small to warrant sub-modules- Single-level flat directories with no internal structure
Layer 4: Minimum-threshold cleanup
After collecting all candidates:
- Keep modules with 2+ source files (lower than the manifest default to avoid gaps)
- Merge candidates that are clearly the same logical module (e.g.,
types/with 1 file that only re-exports frommodels/- fold intomodels) - Flag directories with 1 source file as "minor files" - mention in the parent module doc rather than creating a separate module doc
Step 5: Cross-cutting pattern detection (expanded)
Patterns are concerns that span multiple modules. Scan for all of these:
Structural patterns:
- Error handling - Shared error types, error middleware, Result/Either patterns, custom exception classes, error codes/enums
- Logging/observability - Logger setup, structured logging, metrics export, tracing instrumentation, correlation IDs
- Configuration - Config loading order, environment variable handling, feature flags, secrets management
- Authentication/authorization - Auth middleware, JWT/session handling, guards, decorators, permission checks, RBAC
Data patterns:
- Database access - ORM setup, migration patterns, repository/DAO patterns, connection management, query builders
- Caching - Cache clients, cache key conventions, TTL patterns, cache invalidation strategies
- Event/message handling - Queue clients, event emitters, pub/sub patterns, event schemas
- External API clients - HTTP client wrappers, retry logic, circuit breakers, service clients
Code quality patterns:
- Testing - Test directory structure, test utilities, fixtures, factories, mocking patterns, test configuration, test helpers
- Validation - Input validation libraries, schema validation, DTO patterns, sanitization
- Type system - Shared type definitions, interfaces, enums, generics patterns
- Dependency injection - DI containers, service registration, provider patterns
Operational patterns:
- API conventions - Request/response schemas, pagination patterns, versioning, error response format, serialization
- Background jobs - Job queue setup, worker definitions, scheduled tasks, job retry patterns
- File/storage handling - File upload patterns, storage clients, CDN integration
- Internationalization - i18n library setup, translation file structure, locale handling
Only create a pattern doc if the pattern appears in 2+ modules. Single-module patterns belong in the module doc.
Step 6: Coverage verification
After collecting all module candidates and patterns, run a coverage check before presenting the plan. This ensures the documentation plan covers the codebase adequately.
Calculate coverage:
covered_files = sum of source files in all module candidates
total_files = total source files from the census (Step 3)
coverage = covered_files / total_files * 100Coverage targets by repo size:
| Total source files | Minimum acceptable coverage |
|---|---|
| < 50 files | 90% |
| 50-200 files | 80% |
| 200-500 files | 70% |
| 500+ files | 60% (focus on top-level architecture) |
If coverage is below target:
- Identify uncovered directories (those in the census but not in any module candidate)
- For each uncovered directory with 2+ source files, add it as a module candidate
- For single files not in any module, group them into a
miscmodule or fold them into the nearest parent module - Re-run coverage calculation
- Report the final coverage percentage in the discovery plan
Always report in the discovery plan:
Coverage: <N>% (<covered> of <total> source files documented)Step 7: Present the plan
Before writing any documentation, present the discovery results to the user:
Codedocs Discovery Plan
========================
Repository: <name>
Tech stack: <language> + <framework> (<build tool>)
Entry points: <list>
Modules to document (<count>):
Top-level modules:
- <module-name> (<path>) - <one-line summary> (<N> files)
- ...
Sub-modules:
- <parent>/<child> (<path>) - <one-line summary> (<N> files)
- ...
Patterns detected (<count>):
- <pattern-name> - <where it appears>
- ...
Coverage: <N>% (<covered> of <total> source files)
Estimated output: <N> files in <output-dir>/
- 1 OVERVIEW.md
- 1 INDEX.md
- <N> module docs
- <N> pattern docs
- 1 .codedocs.json
Proceed? [Y/n]Wait for user approval. They may want to add, remove, rename, or merge modules. If coverage is below target, proactively call out which directories are uncovered and ask if they should be included.
Step 8: Generate GETTING_STARTED.md
After writing module and pattern docs, generate GETTING_STARTED.md by
extracting and expanding all runnable commands from the repo. This is the
authoritative local development guide.
How to discover commands:
- package.json
scripts- List every script with a one-line description of what it does. Group them by purpose (dev, test, build, lint, etc.). - Makefile targets - List every non-phony target with its recipe and purpose.
- Taskfile.yml / justfile - Same as Makefile.
- Framework CLI conventions - Detect from the stack:
- Next.js/Vite/CRA:
dev,build,start,lint,test - Django:
manage.py runserver,migrate,makemigrations,shell - Rails:
rails server,rails console,rails db:migrate,rspec - Go:
go run ./...,go test ./...,go build - Rust:
cargo run,cargo test,cargo build,cargo clippy - Python: look for
pyproject.tomlscripts,tox.ini,pytest.ini
- Next.js/Vite/CRA:
- Docker / docker-compose - List
docker compose up,down, and any named services that a developer would interact with. - CI config - Read
.github/workflows/,.gitlab-ci.yml, or similar. The CI steps reveal the canonical commands the project actually uses in production. Extract the test, build, and lint commands from there. - README - If the repo has a README with setup/usage sections, extract commands from code blocks.
- Environment files - Check for
.env.example,.env.sample, or documented env vars in README. List required variables and their purpose.
GETTING_STARTED.md template:
# Getting Started
Everything you need to run, test, and develop <Project Name> locally.
## Prerequisites
<List of required tools and minimum versions. Only include what's actually
needed - don't list things like "a computer" or "internet access".>
| Tool | Version | Install |
|---|---|---|
| Node.js | >= 20 | https://nodejs.org |
| pnpm | >= 9 | `npm install -g pnpm` |
| Docker | >= 24 | https://docker.com |
| <etc.> | | |
## Installation
```bash
# Clone the repo
git clone <repo-url>
cd <repo-name>
# Install dependencies
<install command - e.g. pnpm install, pip install -e ".[dev]", cargo build>Environment Setup
# Copy the example env file
cp .env.example .env
# Edit .env and fill in the required values:
# DATABASE_URL - PostgreSQL connection string
# JWT_SECRET - Random secret for signing tokens (min 32 chars)
# <etc.> - <purpose><If there are external services needed (database, Redis, etc.), explain how to start them:>
# Start required services via Docker
docker compose up -dDevelopment
<How to start the development server / run the app locally.>
<dev command - e.g. pnpm dev, python manage.py runserver, cargo run><Note the URL(s) the app runs on, e.g. "Opens at http://localhost:3000">
<migration command - e.g. pnpm db:migrate, python manage.py migrate>Testing
# Run all tests
<test command>
# Run a specific test file
<test command for single file>
# Run tests in watch mode
<watch command if available>
# Run with coverage
<coverage command if available><Explain what the test suite covers and any environment requirements (e.g., "requires a running database").>
Building
# Build for production
<build command>
# Preview the production build locally (if applicable)
<preview command>Linting & Formatting
# Lint
<lint command>
# Format
<format command>
# Type check (if applicable)
<typecheck command><If there's a pre-commit hook or CI check, mention it here.>
Database
Only include this section if the repo has a database layer.
# Apply pending migrations
<migrate command>
# Create a new migration
<create migration command>
# Reset the database (destructive)
<reset command>
# Open a database shell / GUI
<db shell command>
# Seed with development data
<seed command if available>Common Workflows
Adding a new API endpoint
# <step 1 - e.g. create the route file>
# <step 2 - e.g. register it in the router>
# <step 3 - e.g. run tests>Running a subset of tests
# Run tests matching a pattern
<command>
# Run tests for a specific module
<command>Debugging
<How to run the app in debug mode, attach a debugger, or read logs.>
<debug command if available>CI/CD
# Reproduce CI checks locally
<lint command>
<typecheck command>
<test command>
<build command><If there's a deployment process, mention how it's triggered.>
---
### Step 9: Generate INDEX.md
After writing all module docs, generate `INDEX.md` as a lookup table mapping
every significant source file to its module doc. This is primarily for AI agent
navigation.
```markdown
# File Index
Quick lookup: find which module documents any file in this repo.
| File | Module | Doc |
|---|---|---|
| `src/auth/middleware.ts` | auth | `modules/auth.md` |
| `src/auth/strategies/jwt.ts` | auth/strategies | `modules/auth/strategies.md` |
| `src/api/routes/users.ts` | api/routes | `modules/api/routes.md` |
| ... | ... | ... |Only include files that are part of a documented module. Skip generated files, lock files, and trivial configs.
Output templates
OVERVIEW.md Template
# <Project Name>
<2-3 sentence summary of what the project does, who it's for, and the core
problem it solves.>
## Tech Stack
| Layer | Technology |
|---|---|
| Language | <e.g. TypeScript> |
| Framework | <e.g. Next.js 14> |
| Database | <e.g. PostgreSQL via Prisma> |
| Testing | <e.g. Vitest + Playwright> |
| Build | <e.g. Turbopack> |
## Project Structure
<Directory tree of the repo showing only meaningful directories and key files.
Collapse noisy subtrees (node_modules, dist, .git) entirely. Annotate every
entry with a short inline comment explaining its role. Aim for 30-60 lines -
enough to understand the layout at a glance without scrolling forever.>
Rules for generating the tree:
- Show every directory that has a module doc
- Show key root-level config files (package.json, Dockerfile, Makefile, etc.)
- Show entry point files explicitly (main.ts, manage.py, etc.)
- Collapse deeply nested subtrees into a single annotated line
- Omit: node_modules, dist, build, .git, coverage, lock files, generated files
- Use `# comment` inline annotations on every line - this is what makes the
tree useful vs just running `tree` in the terminal
## Architecture
<2-4 paragraphs describing the high-level architecture. Include:
- System boundaries (what's in this repo vs external services)
- Request/data flow (how a request enters, gets processed, and returns)
- Key architectural decisions and their rationale>
## Entry Points
| Entry point | Purpose |
|---|---|
| `<path>` | <what it starts/serves> |
## Module Map
| Module | Path | Description | Files |
|---|---|---|---|
| <name> | `<path>` | <one-line purpose> | <N> |
> Sub-modules are listed under their parent. See `INDEX.md` for file-level lookup.
## Cross-cutting Patterns
| Pattern | Doc | Modules affected |
|---|---|---|
| <name> | `patterns/<name>.md` | <module list> |
## Key Concepts
<Glossary of domain-specific terms used throughout the codebase. Only include
terms that would confuse someone unfamiliar with the project.>
## Getting Started
<Minimal steps to clone, install, and run the project locally. Pull from
existing README if available.>
## Documentation Coverage
Generated by codedocs. Coverage: <N>% (<covered>/<total> source files).
Last updated: <timestamp> at commit `<sha>`.Module Doc Template
Each module doc in modules/ follows this structure. For top-level modules with
sub-modules, include a sub-module index at the top.
# <Module Name>
<1-2 sentence summary of the module's purpose and responsibility.>
## Sub-modules
> Only include this section if the module has sub-modules.
| Sub-module | Doc | Description |
|---|---|---|
| <name> | `modules/<parent>/<child>.md` | <purpose> |
## Public API
<List of exported functions, classes, types, or endpoints with brief
descriptions. This is what other modules consume.>
## Internal Structure
<How the module is organized internally. Key files and their roles.
Only list files that are important for understanding - skip trivial
utility files.>
| File | Purpose |
|---|---|
| `<relative-path>` | <what it does> |
## Dependencies
| Depends on | Why |
|---|---|
| <module/package> | <what it uses from it> |
## Dependents
| Used by | How |
|---|---|
| <module> | <what it imports/uses> |
## Implementation Notes
<Key design decisions, non-obvious behavior, performance considerations,
or known limitations specific to this module. Skip this section if there
is nothing noteworthy.>Pattern Doc Template
Each pattern doc in patterns/ follows this structure:
# <Pattern Name>
<1-2 sentence description of the pattern and why the codebase uses it.>
## Where It Appears
<List of modules that implement or interact with this pattern.>
## Convention
<The rules to follow when working with this pattern. Be specific -
code style, naming conventions, file placement, etc.>
## Examples
<2-3 concrete examples from the codebase showing the pattern in use.
Reference actual file paths.>
## Adding to This Pattern
<What a developer should do when adding new code that touches this pattern.
E.g., "When adding a new route, register it in X and add error handling
using Y."> output-structure.md
Output Structure
Complete specification for the codedocs output directory, file formats,
and the .codedocs.json manifest schema.
Directory Layout
<output-dir>/ # Default: docs/ at repo root
OVERVIEW.md # Architecture, tech stack, project structure tree, module map
GETTING_STARTED.md # Dev environment setup, all runnable commands, workflows
INDEX.md # File-to-module lookup table for AI agent navigation
.codedocs.json # Manifest: tracked modules, SHAs, config, coverage stats
modules/ # One file per code module (flat for simple modules)
<module-name>.md # e.g. auth.md, api.md, database.md
<module-name>/ # Directory for modules with sub-modules
<sub-module>.md # e.g. api/routes.md, api/middleware.md
patterns/ # One file per cross-cutting concern
<pattern-name>.md # e.g. error-handling.md, testing.mdWhen to use flat files vs sub-module directories
Use a flat file (modules/auth.md) when:
- The module has fewer than 15 source files
- The module has no meaningfully distinct internal directories
- All of the module's behavior can be described in one focused document
Use a sub-module directory (modules/api/routes.md, modules/api/middleware.md) when:
- The module has 15+ source files with distinct internal groupings
- Sub-directories have 3+ files each with a clearly different purpose
- The module doc would otherwise need 4+ "Internal Structure" subsections
A parent module with sub-modules still gets its own <module-name>.md as an
index that describes the module's overall purpose and lists sub-modules. The
sub-module files contain the detailed content.
Naming conventions
- Module files: kebab-case matching the directory or package name.
src/auth/becomesmodules/auth.md.packages/user-service/becomesmodules/user-service.md. - Sub-module files: kebab-case inside a directory named after the parent.
src/api/routes/becomesmodules/api/routes.md. - Pattern files: kebab-case describing the concern.
patterns/error-handling.md,patterns/testing-strategy.md,patterns/logging-conventions.md. - No deeper nesting: Sub-module directories are the deepest level allowed.
modules/<parent>/<child>.mdis the maximum depth. Do not createmodules/<parent>/<child>/<grandchild>.md.
Output directory configuration
The output directory defaults to docs/ at the repo root. Override with
the --output flag:
codedocs:generate --output documentation/
codedocs:generate path/to/subpackage --output path/to/subpackage/docs/The output directory is recorded in the manifest so that codedocs:ask and
codedocs:update can find it automatically.
.codedocs.json Manifest Schema
{
"version": "1.1",
"project_name": "<repo or directory name>",
"output_dir": "docs/",
"generated_at": "2026-03-18T10:30:00Z",
"last_updated": "2026-03-18T14:45:00Z",
"last_global_sha": "abc1234def5678...",
"update_count": 0,
"output_files": {
"overview": "OVERVIEW.md",
"getting_started": "GETTING_STARTED.md",
"index": "INDEX.md"
},
"tech_stack": {
"primary_language": "TypeScript",
"framework": "Next.js 14",
"build_tool": "Turbopack",
"test_framework": "Vitest",
"package_manager": "pnpm"
},
"coverage": {
"total_source_files": 187,
"documented_source_files": 154,
"percentage": 82
},
"modules": [
{
"name": "auth",
"source_path": "src/auth/",
"doc_path": "modules/auth.md",
"description": "Authentication and authorization middleware",
"last_sha": "abc1234...",
"last_updated": "2026-03-18T10:30:00Z",
"file_count": 8,
"primary_language": "TypeScript",
"sub_modules": []
},
{
"name": "api",
"source_path": "src/api/",
"doc_path": "modules/api.md",
"description": "REST API route handlers and middleware",
"last_sha": "def5678...",
"last_updated": "2026-03-18T10:30:00Z",
"file_count": 22,
"primary_language": "TypeScript",
"sub_modules": [
{
"name": "api/routes",
"source_path": "src/api/routes/",
"doc_path": "modules/api/routes.md",
"description": "Route definitions for all API endpoints",
"last_sha": "def5678...",
"last_updated": "2026-03-18T10:30:00Z",
"file_count": 11
},
{
"name": "api/middleware",
"source_path": "src/api/middleware/",
"doc_path": "modules/api/middleware.md",
"description": "Request/response middleware chain",
"last_sha": "def5678...",
"last_updated": "2026-03-18T10:30:00Z",
"file_count": 6
}
]
}
],
"patterns": [
{
"name": "error-handling",
"doc_path": "patterns/error-handling.md",
"description": "Shared error types and error middleware",
"appears_in": ["auth", "api", "database"]
}
],
"config": {
"ignore_paths": ["node_modules", "dist", "build", ".git", "coverage"],
"min_module_files": 2,
"include_test_files": false,
"max_sub_module_depth": 1
}
}Field descriptions
| Field | Type | Description |
|---|---|---|
version |
string | Manifest schema version. Currently "1.1" |
project_name |
string | Name of the project (from package.json, Cargo.toml, or directory name) |
output_dir |
string | Relative path to the output directory from repo root |
generated_at |
string | ISO 8601 timestamp of initial generation |
last_updated |
string | ISO 8601 timestamp of most recent update |
last_global_sha |
string | Git commit SHA at last generation/update |
update_count |
number | Number of times codedocs:update has been run |
output_files |
object | Paths to top-level output files (overview, getting_started, index) |
tech_stack |
object | Detected technology stack |
coverage |
object | Documentation coverage statistics |
coverage.total_source_files |
number | Total source files in repo (excluding ignored paths) |
coverage.documented_source_files |
number | Source files covered by at least one module doc |
coverage.percentage |
number | Integer percentage of documented files |
modules |
array | List of documented modules (includes top-level and those with sub-modules) |
modules[].name |
string | Module name (kebab-case, or parent/child for sub-modules) |
modules[].source_path |
string | Relative path to source directory |
modules[].doc_path |
string | Relative path to module doc file (from output dir) |
modules[].description |
string | One-line description of the module |
modules[].last_sha |
string | Git SHA of latest commit touching this module |
modules[].last_updated |
string | ISO 8601 timestamp of last doc update for this module |
modules[].file_count |
number | Number of source files in the module |
modules[].primary_language |
string | Dominant language in the module |
modules[].sub_modules |
array | Sub-module entries (same shape, no further nesting) |
patterns |
array | List of documented cross-cutting patterns |
patterns[].name |
string | Pattern name (kebab-case) |
patterns[].doc_path |
string | Relative path to pattern doc file |
patterns[].description |
string | One-line description |
patterns[].appears_in |
array | Module names where this pattern is found |
config |
object | Generation configuration |
config.ignore_paths |
array | Paths to skip during discovery |
config.min_module_files |
number | Minimum files for a directory to become a module (default: 2) |
config.include_test_files |
boolean | Whether to scan test files during discovery |
config.max_sub_module_depth |
number | Maximum nesting depth for sub-modules (always 1) |
File Format Guidelines
All doc files
- Use standard GitHub-flavored Markdown
- Start with a level-1 heading (
# Title) - Use level-2 headings (
## Section) for major sections - Use tables for structured data (dependencies, exports, config)
- Use code blocks with language annotation for code references
- Reference file paths relative to the repo root
- Keep each file self-contained - don't require reading other files to understand the basics (cross-references are fine for deep dives)
OVERVIEW.md specifics
- Must be readable in under 5 minutes by a human
- Must contain enough context for an AI agent to route questions to the right module doc
- Module Map table is the routing index - every documented module must appear here (sub-modules nested under their parent)
- Cross-cutting Patterns table is the secondary routing index
- Project Structure tree must be annotated - every line has an inline comment
- Getting Started section is a brief pointer: "See
GETTING_STARTED.mdfor the full development guide" - Always include a Documentation Coverage line at the bottom
GETTING_STARTED.md specifics
- The authoritative guide for running and developing the repo locally
- Must be fully self-contained: a developer with a clean machine should be able to follow it top-to-bottom without consulting any other file
- All commands must be copy-pasteable and verified against actual scripts in the repo (package.json scripts, Makefile targets, Cargo commands, etc.)
- Organized into sections: Prerequisites, Installation, Environment, Dev server, Testing, Building, Linting/formatting, and Common workflows
- If the repo has a README with setup instructions, extract and expand them - don't just repeat them verbatim; add context and fill gaps
- Common workflows section covers the day-to-day developer actions: how to add a feature, run a subset of tests, apply a migration, etc.
INDEX.md specifics
- One row per source file that belongs to a documented module
- Sorted alphabetically by file path
- Columns: File, Module, Doc (link to module doc)
- Primary purpose is AI agent navigation: given a file name, find the doc
- Does not include undocumented files (they're not linked to any doc)
- Updated during
codedocs:updatewhen files are added or moved
Module doc specifics
- Public API section is the most important - this is what consumers need
- Internal Structure table should cover every significant file (not trivial helpers)
- Dependencies and Dependents sections enable understanding the module in context without reading the full codebase
- Implementation Notes is optional - only include if there are genuinely non-obvious design decisions
- Parent module docs (those with sub-modules) should have a Sub-modules table immediately after the opening summary
Pattern doc specifics
- Convention section must be prescriptive, not descriptive - tell the reader what to do, not just what exists
- Examples must reference actual file paths in the repo
- Where It Appears must list specific modules, not vague references
- Adding to This Pattern section helps developers extend the pattern correctly
Default Ignore Paths
These paths are always excluded from discovery unless explicitly overridden:
node_modules/
dist/
build/
.git/
coverage/
.next/
.nuxt/
__pycache__/
*.pyc
target/ # Rust, Java
vendor/ # Go, PHP, Ruby
.cache/
.turbo/
.vercel/
.output/
out/
.expo/
.svelte-kit/
generated/
gen/
*.generated.*
*.pb.go # Protobuf generated
*_pb2.py # Protobuf generatedTest directories (__tests__/, test/, tests/, spec/) are excluded by
default but can be included with config.include_test_files: true in the
manifest. When included, test files count toward coverage but are documented
under the patterns/testing-strategy.md pattern doc rather than as modules.
update-workflow.md
Update Workflow
Complete reference for the codedocs:update command - diff detection, manifest-driven
scoping, new module detection, and OVERVIEW.md synchronization.
Pre-flight Check
- Look for
.codedocs.jsonin the output directory - If missing, respond: "No existing codedocs found. Run
codedocs:generatefirst.codedocs:updateonly works with existing documentation." - If found, read the full manifest to understand the current documentation state
Mode 1: Targeted Scope Update
Command: codedocs:update --scope path/to/module
Step-by-step workflow
Validate scope - Confirm the specified path exists in the repo. Check if it maps to an existing module in the manifest.
Re-discover the scoped path - Run the discovery phase (from
generate-workflow.md) limited to the specified directory. This produces an updated snapshot of:- File list and primary language
- Exports (public API surface)
- Imports from other modules
- Internal structure
Diff against existing module doc - Compare the new discovery against the current content in
modules/<module>.md. Identify:- New exports not in the current doc
- Removed exports still listed in the current doc
- Changed dependencies (new imports or dropped imports)
- New files that might deserve mention in Internal Structure
- Changed file structure (renamed, moved, or deleted files)
Rewrite the module doc - Update only the sections that changed. Keep unchanged sections intact to preserve any manual edits or notes the user may have added.
Check OVERVIEW.md impact - If any of these changed, update OVERVIEW.md:
- Module's one-line description in the Module Map table
- Module's dependencies (affects architecture understanding)
- Module was renamed or moved
Check pattern impact - If the module's changes affect a documented pattern (e.g., a new error type, a changed auth flow), flag it: "The changes in
<module>may affect the pattern docpatterns/<pattern>.md. Review and update if needed."Update manifest - Set the module's
last_shato the current commit SHA andlast_updatedto the current timestamp.
Handling new paths
If the --scope path doesn't match any existing module in the manifest:
- Treat it as a new module
- Run the full module doc generation workflow
- Add it to the manifest
- Add it to OVERVIEW.md's Module Map
- Prompt: "This path wasn't previously documented. I've added it as a new
module:
<name>. Verify the module name and description are correct."
Mode 2: Git Diff Update
Command: codedocs:update --diff [base..head]
Determining the diff range
- If
base..headis provided, use it directly - If only
--diffis provided (no range), determine the range automatically:- Read
last_global_shafrom the manifest - Use
last_global_sha..HEADas the range - If
last_global_shais missing, fall back toHEAD~10..HEADand warn: "No baseline SHA in manifest. Diffing last 10 commits. For accurate results, run a fullcodedocs:generateto establish a baseline."
- Read
Step-by-step workflow
Get changed files - Run:
git diff --name-only <base>..<head>Collect the list of changed file paths.
Filter to source files - Remove non-source files that don't affect documentation: images, lock files, CI configs, editor configs, etc. Keep: source code files, manifest files (package.json, etc.), config files that affect architecture.
Map files to modules - For each changed file, find its parent module using the manifest's
source_pathmappings. Build a set of affected modules.Categorize changes:
- Modified modules - Modules with changed source files
- New module candidates - Changed files in directories not mapped to any existing module
- Deleted modules - Modules whose entire source directory was removed
- Config changes - Changes to root-level config that might affect OVERVIEW.md (package.json dependencies, build config, etc.)
Process modified modules - For each affected module, run the targeted scope update workflow (Mode 1, steps 2-7).
Handle new module candidates - For directories with changed files that don't belong to any documented module:
- If the directory has 3+ source files, suggest it as a new module
- If fewer, suggest adding the files to the nearest existing module's doc
- Prompt the user for confirmation before adding
Handle deleted modules - If a documented module's source directory no longer exists:
- Remove the module doc from
modules/ - Remove the entry from the manifest
- Remove the row from OVERVIEW.md's Module Map
- Warn: "Module
<name>was removed (source directory deleted). Its documentation has been cleaned up."
- Remove the module doc from
Update OVERVIEW.md - Sync any changes to the Module Map, Tech Stack (if dependencies changed), or Architecture section (if major structural changes detected).
Update manifest - Bump
last_global_shato<head>. Update per-module SHAs for all modified modules.
Summary output
After processing, print a summary:
Codedocs Update Summary
========================
Diff range: <base>..<head> (<N> commits)
Files changed: <N>
Modules updated: <list>
New modules added: <list or "none">
Modules removed: <list or "none">
Pattern docs flagged: <list or "none">
Updated files:
- docs/modules/<name>.md (modified)
- docs/OVERVIEW.md (module map updated)
- docs/.codedocs.json (manifest updated)OVERVIEW.md Sync Rules
OVERVIEW.md should be updated during any update operation if:
- Module Map changed - Module added, removed, renamed, or description changed
- Tech Stack changed - New dependency added to manifest file that changes the tech stack table (e.g., new database, new framework)
- Entry points changed - New CLI command, new route file, new main entry
- Architecture changed - Major structural refactor detected (multiple modules affected, new inter-module dependencies)
For minor changes (single module internal update, no API changes), skip OVERVIEW.md to avoid unnecessary churn.
Manifest Update Rules
After every update operation:
- Set
last_global_shato the current HEAD (or theheadfrom the diff range) - For each updated module, set
last_shato the latest commit touching that module's source path - Set
last_updatedto the current ISO 8601 timestamp - If modules were added or removed, update the
modulesarray accordingly - Increment
update_countby 1 (tracks how many times docs have been updated)
Frequently Asked Questions
What is codedocs?
Use this skill when generating AI-agent-friendly documentation for a git repo or directory, answering questions about a codebase from existing docs, or incrementally updating documentation after code changes. Triggers on codedocs:generate, codedocs:ask, codedocs:update, "document this codebase", "generate docs for this repo", "what does this project do", "update the docs after my changes", or any task requiring structured codebase documentation that serves AI agents, developers, and new team members.
How do I install codedocs?
Run npx skills add AbsolutelySkilled/AbsolutelySkilled --skill codedocs in your terminal. The skill will be immediately available in your AI coding agent.
What AI agents support codedocs?
codedocs works with claude-code, gemini-cli, openai-codex, mcp. Install it once and use it across any supported AI coding agent.