Skip to main content

ContextMesh — Intelligent Context Layer for Claude Code

One coding session. Infinite memory. Minimal active context.

ContextMesh sits between Claude Code and the model. It captures every event in your session, builds a structured knowledge graph of your work, and dynamically provides Claude with only the most relevant context for the current task — saving tokens, reducing cost, and preventing context overload.

How it works

Claude Code Hooks → ContextMesh Daemon → Session Graph + Repo Graph
                                               ↓
                              Context Router (multi-signal scoring)
                                               ↓
                              Claude Code ← MCP Server (get_context)
                                               ↓
                              Token Savings Tracker → Report
  • RTK Output Compressor: Automatically intercepts massive terminal outputs (like npm install or massive grep commands) and intelligently compresses them down before sending them to Anthropic, saving you up to 90% on useless token noise.
  • Live Web Dashboard: Monitor your exact token savings and costs averted in real-time by visiting the local God-Mode dashboard at http://127.0.0.1:8765/dashboard.

The key insight: semantic similarity alone fails for long coding sessions because everything related to the same feature looks similar. ContextMesh uses graph proximity + code dependency relationships + causal edges + recency + file overlap — not just vectors.

Installation

The easiest way to install ContextMesh globally is using pipx.

# 1. Install globally
pipx install claude-contextmesh

# 2. Register as a macOS background service (runs silently on boot)
contextmesh install-mac

Setup a new project

When you start working on a new repository, just run:

cd /path/to/your/project
contextmesh init

This instantly connects Claude Code to the MCP server, indexes your codebase for the repo graph, and configures the hooks.

Using ContextMesh

You have two options for running Claude Code with ContextMesh:

Option A: Standard usage

Just run claude normally. Claude will automatically query ContextMesh for relevant memory and codebase context using the MCP server.

Option B: Token Proxy mode (Recommended for Enterprise)

If you want to measure exact token savings and cost reductions on your Anthropic bill, use our wrapper command instead:

claude-mesh

(You can also run contextmesh proxy manually and set export ANTHROPIC_BASE_URL=http://127.0.0.1:8099 if you prefer not to use the wrapper).

View token savings

# Session summary
contextmesh stats --session YOUR_SESSION_ID

# Recent turns with savings breakdown
contextmesh turns --session YOUR_SESSION_ID --limit 20

# Global summary across all sessions
contextmesh stats

# If using proxy mode — actual API token counts
contextmesh stats --proxy

Token savings tracker

Every time Claude calls get_context(), ContextMesh records:

Metric What it is
Accumulated tokens What the full session history would have been
Routed tokens What ContextMesh actually provided
Tokens saved The difference
Compression ratio routed / accumulated
Cost saved Based on your configured per-MTok price

Architecture

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:

  • Functions, classes, methods, files (Tree-sitter parsed)
  • calls, imports, same_file, tested_by, inherits edges
  • Updated incrementally on every file write

Hot / Warm / Cold Memory

HOT   → Current task context (always injected)
WARM  → Related tasks, decisions, nearby graph nodes (retrieved on demand)
COLD  → Full historical transcripts (never auto-injected)

Context Router

Before every get_context() call:

context_score =
    semantic_relevance   (embedding cosine similarity)
  + graph_proximity      (BFS distance in session graph)
  + file_overlap         (Jaccard similarity with current task files)
  + recency              (exponential decay from now)
  + causal_relevance     (DECISION/BUG/SOLUTION type bonus)
  + unresolved_bonus     (UNRESOLVED_ISSUE always surfaces)

Cache-aware assembly order

STATIC (cacheable)
─────────────────────────────
=== CURRENT TASK ===
[hot nodes — current thread]

=== RELEVANT DECISIONS ===
[top-scored decisions]

DYNAMIC
─────────────────────────────
=== RELATED CODE CONTEXT ===
[repo graph: functions/classes in touched files]

=== RECENT HISTORY ===
[recent warm nodes]

=== UNRESOLVED ISSUES ===
[always surfaced]

Configuration

.contextmesh/config.toml in your project (or ~/.contextmesh/config.toml globally):

[router]
default_budget_tokens = 15000

[tracker]
input_price_per_mtok = 3.0       # Claude Enterprise cached input price
uncached_price_per_mtok = 15.0

[embeddings]
model = "all-MiniLM-L6-v2"       # Local, no API key needed

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

Development

pip install -e ".[dev]"
pytest tests/

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.4.0.tar.gz (49.6 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.4.0-py3-none-any.whl (59.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: claude_contextmesh-0.4.0.tar.gz
  • Upload date:
  • Size: 49.6 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.4.0.tar.gz
Algorithm Hash digest
SHA256 33c7277a5550c3025bdda0aff413a9bbf34677406b883cb7b80ab17e1be6cef7
MD5 c86014f0c244ca6e3ab4b4e839d709cc
BLAKE2b-256 8fbe9ca34bae4ee997b7354e5b5b98721942a8f7761b2bed2bc76fd899d75461

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_contextmesh-0.4.0.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.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_contextmesh-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5bd9b50d6bb60651d74557405eb819dbefdfd004d3eeacc0f4c0f881b892207d
MD5 e26abd1e2260dd1d3faa91e4034efeb6
BLAKE2b-256 3ebafa3933dbe36df3e984415bf2b7386c7e71e3702e577616431172cb8498af

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_contextmesh-0.4.0-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

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

This release

0.4.0 This release

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