Extract compact structural maps from source code to save LLM tokens
Project description
shortcode
Extract compact structural maps from source code — designed to reduce LLM context usage.
When working with an LLM on a large codebase, dumping entire source files into the context is expensive and slow. shortcode generates a .meta file for each source file — a one-line-per-symbol summary that tells the LLM where everything lives without wasting tokens on implementation details.
Workflow:
- Run
shortcode ./srconce to generate.metafiles - Feed the LLM the relevant
.metafiles (tiny) - Ask it to read only the specific functions it needs
- The LLM reads targeted line ranges from the originals
What it looks like
Given auth.py:
class TokenManager:
def __init__(self, secret): ...
def generate(self, user_id): ...
def verify(self, token): ...
shortcode produces auth.py.meta:
[py] src/auth.py
IMPORT flask,jwt,datetime
CLASS TokenManager:4-52
__init__:5-9
generate:11-24
verify:26-38
FN hash_password:54-61
FN check_password:63-70
~15 tokens instead of ~400. The LLM asks to see lines 11-24 when it needs generate.
Supported languages
| Language | Extensions |
|---|---|
| Python | .py |
| JavaScript | .js .mjs .cjs |
| TypeScript | .ts .tsx |
| Java | .java |
| C# | .cs |
| C / C++ | .cpp .cc .cxx .hpp .h |
| Go | .go |
| Rust | .rs |
| Ruby | .rb |
| PHP | .php |
Powered by tree-sitter — real AST parsing, no regex heuristics.
Installation
pip install shortcode
# or
uv add shortcode
No Python? Download the pre-built Windows executable from Releases.
CLI usage
# Scan a folder — writes .meta next to each source file
shortcode ./src
# Write all .meta files to a separate directory
shortcode ./src --output-dir ./meta
# Only process specific extensions
shortcode ./src --ext py ts java
# Top-level only (no subdirectories)
shortcode ./src --no-recursive
Double-clicking the .exe opens an interactive prompt asking for the folder path.
Python API
from shortcode import parse_file
from pathlib import Path
meta = parse_file(Path("src/auth.py"))
print(meta.language) # "py"
print(meta.imports) # ["flask", "jwt", "datetime"]
for cls in meta.classes:
print(cls.name, cls.line_start, cls.line_end)
for method in cls.methods:
print(" ", method.name, method.line_start)
for fn in meta.functions:
print(fn.name, fn.line_start)
Claude Code integration (MCP)
shortcode ships an MCP server so Claude Code (and any MCP-compatible agent) can call it as a tool directly — no manual .meta file management needed.
Install with MCP support
pip install "shortcode[mcp]"
# or
uv add "shortcode[mcp]"
Register in Claude Code
Edit your Claude Code config file:
- macOS/Linux:
~/.claude.json - Windows:
C:\Users\<YourName>\.claude.json
Add the mcpServers block:
{
"mcpServers": {
"shortcode": {
"command": "shortcode-mcp"
}
}
}
Or with uvx — no separate install needed, just requires uv:
{
"mcpServers": {
"shortcode": {
"command": "uvx",
"args": ["--from", "shortcode[mcp]", "shortcode-mcp"]
}
}
}
Restart Claude Code after editing the config. Run /mcp to confirm the server is connected.
Make Claude use it consistently (recommended)
Add a CLAUDE.md file to your project root:
## Code navigation
A shortcode MCP server is available. Before reading any source file, call
`compact_file(path)` to get its structure and line ranges. Then read only
the specific lines you need using offset + limit.
This instructs Claude to use shortcode at the start of every session instead of reading full files.
Available tools
| Tool | Description |
|---|---|
compact_file(path) |
Return the structural map of a source file with exact line ranges |
Example session
You: show me the generate method in src/auth.py
Claude: [calls compact_file("src/auth.py")]
[py] src/auth.py
IMPORT flask,jwt,datetime
CLASS TokenManager:12-87
__init__:13-18
generate:20-35
verify:37-52
[reads src/auth.py lines 20-35]
Other MCP clients: The same
shortcode-mcpserver works with Cursor, Windsurf, and any agent that supports the Model Context Protocol.
Contributing
See CONTRIBUTING.md. Adding support for a new language takes about 10 lines.
License
MIT © Ahmet Bekcan
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shortcode-0.1.1.tar.gz.
File metadata
- Download URL: shortcode-0.1.1.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6218703a4e1cdc6f51ba56828db1ddedd0589f78244e35b46dbdcacf0a115ebd
|
|
| MD5 |
6702cb4e94bb79390323929a16e3ff51
|
|
| BLAKE2b-256 |
9aa9295e0c7e50d2bd7438a9ea403cce5e273a0a73b13d24e8b5300ebe6ec1f8
|
File details
Details for the file shortcode-0.1.1-py3-none-any.whl.
File metadata
- Download URL: shortcode-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b2374eb4348e517cceccc123e7f43e9c5b2b02afc36acef52df1104e65c6cdc
|
|
| MD5 |
5866b2d02382d8ba91c50a391ece822d
|
|
| BLAKE2b-256 |
f35ace9316b42905015e9d2b71eab6834770167dc79f53f1699a5741488cf20e
|