Skip to main content

See exactly what context each LLM call consumed - local-first context lineage for LLM apps.

Project description

ctxlineage logo

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.

CI Coverage PyPI Python License

Call anatomy view — what filled the context window, segment by segment

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.

Ten-second tour: Overview, call anatomy, session chain, lineage graph with click-to-trace, dark mode

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 usage counts 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

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ctxlineage-0.1.0.tar.gz (902.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ctxlineage-0.1.0-py3-none-any.whl (51.2 kB view details)

Uploaded Python 3

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

Hashes for ctxlineage-0.1.0.tar.gz
Algorithm Hash digest
SHA256 79d9d13e1bb75c9baceacc20351bd27cb8ab8375c0e473886223d1f4f862f5ab
MD5 a1da1e96536b2ca08ac438ece8fdd7f8
BLAKE2b-256 5c8a946d5ebcfbb188b6d10ed61876a6e163e01c6f4dd77cf580b40eef46fbfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for ctxlineage-0.1.0.tar.gz:

Publisher: release.yml on ctxlineage/ctxlineage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for ctxlineage-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dec375f8cb30680df15a1a846dd0eec7238096cee5de0cc29c4a41140d2d4d38
MD5 5cf602c9ec6046982053cddbb0bc5052
BLAKE2b-256 128d2c3c689e73b2f2771e915dd22ec4865851568f2cdc62edb97626e5f488ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for ctxlineage-0.1.0-py3-none-any.whl:

Publisher: release.yml on ctxlineage/ctxlineage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page