Skip to content

Commit ff9fe80

Browse files
jeremyederclaude
andcommitted
Add repomap tool for AI-friendly code structure maps
Implement tree-sitter based repomap tool inspired by Aider's repomap.py. Generates token-optimized code structure maps for AI-assisted development. Implementation: - Single-file repomap.py (~330 lines) - Tree-sitter parsing for Python, TypeScript, JavaScript, Go, Shell - Parallel processing for performance - Respects .gitignore patterns - CLI with --verbose, --max-file-size, --no-parallel options - Comprehensive README with CI/CD examples CLAUDE.md Configuration: - Mandate repomap generation at session start (.repomap.txt) - Define proactive usage scenarios (planning, reviews, refactoring) - Specify regeneration triggers (file/class changes, before PRs) - Integrate .repomap.txt into commit workflow - Track .repomap.txt in git for project context - Version bumped to 2.2.0 Files: - repomap.py - Main implementation - requirements.txt - Dependencies (tree-sitter + language grammars) - README-repomap.md - Usage documentation - .repomap.txt - Generated repository map - .gitignore - Added repomap patterns - CLAUDE.md - Updated with repomap workflow Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 5b60ba1 commit ff9fe80

File tree

7 files changed

+854
-7
lines changed

7 files changed

+854
-7
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,16 @@ yarn-error.log*
7575
*.bak
7676
*.backup
7777
COLORING-BOOK-SCRIPT.md
78+
79+
# Repomap
80+
# Tree-sitter compiled grammars
81+
build/
82+
*.so
83+
*.dylib
84+
*.dll
85+
86+
# Repomap cache files (future use)
87+
.repomap-cache/
88+
89+
# Note: .repomap.txt is tracked in git as part of development workflow
90+
prompts/

.repomap.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
repomap.py
2+
class CodeSymbol
3+
class FileInfo
4+
class RepomapGenerator
5+
def __init__()
6+
def _load_gitignore()
7+
def _should_ignore()
8+
def _is_binary()
9+
def _get_file_extension()
10+
def _discover_files()
11+
def _parse_file()
12+
def _format_output()
13+
def generate()
14+
def main()
15+
scripts/
16+
record-demo.sh
17+
setup.sh
18+
validate-mermaid.sh
19+
def validate_markdown_file()
20+
scripts/autonomous-review/
21+
review-reference.sh
22+
scripts/validation/
23+
autonomous-fix-loop-template.sh
24+
scripts/validation/tests/
25+
run-all.sh
26+
test-autonomous-fix-loop.sh

CLAUDE.md

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Ambient Code Reference Repository - Agent Configuration
22

3-
**Version**: 2.1.0
4-
**Last Updated**: 2026-01-04
3+
**Version**: 2.2.0
4+
**Last Updated**: 2026-01-15
55
**Purpose**: Documentation-only reference for AI-assisted development patterns
66

77
---
@@ -99,6 +99,81 @@ echo $VIRTUAL_ENV # Should show project path
9999
uv pip install -r requirements-dev.txt
100100
```
101101

102+
### Repomap - Context Window Optimization
103+
104+
**MANDATORY: Generate repomap at session start and use proactively throughout development.**
105+
106+
#### Session Start Protocol
107+
108+
**ALWAYS run repomap as the first action** when starting any development session:
109+
110+
```bash
111+
# At session start (after activating venv)
112+
source .venv/bin/activate
113+
python repomap.py . > .repomap.txt
114+
115+
# Review the structure
116+
cat .repomap.txt
117+
```
118+
119+
**Purpose**: Provides token-optimized codebase context for AI-assisted development, reducing context window usage while maintaining code understanding.
120+
121+
#### Proactive Usage Throughout Development
122+
123+
**Use repomap context in these scenarios**:
124+
125+
1. **Planning implementations** - Review repomap before designing features
126+
2. **Understanding dependencies** - Check which files/classes exist before creating new ones
127+
3. **Code reviews** - Reference structure when reviewing changes
128+
4. **Refactoring** - Understand impact scope across codebase
129+
5. **Documentation** - Ensure docs reflect actual code structure
130+
131+
#### When to Regenerate
132+
133+
**Regenerate repomap when**:
134+
135+
- Files are added or removed
136+
- Classes or functions are added/removed
137+
- Major refactoring is completed
138+
- Before creating PRs (ensure map is current)
139+
140+
```bash
141+
# Regenerate after changes
142+
python repomap.py . > .repomap.txt
143+
git add .repomap.txt # Include in commits
144+
```
145+
146+
#### Integration with Development Workflow
147+
148+
**Include repomap in commit tracking**:
149+
150+
```bash
151+
# Pre-commit: Update repomap
152+
python repomap.py . > .repomap.txt
153+
git add .repomap.txt
154+
155+
# Commit message references structure changes
156+
git commit -m "Add UserService class
157+
158+
Updated repomap to reflect new service layer structure"
159+
```
160+
161+
**Use in AI prompts**:
162+
163+
- Reference specific files/classes from repomap by name
164+
- Ask questions about structure (e.g., "Where should I add authentication logic?")
165+
- Validate assumptions (e.g., "Does a Config class already exist?")
166+
167+
#### Repomap Best Practices
168+
169+
- ✅ Generate at session start (always)
170+
- ✅ Regenerate after structural changes
171+
- ✅ Reference in planning and design discussions
172+
- ✅ Include in commit workflow
173+
- ✅ Use to avoid duplicate implementations
174+
- ❌ Don't rely on stale repomaps
175+
- ❌ Don't skip regeneration before PRs
176+
102177
### Code Quality Tools
103178

104179
For linting documentation code examples:
@@ -338,6 +413,9 @@ cd reference
338413
# Install doc tooling
339414
uv pip install -r requirements-dev.txt
340415

416+
# Generate repomap (session start)
417+
python repomap.py . > .repomap.txt
418+
341419
# Lint documentation
342420
markdownlint docs/**/*.md --fix
343421

@@ -351,18 +429,24 @@ markdownlint docs/**/*.md --fix
351429
# 1. Create feature branch
352430
git checkout -b docs/topic-name
353431

354-
# 2. Edit documentation
432+
# 2. Generate/review repomap
433+
python repomap.py . > .repomap.txt
434+
435+
# 3. Edit documentation
355436
# ... make changes ...
356437

357-
# 3. Validate
438+
# 4. Validate
358439
markdownlint docs/**/*.md --fix
359440
./scripts/validate-mermaid.sh
360441

361-
# 4. Commit
362-
git add docs/
442+
# 5. Regenerate repomap if structure changed
443+
python repomap.py . > .repomap.txt
444+
445+
# 6. Commit
446+
git add docs/ .repomap.txt
363447
git commit -m "Add documentation for X"
364448

365-
# 5. Push and create PR
449+
# 7. Push and create PR
366450
git push -u origin docs/topic-name
367451
gh pr create --title "docs: Add X" --body "Documentation for X pattern"
368452
```

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ AI-assisted development patterns. Each pattern is standalone - adopt what you ne
66

77
| Problem | Pattern |
88
|---------|---------|
9+
| AI context windows fill up fast | [Repomap](docs/patterns/repomap.md) |
910
| AI gives inconsistent answers | [Codebase Agent](docs/patterns/codebase-agent.md) |
1011
| AI misses obvious bugs | [Self-Review Reflection](docs/patterns/self-review-reflection.md) |
1112
| PRs take forever to create | [Issue-to-PR Automation](docs/patterns/issue-to-pr.md) |

0 commit comments

Comments
 (0)