diff --git a/.planning/ROADMAP.md b/.planning/ROADMAP.md
index f546baca2..3aa598c1f 100644
--- a/.planning/ROADMAP.md
+++ b/.planning/ROADMAP.md
@@ -67,36 +67,50 @@ Plans:
### Phase 5: Subagent Codebase Analysis
**Goal:** Prevent context exhaustion on large codebases by delegating analysis to subagents
**Depends on:** Phase 4
-**Plans:** 2 plans
+**Status:** Gap closure in progress
+**Plans:** 4 plans (2 complete, 2 gap closure)
Plans:
-- [ ] 05-01-PLAN.md — Create gsd-entity-generator subagent (Wave 1)
-- [ ] 05-02-PLAN.md — Refactor analyze-codebase to use subagent delegation (Wave 2)
+- [x] 05-01-PLAN.md — Create gsd-entity-generator subagent (Wave 1)
+- [x] 05-02-PLAN.md — Refactor Step 9 for subagent delegation (Wave 2) — partial, gap found
+- [ ] 05-03-PLAN.md — Create gsd-indexer subagent for Steps 2-3 (Wave 3) — gap closure
+- [ ] 05-04-PLAN.md — Refactor Steps 2-3 for subagent delegation (Wave 4) — gap closure
**Wave Structure:**
-- Wave 1: 05-01 (agent definition)
-- Wave 2: 05-02 (command refactor + verification)
+- Wave 1: 05-01 (entity generator agent)
+- Wave 2: 05-02 (Step 9 refactor)
+- Wave 3: 05-03 (indexer agent) — gap closure
+- Wave 4: 05-04 (Steps 2-3 refactor + verification) — gap closure
**Why this phase:**
- Current entity generation loads file contents in orchestrator context
- On large codebases (500+ files), orchestrator exhausts context during file selection and batching
-- Subagent delegation gives fresh 200k context for entity generation
+- Subagent delegation gives fresh 200k context for file processing
+
+**Gap Found (05-VERIFICATION.md):**
+- Original scope only addressed Step 9 (entity generation)
+- Actual context exhaustion occurs during Steps 2-3 (indexing)
+- Orchestrator reads ALL file contents during indexing, not just entity generation
+- Need additional gsd-indexer subagent for Steps 2-3
**Delivers:**
- `gsd-entity-generator` subagent following gsd-codebase-mapper pattern
-- Refactored `/gsd:analyze-codebase` that spawns subagent instead of inline batching
+- `gsd-indexer` subagent for file reading and export/import extraction
+- Refactored `/gsd:analyze-codebase` with full subagent delegation
- Preserved orchestrator context for large codebase analysis
**Requirements:**
-- INTEL-08: Entity generation delegated to subagent (not inline)
-- INTEL-09: Subagent writes entities directly, returns statistics only
-- INTEL-10: Orchestrator passes file paths, not file contents
+- INTEL-08: Entity generation delegated to subagent (not inline) ✓
+- INTEL-09: Subagent writes entities directly, returns statistics only ✓
+- INTEL-10: Orchestrator passes file paths, not file contents — BLOCKED (needs 05-03, 05-04)
+- INTEL-11: Indexing phase delegated to subagent (gap closure)
**Success Criteria:**
-1. Entity generation works via subagent spawn
-2. Orchestrator context preserved (no file contents loaded)
-3. Entities correctly formatted and graph.db updated
-4. Works on 500+ file codebases without context exhaustion
+1. Entity generation works via subagent spawn ✓
+2. Indexing works via subagent spawn (gap closure)
+3. Orchestrator context preserved (no file contents loaded in orchestrator)
+4. Entities correctly formatted and graph.db updated ✓
+5. Works on 500+ file codebases without context exhaustion
---
@@ -111,10 +125,11 @@ Plans:
| INTEL-05 | Phase 4 | ✓ Complete (04-04) |
| INTEL-06 | Phase 4 | ✓ Complete (04-03) |
| INTEL-07 | Phase 4 | ✓ Complete (04-02) |
-| INTEL-08 | Phase 5 | Planned (05-01, 05-02) |
-| INTEL-09 | Phase 5 | Planned (05-01) |
-| INTEL-10 | Phase 5 | Planned (05-02) |
+| INTEL-08 | Phase 5 | ✓ Complete (05-01, 05-02) |
+| INTEL-09 | Phase 5 | ✓ Complete (05-01) |
+| INTEL-10 | Phase 5 | Gap closure (05-03, 05-04) |
+| INTEL-11 | Phase 5 | Gap closure (05-03, 05-04) |
---
*Created: 2026-01-19*
-*Updated: 2026-01-20 — Phase 5 planned with 2 plans in 2 waves*
+*Updated: 2026-01-20 — Phase 5 gap closure plans added (05-03, 05-04)*
diff --git a/.planning/phases/05-subagent-codebase-analysis/05-03-PLAN.md b/.planning/phases/05-subagent-codebase-analysis/05-03-PLAN.md
new file mode 100644
index 000000000..be46579bb
--- /dev/null
+++ b/.planning/phases/05-subagent-codebase-analysis/05-03-PLAN.md
@@ -0,0 +1,192 @@
+---
+phase: 05-subagent-codebase-analysis
+plan: 03
+type: execute
+wave: 3
+depends_on: []
+files_modified:
+ - agents/gsd-indexer.md
+autonomous: true
+gap_closure: true
+
+must_haves:
+ truths:
+ - "Indexer agent definition exists following gsd-entity-generator pattern"
+ - "Agent reads files and extracts exports/imports using same regex as Step 3"
+ - "Agent writes index.json directly to disk"
+ - "Agent returns statistics only (not file contents)"
+ artifacts:
+ - path: "agents/gsd-indexer.md"
+ provides: "Subagent definition for file indexing"
+ contains: "gsd-indexer"
+ key_links:
+ - from: "agents/gsd-indexer.md"
+ to: ".planning/intel/index.json"
+ via: "Write tool call"
+ pattern: "Write.*index\\.json"
+---
+
+
+Create gsd-indexer subagent definition for Steps 2-3 file indexing.
+
+Purpose: Define the subagent that reads files and extracts exports/imports. This agent is spawned by `/gsd:analyze-codebase` with a list of file paths (from Glob), reads each file, applies the same regex patterns as current Step 3, and writes the complete index.json to disk. Returns statistics only to preserve orchestrator context.
+
+Output: `agents/gsd-indexer.md`
+
+
+
+@~/.claude/get-shit-done/workflows/execute-plan.md
+@~/.claude/get-shit-done/templates/summary.md
+
+
+
+@.planning/PROJECT.md
+@.planning/ROADMAP.md
+@.planning/STATE.md
+@.planning/phases/05-subagent-codebase-analysis/05-VERIFICATION.md
+@agents/gsd-entity-generator.md
+@agents/gsd-codebase-mapper.md
+@commands/gsd/analyze-codebase.md
+
+
+
+
+
+ Task 1: Create gsd-indexer agent definition
+ agents/gsd-indexer.md
+
+Create agent definition following gsd-entity-generator.md structure:
+
+**Frontmatter:**
+```yaml
+---
+name: gsd-indexer
+description: Indexes codebase files by extracting exports and imports. Spawned by analyze-codebase with file list. Writes index.json directly to disk.
+tools: Read, Write, Bash
+color: cyan
+---
+```
+
+**Role section:**
+- Spawned by `/gsd:analyze-codebase` with file paths (from Glob results)
+- Reads source files using Read tool
+- Extracts exports and imports using regex patterns
+- Writes complete index.json to `.planning/intel/index.json`
+- Returns statistics only (NOT file contents or index data)
+
+**Why this matters section:**
+- Index.json is consumed by convention detection (Step 4)
+- Entity generation uses index to find hub files (Step 9.2)
+- PostToolUse hook uses index for incremental updates
+- Orchestrator MUST NOT load file contents (context exhaustion on 500+ files)
+
+**Process sections:**
+
+1. `parse_input` - Extract from prompt:
+ - Output path: `.planning/intel/index.json`
+ - List of absolute file paths (one per line)
+ - Initialize counters: files_processed=0, exports_found=0, imports_found=0, errors=0
+
+2. `process_each_file` - For each file path:
+
+ a. Read file content using Read tool
+
+ b. Extract exports using these patterns (EXACTLY as Step 3):
+ - Named exports: `export\s*\{([^}]+)\}`
+ - Declaration exports: `export\s+(?:const|let|var|function\*?|async\s+function|class)\s+(\w+)`
+ - Default exports: `export\s+default\s+(?:function\s*\*?\s*|class\s+)?(\w+)?`
+ - CommonJS object: `module\.exports\s*=\s*\{([^}]+)\}`
+ - CommonJS single: `module\.exports\s*=\s*(\w+)\s*[;\n]`
+ - TypeScript: `export\s+(?:type|interface)\s+(\w+)`
+
+ c. Extract imports using these patterns (EXACTLY as Step 3):
+ - ES6: `import\s+(?:\{[^}]*\}|\*\s+as\s+\w+|\w+)\s+from\s+['"]([^'"]+)['"]`
+ - Side-effect: `import\s+['"]([^'"]+)['"]` (not preceded by 'from')
+ - CommonJS: `require\s*\(\s*['"]([^'"]+)['"]\s*\)`
+
+ d. Store in index structure:
+ ```javascript
+ index.files[absolutePath] = {
+ exports: [], // Array of export names
+ imports: [], // Array of import sources
+ indexed: Date.now()
+ }
+ ```
+
+ e. Track statistics: increment files_processed, add to exports_found/imports_found
+
+ f. Handle errors: if file can't be read, increment errors and continue
+
+3. `write_index` - Write complete index to disk:
+ ```javascript
+ {
+ version: 1,
+ updated: Date.now(),
+ files: { /* all file entries */ }
+ }
+ ```
+ Write to `.planning/intel/index.json` using Write tool.
+
+4. `return_statistics` - Return ONLY:
+ ```
+ ## INDEXING COMPLETE
+
+ **Files processed:** {files_processed}
+ **Exports found:** {exports_found}
+ **Imports found:** {imports_found}
+ **Errors:** {errors}
+
+ Index written to: .planning/intel/index.json
+ ```
+
+**Critical rules section:**
+- WRITE index.json directly (never return index contents)
+- Use EXACT regex patterns from Step 3 (patterns are validated)
+- Handle read errors gracefully (log path, continue)
+- Return only statistics (~10 lines)
+- DO NOT commit (orchestrator handles git)
+- File paths in index must be ABSOLUTE paths (key for O(1) lookup)
+
+**Success criteria checklist:**
+- All file paths processed
+- index.json written with version, updated, files
+- Each file entry has exports, imports, indexed timestamp
+- Absolute paths as keys (not relative)
+- Statistics returned (not index contents)
+
+
+File exists and contains:
+- Frontmatter with name: gsd-indexer, tools: Read/Write/Bash
+- Role section explaining spawn context from analyze-codebase
+- Why this matters section explaining index consumers
+- Process steps: parse_input, process_each_file, write_index, return_statistics
+- EXACT regex patterns matching Step 3 of analyze-codebase
+- Critical rules section (write directly, return stats only)
+- Success criteria checklist
+
+
+`agents/gsd-indexer.md` exists with complete agent definition. Agent uses same regex patterns as current Step 3. Ready to be spawned by analyze-codebase.
+
+
+
+
+
+
+- [ ] File exists at `agents/gsd-indexer.md`
+- [ ] Frontmatter valid YAML (name, description, tools, color)
+- [ ] Role section explains subagent purpose (spawned by analyze-codebase)
+- [ ] Process has 4 steps: parse, process, write, return
+- [ ] Export regex patterns match Step 3 exactly (6 patterns)
+- [ ] Import regex patterns match Step 3 exactly (3 patterns)
+- [ ] Index schema matches Step 5 format (version, updated, files)
+- [ ] Critical rules section matches gsd-entity-generator style
+- [ ] Returns statistics only (not index contents)
+
+
+
+gsd-indexer agent definition complete. Agent can be spawned with file paths and will read files, extract exports/imports using validated regex patterns, and write index.json directly to disk.
+
+
+
diff --git a/.planning/phases/05-subagent-codebase-analysis/05-04-PLAN.md b/.planning/phases/05-subagent-codebase-analysis/05-04-PLAN.md
new file mode 100644
index 000000000..fcdb0daf4
--- /dev/null
+++ b/.planning/phases/05-subagent-codebase-analysis/05-04-PLAN.md
@@ -0,0 +1,272 @@
+---
+phase: 05-subagent-codebase-analysis
+plan: 04
+type: execute
+wave: 4
+depends_on: ["05-03"]
+files_modified:
+ - commands/gsd/analyze-codebase.md
+autonomous: false
+gap_closure: true
+
+must_haves:
+ truths:
+ - "Orchestrator never reads file contents during Steps 2-3"
+ - "Indexer subagent is spawned with file paths from Glob"
+ - "Subagent writes index.json, orchestrator receives statistics only"
+ - "User can run /gsd:analyze-codebase on 500+ file codebases without context exhaustion"
+ artifacts:
+ - path: "commands/gsd/analyze-codebase.md"
+ provides: "Refactored command with subagent delegation for indexing"
+ contains: "gsd-indexer"
+ key_links:
+ - from: "commands/gsd/analyze-codebase.md"
+ to: "agents/gsd-indexer.md"
+ via: "Task tool spawn"
+ pattern: "Task.*gsd-indexer"
+ - from: "Step 2 Glob"
+ to: "Step 3 subagent spawn"
+ via: "file paths array"
+ pattern: "Glob.*file_paths"
+---
+
+
+Refactor analyze-codebase Steps 2-3 to spawn indexer subagent.
+
+Purpose: Replace the current inline file reading (Step 3: "Read file content using Read tool") with a single subagent spawn. The orchestrator runs Glob to find files (Step 2), spawns `gsd-indexer` with the file list, and receives index.json back. This prevents context exhaustion on large codebases where 250+ file reads were causing the orchestrator to die before reaching Step 9.
+
+Output: Updated `commands/gsd/analyze-codebase.md`
+
+
+
+@~/.claude/get-shit-done/workflows/execute-plan.md
+@~/.claude/get-shit-done/templates/summary.md
+
+
+
+@.planning/PROJECT.md
+@.planning/ROADMAP.md
+@.planning/STATE.md
+@.planning/phases/05-subagent-codebase-analysis/05-VERIFICATION.md
+@.planning/phases/05-subagent-codebase-analysis/05-03-SUMMARY.md
+@commands/gsd/analyze-codebase.md
+@agents/gsd-indexer.md
+
+
+
+
+
+ Task 1: Refactor Steps 2-3 to use indexer subagent
+ commands/gsd/analyze-codebase.md
+
+Modify Steps 2 and 3 of analyze-codebase.md. Step 2 stays mostly the same (Glob). Step 3 is completely replaced with subagent spawn.
+
+**Update Step 2: Find all indexable files**
+
+Keep the Glob pattern and exclusion list, but change the output description:
+
+```markdown
+## Step 2: Find all indexable files
+
+Use Glob tool with pattern: `**/*.{js,ts,jsx,tsx,mjs,cjs}`
+
+Exclude directories (skip any path containing):
+- node_modules
+- dist
+- build
+- .git
+- vendor
+- coverage
+- .next
+- __pycache__
+
+Filter results to remove excluded paths. Store as `file_paths` array.
+
+**Output:** List of absolute file paths for indexing. Do NOT read file contents.
+```
+
+**Replace Step 3: Process each file**
+
+Remove the entire current Step 3 (lines ~67-100) which contains:
+- "Read file content using Read tool"
+- Export regex patterns inline
+- Import regex patterns inline
+- Store in index structure
+
+Replace with:
+
+```markdown
+## Step 3: Spawn indexer subagent
+
+Spawn `gsd-indexer` subagent with the file paths from Step 2.
+
+**Why subagent delegation:**
+- Orchestrator would exhaust context reading 500+ files inline
+- Subagent gets fresh 200k context for file reading
+- Orchestrator only handles file paths (small)
+- Subagent writes index.json directly (large)
+
+**Task tool invocation:**
+
+```python
+file_list = "\n".join(file_paths) # From Step 2 Glob results
+
+Task(
+ prompt=f"""Index codebase files by extracting exports and imports.
+
+You are a GSD indexer. Read source files and extract exports/imports using regex patterns.
+
+**Parameters:**
+- Files to process: {len(file_paths)}
+- Output path: .planning/intel/index.json
+
+**Export patterns:**
+- Named: export\\s*\\{{([^}}]+)\\}}
+- Declaration: export\\s+(?:const|let|var|function\\*?|async\\s+function|class)\\s+(\\w+)
+- Default: export\\s+default\\s+(?:function\\s*\\*?\\s*|class\\s+)?(\\w+)?
+- CommonJS object: module\\.exports\\s*=\\s*\\{{([^}}]+)\\}}
+- CommonJS single: module\\.exports\\s*=\\s*(\\w+)\\s*[;\\n]
+- TypeScript: export\\s+(?:type|interface)\\s+(\\w+)
+
+**Import patterns:**
+- ES6: import\\s+(?:\\{{[^}}]*\\}}|\\*\\s+as\\s+\\w+|\\w+)\\s+from\\s+['\"]([^'\"]+)['\"]
+- Side-effect: import\\s+['\"]([^'\"]+)['\"]
+- CommonJS: require\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)
+
+**Index schema:**
+```json
+{{
+ "version": 1,
+ "updated": {timestamp},
+ "files": {{
+ "/absolute/path/file.js": {{
+ "exports": ["name1", "name2"],
+ "imports": ["source1", "source2"],
+ "indexed": {timestamp}
+ }}
+ }}
+}}
+```
+
+**Process:**
+For each file path below:
+1. Read file content using Read tool
+2. Apply export regex patterns, collect export names
+3. Apply import regex patterns, collect import sources
+4. Store in index structure with absolute path as key
+
+**Files:**
+{file_list}
+
+**Return format:**
+When complete, return ONLY statistics:
+
+## INDEXING COMPLETE
+
+**Files processed:** {{N}}
+**Exports found:** {{M}}
+**Imports found:** {{K}}
+**Errors:** {{E}}
+
+Index written to: .planning/intel/index.json
+
+Do NOT return index contents.
+""",
+ subagent_type="gsd-indexer"
+)
+```
+
+**Wait for completion:** Task() blocks until subagent finishes.
+
+**Verify index created:**
+```bash
+ls -la .planning/intel/index.json
+```
+```
+
+**Update context section** (around lines 21-38):
+
+Add to the context section, before the existing "Execution model (Step 9)" section:
+
+```markdown
+**Execution model (Steps 2-3 - Indexing):**
+- Orchestrator finds file paths via Glob (Step 2)
+- Spawns `gsd-indexer` subagent with file paths only (Step 3)
+- Subagent reads files in fresh 200k context, applies regex patterns
+- Subagent writes index.json directly to disk
+- Subagent returns statistics only (not file contents or index data)
+- This prevents context exhaustion on large codebases (500+ files)
+```
+
+**Remove inline regex documentation:**
+
+The regex patterns are now documented in the subagent prompt. Remove any duplicate documentation that described inline processing. The command should make clear that file reading is DELEGATED, not performed inline.
+
+**Verify Step 4 still works:**
+
+Step 4 "Detect conventions" reads from index.json that the subagent wrote. This should work unchanged since the index format is the same.
+
+
+Read updated commands/gsd/analyze-codebase.md and confirm:
+- Step 2 mentions storing as "file_paths" array, NOT reading contents
+- Step 3 spawns gsd-indexer via Task tool
+- No "Read file content" instruction in orchestrator steps
+- Context section documents subagent delegation for Steps 2-3
+- Step 4+ remain unchanged (read index.json from disk)
+- Regex patterns appear in subagent prompt (not inline)
+
+
+analyze-codebase.md Steps 2-3 refactored. Orchestrator only Globs for paths, then spawns indexer subagent. File reading is fully delegated to subagent with fresh context.
+
+
+
+
+ Subagent delegation for indexing in /gsd:analyze-codebase (Steps 2-3)
+
+1. Navigate to a LARGE test project (100+ files, ideally 250+)
+2. Delete existing intel if any: `rm -rf .planning/intel`
+3. Run `/gsd:analyze-codebase`
+4. Observe execution:
+ - Step 1: Creates directory
+ - Step 2: Runs Glob, collects file paths (does NOT read files)
+ - Step 3: Spawns gsd-indexer subagent with file list
+ - Subagent reads files (should see many Read tool calls in subagent output)
+ - Subagent writes index.json directly
+ - Subagent returns statistics only
+ - Step 4+: Orchestrator reads index.json, continues with conventions
+ - Step 9: Spawns gsd-entity-generator (existing flow)
+5. Verify:
+ - Orchestrator context NOT exhausted (no early death)
+ - `.planning/intel/index.json` exists with file entries
+ - `.planning/intel/conventions.json` has detected patterns
+ - `.planning/intel/summary.md` exists
+ - Entity generation works (if Step 9 executed)
+6. Compare orchestrator context usage before/after refactor
+ - Before: Orchestrator read all files -> context exhaustion at ~250 files
+ - After: Orchestrator only handles paths -> survives 500+ files
+
+ Type "approved" if /gsd:analyze-codebase completes on large codebase without context exhaustion, or describe issues
+
+
+
+
+
+- [ ] Step 2 outputs file_paths array (no file reading)
+- [ ] Step 3 spawns gsd-indexer subagent
+- [ ] Subagent prompt includes all 6 export patterns
+- [ ] Subagent prompt includes all 3 import patterns
+- [ ] Context section documents indexing subagent delegation
+- [ ] No "Read file content" in orchestrator steps
+- [ ] Step 4+ reads index.json from disk (unchanged)
+- [ ] Command runs successfully on 250+ file codebase
+- [ ] Orchestrator context preserved (no early death)
+- [ ] User verification checkpoint passed
+
+
+
+analyze-codebase refactored with full subagent delegation. Both indexing (Steps 2-3) and entity generation (Step 9) now use subagents. Command works on 500+ file codebases without context exhaustion.
+
+
+