See exactly what context each LLM call consumed - local-first context lineage for LLM apps.
Project description
ctxlineage
See exactly what context each LLM call consumed — and how it flowed into the next.
Two lines of code turn your app's LLM calls into a single static HTML report: the anatomy of every context window, and the lineage of every context element. No server, no database, no account. Your prompts never leave your machine.
Not another trace viewer: ctxlineage makes your runtime context an engineered artifact — decomposed, provenance-tracked, and (v0.2) testable in CI.
Quickstart
pip install ctxlineage
import ctxlineage
ctxlineage.init() # auto-instruments the openai and anthropic SDKs
# ... run your app: every LLM call is recorded to .ctxlineage/events.jsonl
ctxlineage report --open # one self-contained HTML file
That's the whole integration. Streaming, async, tool calls — captured.
Add .ctxlineage/ to your .gitignore.
What you get
| View | Question it answers |
|---|---|
| Overview | Which calls are heaviest? How close to the window limit? Did my tags match? |
| Calls | What actually filled this call's context window — and at what token cost? |
| Chain | How did each output become the next call's input? Where do agent loops accumulate context? |
| Graph | Where did each context element come from (vector DB, prompt file, memory) and which downstream calls did it influence? |
Think dbt docs generate, for your context windows: calls are functions,
context elements are typed inputs with provenance, outputs flow into
downstream inputs.
Tagging (optional, unlocks lineage)
Everything above works with zero tagging. Label your context assembly and the report upgrades from role-based heuristics to real, provenance-carrying segments:
with ctxlineage.span("answer_user_query") as span:
span.tag("rag_chunks", docs, source="qdrant:products_v2", transform="top_k(8)")
span.tag("memory", user_profile, source="memory:user_prefs")
resp = client.chat.completions.create(...)
Tagged content is matched back into the actual prompts (exact → partial → honestly-untagged, with the match rate displayed — never fabricated).
Principles
- Local-first, zero-server. The artifact is one HTML file that opens offline. Capture is an append-only local JSONL. Nothing is ever transmitted.
- Non-intrusive by default.
init()and you're done; tags are progressive enhancement. The capture layer never breaks your app — failures degrade to warnings, not exceptions. - Honest data. Real
usagecounts preferred over estimates, estimates labeled, unmatched tags shown as unmatched, inference caps disclosed.
Scope & limits
Designed as a per-run, dev-time artifact. Comfortable up to ~5,000 calls
(~15 MB report); usable to ~20,000 calls (~65 MB). Reports contain full prompt
text — treat them like logs with sensitive data (see SECURITY.md).
Before sharing, mask secrets with ctxlineage report --redact "sk-[A-Za-z0-9]+"
(repeatable regex; the report discloses what was redacted), or keep them out of
the log entirely with ctxlineage.init(redact_fields=["request.messages.content"]).
Status
v0.1.0 — first public release: the capture layer (openai + anthropic), the
four-view report, the span/tag lineage pipeline, the read-only MCP server, and
runnable examples are all in. Where it's going: context you can test in CI
(v0.2) and importing coding-agent sessions (claude -p / Claude Code) into the
same report. See the issues.
Contributing
See CONTRIBUTING.md — DCO sign-off, hermetic tests, deliberately small maintenance surface (off-roadmap issues may be closed).
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 ctxlineage-0.1.0.tar.gz.
File metadata
- Download URL: ctxlineage-0.1.0.tar.gz
- Upload date:
- Size: 902.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79d9d13e1bb75c9baceacc20351bd27cb8ab8375c0e473886223d1f4f862f5ab
|
|
| MD5 |
a1da1e96536b2ca08ac438ece8fdd7f8
|
|
| BLAKE2b-256 |
5c8a946d5ebcfbb188b6d10ed61876a6e163e01c6f4dd77cf580b40eef46fbfe
|
Provenance
The following attestation bundles were made for ctxlineage-0.1.0.tar.gz:
Publisher:
release.yml on ctxlineage/ctxlineage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ctxlineage-0.1.0.tar.gz -
Subject digest:
79d9d13e1bb75c9baceacc20351bd27cb8ab8375c0e473886223d1f4f862f5ab - Sigstore transparency entry: 2189066167
- Sigstore integration time:
-
Permalink:
ctxlineage/ctxlineage@0bc644b6a6f6ae6a4ada33536e4a2e9051c8ed60 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ctxlineage
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0bc644b6a6f6ae6a4ada33536e4a2e9051c8ed60 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ctxlineage-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ctxlineage-0.1.0-py3-none-any.whl
- Upload date:
- Size: 51.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 |
dec375f8cb30680df15a1a846dd0eec7238096cee5de0cc29c4a41140d2d4d38
|
|
| MD5 |
5cf602c9ec6046982053cddbb0bc5052
|
|
| BLAKE2b-256 |
128d2c3c689e73b2f2771e915dd22ec4865851568f2cdc62edb97626e5f488ef
|
Provenance
The following attestation bundles were made for ctxlineage-0.1.0-py3-none-any.whl:
Publisher:
release.yml on ctxlineage/ctxlineage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ctxlineage-0.1.0-py3-none-any.whl -
Subject digest:
dec375f8cb30680df15a1a846dd0eec7238096cee5de0cc29c4a41140d2d4d38 - Sigstore transparency entry: 2189066251
- Sigstore integration time:
-
Permalink:
ctxlineage/ctxlineage@0bc644b6a6f6ae6a4ada33536e4a2e9051c8ed60 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ctxlineage
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0bc644b6a6f6ae6a4ada33536e4a2e9051c8ed60 -
Trigger Event:
push
-
Statement type: