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

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

This acts exactly like Claude Code, but silently routes traffic through the local ContextMesh proxy to measure cache hits and real token usage.

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.1.1.tar.gz (42.4 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.1.1-py3-none-any.whl (50.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: claude_contextmesh-0.1.1.tar.gz
  • Upload date:
  • Size: 42.4 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.1.1.tar.gz
Algorithm Hash digest
SHA256 18c358b2465e6b2e2d1ce8f1a43e6c8ebf5e79868a773ac5eac7ab7757059220
MD5 95588aca79fafbd5f8b3ef39e590559d
BLAKE2b-256 e5e1ef1f2466495a8154ce980f8fc40c21ada13423ef2f31415a0623efebdce5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for claude_contextmesh-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d12d90cb7b18b8605117ab5424e35ebb9e682fd9fdc7b71a53299346ff047fae
MD5 950b2d715cfcca58b2cf18a63afe8118
BLAKE2b-256 26e0795bb5aefe75870d3bf72f9e89fabde60767f29e75b73e495f6532880414

See more details on using hashes here.

Provenance

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

2 files

0.1.2

2 files

This release

0.1.1 This release

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