LLM proxy that analyses token usage in context windows
Project description
ContextSpy is a local proxy that sits between your coding agent and the LLM API, recording every request and breaking down exactly how your context window is being used.
Modern AI coding agents (GitHub Copilot, Claude Code, opencode, Cursor) pack a lot into each LLM request: system prompts, tool definitions, tool results, file contents, conversation history. It's often unclear why a session is slow, expensive, or hitting the context limit. ContextSpy makes the invisible visible — you see a live breakdown of every token category for every request, across sessions, over time.
Features
- Two proxy modes — forward proxy for cloud APIs (OpenAI, Anthropic, Copilot), reverse proxy for local LLM servers (Ollama, llama.cpp, vLLM)
- Context breakdown — input tokens split into 8 categories: system prompt, tool definitions, tool results, file contents, conversation history, current user message, assistant prefill, uncategorised
- Live dashboard — real-time charts and per-request detail with a visual block map of the context window
- Session tracking — name and group requests by task to compare usage across runs
- SQLite storage — all data stored locally in
~/.contextspy/; no data leaves your machine - Agent detection — Copilot, Claude Desktop/Code, opencode, Cursor, and generic clients
Quick start
# Install
pip install contextspy
# or: uv tool install contextspy
# or: brew install rimantas/contextspy/contextspy
# Install the CA certificate (cloud mode only, one-time)
contextspy start --no-browser # generates cert, then Ctrl+C
contextspy install-cert
# Start
contextspy start
Then configure your agent to route through http://127.0.0.1:8888 and open
http://127.0.0.1:5173 in your browser.
Documentation
- Installation — PyPI, Homebrew, .deb, binary, CA certificate setup
- Cloud API mode — intercept OpenAI, Anthropic, Copilot, etc.
- Local LLM mode — intercept Ollama, llama-server, vLLM
- Usage examples — practical recipes and common workflows
- CLI reference — all commands and options
- Development — architecture, data storage, contributing
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file contextspy-0.1.6.tar.gz.
File metadata
- Download URL: contextspy-0.1.6.tar.gz
- Upload date:
- Size: 785.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
820526d465a8f06378572397ede6bbf444c41941c4cc9a27dbece0b848301b62
|
|
| MD5 |
68e4e41dbfe47b176511fe5d16152160
|
|
| BLAKE2b-256 |
4679bbc93dc24e1c77acc4c411130d74e8d70e09782009f388033479d5ece9d3
|
Provenance
The following attestation bundles were made for contextspy-0.1.6.tar.gz:
Publisher:
publish.yml on RimantasZ/contextspy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contextspy-0.1.6.tar.gz -
Subject digest:
820526d465a8f06378572397ede6bbf444c41941c4cc9a27dbece0b848301b62 - Sigstore transparency entry: 1706685444
- Sigstore integration time:
-
Permalink:
RimantasZ/contextspy@50a5cd27591f9366836bab9faa16845b16b1e5bc -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/RimantasZ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@50a5cd27591f9366836bab9faa16845b16b1e5bc -
Trigger Event:
push
-
Statement type:
File details
Details for the file contextspy-0.1.6-py3-none-any.whl.
File metadata
- Download URL: contextspy-0.1.6-py3-none-any.whl
- Upload date:
- Size: 793.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28071b69b7038f44142155973a2715a0b2845edb45cd41c1729b684d5e1c0f73
|
|
| MD5 |
6ca74574daf942edeadeec3a2d9eaf9d
|
|
| BLAKE2b-256 |
d4bfe65417e693bb1f2bc3e78a5af20e3d515607824236bafa98063ab715f148
|
Provenance
The following attestation bundles were made for contextspy-0.1.6-py3-none-any.whl:
Publisher:
publish.yml on RimantasZ/contextspy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contextspy-0.1.6-py3-none-any.whl -
Subject digest:
28071b69b7038f44142155973a2715a0b2845edb45cd41c1729b684d5e1c0f73 - Sigstore transparency entry: 1706685450
- Sigstore integration time:
-
Permalink:
RimantasZ/contextspy@50a5cd27591f9366836bab9faa16845b16b1e5bc -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/RimantasZ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@50a5cd27591f9366836bab9faa16845b16b1e5bc -
Trigger Event:
push
-
Statement type: