Code Mapping for AI-Assisted Development

By Oskar 🕊️ (@austegard.com)
Published:

Code Mapping for AI-Assisted Development

The Problem

When working with unfamiliar codebases, Claude needs context about code structure before making changes. Reading every file wastes tokens and time. Asking Claude to "explore the codebase" produces inconsistent results and burns through context windows.

The Solution

The mapping-codebases skill generates static _MAP.md files that provide hierarchical code structure without requiring file reads. Each map shows:

Maps use AST parsing (tree-sitter) to extract structural information deterministically. No LLM calls, no hallucination, just facts.

How It Works

uv pip install tree-sitter==0.21.3 tree-sitter-languages==1.10.2

python scripts/codemap.py /path/to/repo

python scripts/codemap.py /path/to/repo --skip locale,migrations,tests

The script walks your directory tree and creates one _MAP.md per directory. Each map links to subdirectory maps, creating a navigable hierarchy.

Example Output

# django/utils/
*Files: 40 | Subdirectories: 1*

## Subdirectories
- [translation/](./translation/_MAP.md)

## Files
- **cache.py** — exports (10): `patch_cache_control, get_max_age`... — imports (11): `time, collections, hashlib`...
- **crypto.py** — exports: `InvalidAlgorithm, salted_hmac, get_random_string, constant_time_compare, pbkdf2` — imports: `hashlib, hmac, secrets, django.conf`
- **timezone.py** — exports (15): `get_fixed_timezone, get_default_timezone_name`... — imports (6): `functools, zoneinfo, contextlib`...

Impact on Development

Before mapping:

After mapping:

Real-world example (Django):

You only load maps as you navigate. Even massive codebases stay manageable.

Supported Languages

Python, JavaScript, TypeScript, TSX, Go, Rust, Ruby, Java.

Using Maps with Claude

Add this to your CLAUDE.md or project instructions:

## Codebase Navigation

This repository has `_MAP.md` files in each directory providing structural overviews.

When working with code:
1. Start by reading the root `_MAP.md` to understand top-level structure
2. Navigate to relevant subdirectory maps to find target modules
3. Use export information to identify which files contain needed functionality
4. Read actual source files only after identifying targets via maps

Maps show:
- Directory statistics (file/subdirectory counts)
- Subdirectories with links to their maps
- Files with exports and imports
- Truncation counts (e.g., "exports (23)" when showing subset)

Always check maps before exploring directories or reading files.

Maintenance

Maps are static snapshots. Regenerate after structural changes:

python scripts/codemap.py /path/to/repo

Or add a git hook to keep maps fresh automatically:

# .git/hooks/pre-commit
#!/bin/sh
python /path/to/codemap.py . >/dev/null
git add '*/_MAP.md'

Performance

Map generation is fast and cheap:

Generated maps are cached on disk. Regenerate only after structural changes.

Key Features

Hierarchical disclosure: Navigate progressively without loading everything at once.

Skip patterns: Exclude directories that add noise (locale with 100+ language subdirs, migrations, test snapshots).

Export/import counts: Quickly assess module complexity. "exports (23)" signals a large API surface, "exports: 2" signals a simple utility.

Statistics: File and subdirectory counts help assess scope at a glance.

When to Use

Works for any size - small projects get instant overview, large codebases (500+ files) stay navigable through hierarchical maps.

Limitations

For semantic understanding, read the actual source files. Maps tell you where to look.

Installation

The skill includes:

Download and add to your Skills directory, or run the script standalone.