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

(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.1.5.tar.gz (43.1 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.5-py3-none-any.whl (51.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: claude_contextmesh-0.1.5.tar.gz
  • Upload date:
  • Size: 43.1 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.5.tar.gz
Algorithm Hash digest
SHA256 b1ce4914e4e541901d809a90517930d5cdbd79f632a25b762a82867b590cdc8f
MD5 6f88b80bb584bbf26be0997f32f19dda
BLAKE2b-256 ad08eb1754e7b2feed49c2e332ea16a5918d6531e4d13e87a07890caccb187c0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for claude_contextmesh-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d28fd079b29eb8bd20493bb24d4446c8c5b04ae1b4883254e3681c33c3520cfa
MD5 85cc5b75bf1264b4be7c44bb699db6d6
BLAKE2b-256 928934c4af033dcf67a7cd3595739427a9d57a52b3b31a4be73447e99f2d2de3

See more details on using hashes here.

Provenance

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

This release

0.1.5 This release

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