Skip to content

Commit 521ed7c

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 documentation with CI/CD examples CLAUDE.md Configuration: - Mandate LOADING .repomap.txt at session start (not generating) - .repomap.txt tracked in git for project context - Define proactive usage scenarios (planning, reviews, refactoring) - Specify regeneration triggers (file/class changes, before PRs) - Integrate .repomap.txt into commit workflow - Version bumped to 2.2.0 Files: - repomap.py - Main implementation - requirements.txt - Dependencies (tree-sitter + language grammars) - docs/patterns/repomap.md - Pattern documentation - .repomap.txt - Generated repository map (tracked in git) - .gitignore - Added repomap patterns - CLAUDE.md - Updated with repomap workflow Terminology: - Replaced all "codemap" references with "repomap" throughout codebase Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 5b60ba1 commit 521ed7c

File tree

7 files changed

+852
-7
lines changed

7 files changed

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

104177
For linting documentation code examples:
@@ -338,6 +411,9 @@ cd reference
338411
# Install doc tooling
339412
uv pip install -r requirements-dev.txt
340413

414+
# Load repomap (session start)
415+
cat .repomap.txt
416+
341417
# Lint documentation
342418
markdownlint docs/**/*.md --fix
343419

@@ -351,18 +427,24 @@ markdownlint docs/**/*.md --fix
351427
# 1. Create feature branch
352428
git checkout -b docs/topic-name
353429

354-
# 2. Edit documentation
430+
# 2. Review repomap
431+
cat .repomap.txt
432+
433+
# 3. Edit documentation
355434
# ... make changes ...
356435

357-
# 3. Validate
436+
# 4. Validate
358437
markdownlint docs/**/*.md --fix
359438
./scripts/validate-mermaid.sh
360439

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

365-
# 5. Push and create PR
447+
# 7. Push and create PR
366448
git push -u origin docs/topic-name
367449
gh pr create --title "docs: Add X" --body "Documentation for X pattern"
368450
```

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)