High-Performance AST Code Graph & Context Optimization Engine for Large Language Models
SynapseCode reduces context token consumption by 75% to 90% when interacting with LLMs such as Claude 3.5 Sonnet, GPT-4, and autonomous coding agents via the Model Context Protocol (MCP).
When using AI code assistants, injecting full raw source files or dumping repository trees consumes tens to hundreds of thousands of tokens per prompt.
This creates three critical engineering bottlenecks:
- Financial Cost: High token consumption multiplies API usage bills.
- Latency: Time-to-first-token (TTFT) degrades significantly with large prompt payloads.
- Context Degradation: Unnecessary implementation details dilute the attention of the model, increasing hallucination rates (Lost in the Middle phenomenon).
SynapseCode continuously analyzes your codebase into an in-memory directed dependency graph:
- AST Extraction: Extracts symbol declarations, types, interfaces, and signatures without full function bodies.
- Multi-Edge Dependency Graph: Maps relations including
CALLS,IMPORTS,DEFINES,IMPLEMENTS, andEXTENDS. - Personalized PageRank (PPR): Calculates centrality and relevance scores seeded by user task terms.
- Adaptive Knapsack Token Budgeting: Selects target implementations and direct 1-hop dependency skeletons under a strict token budget (e.g., 3,500 tokens).
- Zero-Dependency Persistent Cache: Caches parsed file metadata on disk (
.synapse/cache.json) for sub-30ms incremental startup. - Live File Watcher (
fsnotify): Continuously syncs the code graph in the background without restarting the server. - Model Context Protocol (MCP): Exposes 6 standardized JSON-RPC 2.0 tools over
stdioto Claude Desktop, Cursor, and IDE extensions.
Evaluation performed on a 120,000-token repository refactoring task:
| Metric | Raw File Injection | SynapseCode (MCP) | Improvement |
|---|---|---|---|
| Prompt Size | 124,000 tokens | 4,200 tokens | -96.6% |
| API Cost (Claude 3.5 Sonnet) | $0.372 / request | $0.012 / request | 31x reduction |
| Time to First Token (TTFT) | 9.4 seconds | 1.3 seconds | 7.2x faster |
| Context Coherence | Low (Noise) | High (Targeted) | Deterministic |
- Go (
.go) - TypeScript & JavaScript (
.ts,.tsx,.js,.jsx,.mjs,.cjs) — Full ES6+, arrow functions, class methods, enums, interfaces. - Python (
.py) — Async defs, decorators (@dataclass,@property,@classmethod), multiple inheritance. - Rust (
.rs) — Structs, traits, andimplblocks. - Java (
.java) — Spring Boot annotations (@RestController,@Service,@Autowired,@GetMapping), Java records, enums, interfaces. - PHP (
.php,.phtml) — Laravel controllers, Eloquent models, PHP 8+ attributes (#[Route]), traits, enums. - C# (
.cs) — ASP.NET Core controllers ([ApiController],[Route],[HttpGet]), records, enums, interfaces, async tasks. - C & C++ (
.c,.cpp,.cc,.cxx,.h,.hpp) — Headers, namespaces, classes with multiple inheritance, templates, structs, enum classes. - Pluggable architecture allowing seamless community contributions for additional languages.
go install github.com/nosleepman1/SynapseCode/cmd/synapse@latestDownload the latest pre-compiled archive for Linux, macOS, or Windows from the Releases page.
Add the following configuration to your claude_desktop_config.json:
{
"mcpServers": {
"synapse-code": {
"command": "synapse",
"args": ["mcp", "--path", "/path/to/your/repository", "--watch"]
}
}
}Restart Claude Desktop. SynapseCode provides full Model Context Protocol support:
get_repo_map: Generates an architectural overview with language and symbol category distributions.get_context_for_task: Retrieves full target implementations and direct 1-hop skeletons under a strict token budget.get_symbol_callers: Inspects all callers and dependents of a given symbol across the codebase to prevent regressions.get_symbol_definition: Retrieves the full definition, signature, location, documentation, and body of any symbol.get_impact_analysis: Calculates the blast radius of modifying a symbol (direct callers, transitive dependents, affected files, impacted test suites, risk severityLOWtoCRITICAL).get_file_outline: Returns a structured outline of all symbols defined in a file with line numbers and signatures.
synapse://graph/summary: High-level codebase metrics (total files, symbols, dependency edges).synapse://graph/languages: Symbol counts broken down across all supported languages.synapse://graph/symbols: Master index of all exported functions, classes, and interfaces.synapse://graph/file/{path}: Formats a structured outline of all symbols in a file.synapse://graph/symbol/{name}: Full definition, signature, docstring, and incoming callers of a symbol.
refactor_safe: Step-by-step refactoring instruction with blast radius, callers, and dependency contracts.generate_unit_tests: Prompts comprehensive unit test suites with mocks for external dependencies.audit_architecture: Architectural coupling and dependency health check.explain_symbol: Architectural role, upstream dependents, and downstream contracts of any symbol.
# Scan and persist codebase graph index to .synapse/cache.json
synapse index --path /path/to/repo
# Force re-indexing all files, bypassing existing cache
synapse index --force
# Search codebase symbols with Okapi BM25 and Reciprocal Rank Fusion (RRF)
synapse query "jwt token validation" --path /path/to/repo
# Generate an architectural map under 2000 tokens
synapse map --path /path/to/repo
# Extract targeted context for a specific task
synapse context "fix token verification in jwt service" --budget 3500
# Start MCP server on standard I/O with live filesystem watching
synapse mcp --path /path/to/repo --watchSource Repository
|
v
File Discovery (Scanner + Ignore Rules)
|
v
AST Parsing (Go, TS/JS, Python, Rust)
|
v
In-Memory Dependency Graph (Nodes & Edges)
|
+-------------------------------+
| |
v v
BM25 Lexical Index Personalized PageRank
| |
+---------------+---------------+
|
v
Knapsack Token Budget Selector
|
v
Structured Context Pack
|
v
Model Context Protocol
|
v
AI Coding Assistant
Detailed technical specifications are available in ARCHITECTURE.md and PROJECT_SPEC.md.
Contributions are welcome. Please consult CONTRIBUTING.md and CODE_OF_CONDUCT.md for development environment setup and guidelines.
SynapseCode is licensed under the MIT License.
