Analyze codebase architecture. Creates ./.gtd/CODEBASE.md
Core responsibilities:
Flow: Discover → Classify → Document </objective>
<context> **Output:**./.gtd/CODEBASE.mdAgents used:
research — For deep dives on unclear modules
</context>Document what IS, not what SHOULD BE. Save opinions for later.
Start with directory structure. Go deep only when:
CODEBASE.md is updated when:
--refreshNEVER describe a module based on its name alone.
UserService might delete users, not serve themutils/ might contain critical business logiccache.ts might write to databaseEvery description requires reading actual code.
Every claim must cite evidence:
package.json, go.mod, or actual importsNo citation = don't write it.
If you can't verify something, add it to Open Questions.
Better: "Open Question: What does core/ do?"
Worse: "core/ contains core business logic" (guessed from name)
Check if $ARGUMENTS contains --refresh:
If REFRESH mode:
./.gtd/CODEBASE.mdIf NEW mode:
ls -la
cat package.json 2>/dev/null || cat Cargo.toml 2>/dev/null || cat go.mod 2>/dev/null || cat requirements.txt 2>/dev/null || echo "No manifest found"
Identify:
find . -type d -maxdepth 3 | grep -v node_modules | grep -v .git | grep -v __pycache__ | head -50
Map top-level directories:
src/, lib/, app/ → Core codetest/, tests/, __tests__/ → Test suitesconfig/, .env* → Configurationscripts/, bin/ → Toolingdocs/ → DocumentationFind entry points by convention:
main.*, index.*, app.*server.*, cli.*package.json scriptsTrigger: After mapping directory structure (Step 2.2). Concurrency: As many as needed.
Fill prompt and spawn:
<objective>
Analyze and classify modules in: {root_dir}
</objective>
<discovery_checklist>
1. Map Project Structure (directories, key files)
2. Classify Modules (Domain, Infra, API, Shared)
3. Identify Entry Points (HTTP, CLI, Workers)
4. Catalog Patterns (Naming, Error Handling, Testing)
</discovery_checklist>
<output_format>
Codebase Map (CODEBASE.md draft):
- Tech Stack Summary
- Module Classification Table
- Entry Points List
- Observed Patterns
- Open Questions (for anything unclear)
</output_format>
Task(
prompt=filled_prompt,
subagent_type="researcher",
description="Mapping codebase architecture"
)
Note: The subagent will read files without polluting your main context.
Review the subagent's draft. If "Open Questions" remain, manually check or spawn another task.
Bash:
mkdir -p ./.gtd
Write to ./.gtd/CODEBASE.md:
# Codebase Overview
**Generated:** {date}
**Last Updated:** {date}
## Tech Stack
| Layer | Technology |
| --------- | ----------- |
| Language | {language} |
| Runtime | {runtime} |
| Framework | {framework} |
| Database | {database} |
| ... | ... |
## Project Structure
{tree structure with annotations}
## Modules
### {Module Name}
**Path:** `{path}`
**Type:** {Domain | Infrastructure | API | Shared}
**Purpose:** {one-line description}
Key files:
- `{file}` — {responsibility}
### {Next Module}
...
## Entry Points
| Entry Point | Type | File | Purpose |
|-------------|------|------|---------|
| {name} | HTTP/CLI/Worker | {file} | {purpose} |
## Patterns & Conventions
(Only include patterns you verified in 2+ files. Cite examples.)
- **File naming:** {pattern}
- **Error handling:** {pattern}
- **Testing:** {pattern}
## Dependencies (Key)
| Dependency | Purpose |
|------------|---------|
| {name} | {why it's used} |
## Open Questions
- {Anything unclear that needs investigation}
<offer_next>
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GTD ► CODEBASE OVERVIEW COMPLETE ✓
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Overview written to ./.gtd/CODEBASE.md
| Section | Items |
|---------|-------|
| Modules | {N} |
| Entry Points | {N} |
| Key Dependencies | {N} |
─────────────────────────────────────────────────────
▶ Next Up
/spec — define what you want to build (now with codebase context)
─────────────────────────────────────────────────────
</offer_next>
<forced_stop> STOP. The workflow is complete. Do NOT automatically run the next command. Wait for the user. </forced_stop>