Skip to main content

ContextMesh — Intelligent Context Layer for Claude Code

One coding session. Infinite memory. 90% fewer tokens.

ContextMesh is a transparent AI proxy + memory engine that sits between Claude Code and the Anthropic API. It automatically compresses token waste, maintains a persistent knowledge graph of your work, and gives Claude perfect memory across sessions — all without changing how you use Claude.

Just run contextmesh init once. Then use claude normally forever.


How it works

Your Terminal
    │
    ▼
┌──────────────────────────────────────────┐
│         ContextMesh Smart Proxy          │  ← Intercepts every request
│  ┌─────────────────────────────────┐     │
│  │  RTK Output Compressor          │     │  ← Crushes terminal noise
│  │  Anti-Context Auto-Flusher      │     │  ← Removes old resolved turns
│  │  Session Resumption Injector    │     │  ← Injects last session memory
│  └─────────────────────────────────┘     │
└──────────────────────────────────────────┘
    │
    ▼
Anthropic API  (only sees clean, compressed, focused context)
    │
    ▼
┌──────────────────────────────────────────┐
│         ContextMesh Daemon               │  ← Background brain
│  ┌───────────────┐  ┌─────────────────┐  │
│  │ Session Graph │  │   AST RepoMap   │  │  ← NetworkX + Tree-sitter
│  │ (your memory) │  │ (code structure)│  │
│  └───────────────┘  └─────────────────┘  │
│  ┌─────────────────────────────────┐     │
│  │  File Watcher (auto-reindex)    │     │  ← Keeps repomap always fresh
│  └─────────────────────────────────┘     │
└──────────────────────────────────────────┘
    │
    ▼ MCP Server
Claude Code ← get_context() | get_project_architecture() | record_decision()

Features

Feature What it does Savings
RTK Output Compressor Intercepts massive grep, npm test, cat outputs and crushes the middle noise Up to 90% on tool outputs
Anti-Context Auto-Flusher Silently drops old resolved tool calls from history when context bloats past 150k chars 30–60% on long sessions
AST Repo-Map Parses your entire codebase with Tree-sitter, gives Claude a dense structural map instead of raw files 95% on code reads
Session Resumption Automatically injects last session summary on startup — no /resume command Saves re-explanation tokens
File Watcher Auto-reindexes changed files in background so the repo map is always fresh Zero manual indexing
God-Mode Dashboard Beautiful live web UI showing tokens saved, cost averted, and compression chart
Universal Auth Works with API keys, Claude Max/Pro subscriptions, AWS Bedrock, and Google Vertex

Installation

# Install globally
pipx install claude-contextmesh

# One-time transparent setup (like RTK/Headroom — no wrapper needed after this!)
cd /path/to/your/project
contextmesh init

contextmesh init does 4 things automatically:

  1. Shell Profile — writes ANTHROPIC_BASE_URL to ~/.zshrc so every claude session routes through the proxy
  2. Claude Code Hooks — installs PreToolUse/PostToolUse hooks in ~/.claude/settings.json
  3. Persistent Service — installs a macOS LaunchAgent (or Linux systemd unit) so the proxy auto-starts on login
  4. MCP Server — connects the ContextMesh brain to Claude Code

Then reload your shell once:

source ~/.zshrc   # or source ~/.bashrc

From now on just use claude normally. ContextMesh intercepts everything transparently.


Commands

Core

contextmesh init          # One-time transparent setup (run once per machine)
contextmesh start         # Start the daemon manually (if not using the service)
contextmesh stop          # Stop the proxy service
contextmesh stop --all    # Stop both proxy AND daemon
contextmesh uninstall     # Remove all ContextMesh integrations cleanly

Stats & Monitoring

contextmesh stats                           # Global token savings report
contextmesh stats --session SESSION_ID      # Per-session breakdown
contextmesh turns --session SESSION_ID      # Per-turn savings table
contextmesh status                          # Check if daemon + proxy are running
contextmesh dashboard                       # Open live web dashboard in browser

Codebase

contextmesh index .                         # Manually index the current project
contextmesh proxy                           # Start the proxy manually (foreground)
contextmesh mcp                             # Run the MCP server (stdio)

Live Dashboard

After running contextmesh start, open your browser to:

http://127.0.0.1:8765/dashboard

You'll see a live, auto-refreshing dark-themed dashboard with:

  • 4 stat cards: Raw tokens sent, Compressed tokens, Total saved (green), USD saved (green)
  • SVG bar chart: Tokens saved per last 10 turns
  • RTK Interception Log: Every compression event with timestamps and savings %

Or use the CLI shortcut:

contextmesh dashboard

Token Savings Report

$ contextmesh stats

╭─ ContextMesh Global Token Savings Report ─╮
│  Sessions tracked                  12    │
│  Turns tracked                    284    │
│  Total baseline tokens        2,847,000  │
│  Total routed tokens            391,000  │
│  Tokens saved                 2,456,000  │
│  Net saved (after overhead)   2,412,000  │
│  Avg compression ratio             14%   │
│  Estimated cost saved           $7.3680  │
╰────────────────────────────────────────────╯

MCP Tools available to Claude

Tool What Claude uses it for
get_context(session_id, task_hint, budget_tokens) Retrieve optimally scored context for the current task
get_project_architecture(project_path) Get AST repo-map (class/function signatures) without reading full files
record_decision(session_id, content, consequence) Permanently store an architectural decision
get_savings_report(session_id) See token savings from inside a session
switch_task(session_id, new_task_name) Explicitly switch task context
get_task_graph(session_id) View task hierarchy and node counts

Architecture

Memory Tiers

HOT   → Current task context (always in every request)
WARM  → Related decisions, nearby graph nodes (retrieved on demand)
COLD  → Full historical archive (never auto-injected, always searchable)

Context Scoring

Before every get_context() call, every node in the graph is scored:

score =
    semantic_relevance   (local embedding cosine similarity)
  + graph_proximity      (BFS distance — depth 1=1.0, depth 2=0.7, depth 3=0.4)
  + file_overlap         (Jaccard similarity with current task files)
  + recency              (exponential decay from last_active)
  + causal_relevance     (DECISION/BUG/SOLUTION type bonus)
  + unresolved_bonus     (UNRESOLVED_ISSUE always surfaces)

Dual Graph

Session Graph — captures every meaningful event:

  • User prompts, tool results, file reads/writes
  • Decisions, bugs, solutions, errors, test results
  • Typed edges: caused_by, solved_by, depends_on, same_task

Repo Graph — deterministic code relationships (Tree-sitter):

  • Functions, classes, methods across .py, .ts, .js, .go, .rs
  • calls, imports, same_file, tested_by, inherits edges
  • Auto-updated by the file watcher on every save

Configuration

~/.contextmesh/config.toml (global) or .contextmesh/config.toml (per project):

[router]
default_budget_tokens = 15000

[tracker]
input_price_per_mtok = 3.0        # Claude cached input price (USD per million)
uncached_price_per_mtok = 15.0

[embeddings]
model = "all-MiniLM-L6-v2"        # Local model, no API key needed (~22MB)

[tasks]
topic_shift_threshold = 0.35      # Cosine distance to auto-detect task switch

[proxy]
port = 8099

Supported Claude Auth Modes

ContextMesh auto-detects how you authenticate and behaves accordingly:

Mode Detection Behavior
API Key ANTHROPIC_API_KEY is set Full proxy (compression + cost tracking)
Max/Pro Subscription OAuth login, no API key Full proxy (compression only, no per-token cost)
AWS Bedrock CLAUDE_CODE_USE_BEDROCK=1 Proxy skipped, daemon + MCP active
Google Vertex CLAUDE_CODE_USE_VERTEX=1 Proxy skipped, daemon + MCP active

Development

git clone https://github.com/gajanansr/ContextMesh
cd ContextMesh
pip install -e ".[dev]"

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claude_contextmesh-0.6.1.tar.gz (56.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_contextmesh-0.6.1-py3-none-any.whl (67.0 kB view details)

Uploaded Python 3

File details

Details for the file claude_contextmesh-0.6.1.tar.gz.

File metadata

  • Download URL: claude_contextmesh-0.6.1.tar.gz
  • Upload date:
  • Size: 56.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for claude_contextmesh-0.6.1.tar.gz
Algorithm Hash digest
SHA256 d4d09aedbc1658fbe53f97ba60e74441d636e295abd6420901f1e5ab195737a4
MD5 fdfb1ec5c157b64f6d5283d4c2ff73bd
BLAKE2b-256 54db2dff4f96efb19f2327e3806abf3c8a9e894a83ce5687824663537568c309

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_contextmesh-0.6.1.tar.gz:

Publisher: publish.yml on gajanansr/ContextMesh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file claude_contextmesh-0.6.1-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_contextmesh-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0bfae6c5eeb4e503a255bd198c3a49686abdda05e7c6fad28a9f1a5f4409f601
MD5 982dff817f7eb60fbb900c8c7bf7c89f
BLAKE2b-256 8a41b894dfac5d830af380982e5482958f622032b8842c42cb016c89fb23d879

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_contextmesh-0.6.1-py3-none-any.whl:

Publisher: publish.yml on gajanansr/ContextMesh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.9.6

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.7.0

2 files

This release

0.6.1 This release

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.1

2 files

0.2.0

2 files

0.1.5

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page