Skip to main content

๐ŸŒฒ ContextLineage

AST-Grounded Code Lineage & Deterministic Navigation for AI Coding Agents

Stop burning 50,000+ tokens on full-codebase dumps. Give your agents progressive context, AST call graphs, pointer-first navigation, and deterministic anti-hallucination guardrails.

PyPI version Python versions License: MIT CI Tests Token Savings PRs Welcome


Setup โ€” 2 Commands

pip install context-lineage
ctx setup src/

That's it. Claude Code, Cursor, and other coding agents receive a compact command index (~219 tokens). It tells them when to run ContextLineage for live, AST-grounded pointers instead of loading a stale module dump into every session.

Commit the generated files so every developer and every AI session uses them:

git add CLAUDE.md AGENTS.md .cursorrules
git commit -m "chore: add ContextLineage AI context"

What ctx setup generates

File Who reads it What it contains
CLAUDE.md Claude Code (automatic) Compact command index, entry-point summary, and live-query triggers
.cursorrules Cursor (automatic) Same compact command index
AGENTS.md Any AI agent Instructions to use ctx verify, ctx query, and ctx pack before asserting code facts
Git pre-commit hook Auto-runs on every git commit Keeps all files fresh on every commit โ€” zero maintenance

Why This Exists

AI coding agents fail on real codebases in two ways:

Context Overflow โ€” Dumping all source files into the prompt burns 50,000+ tokens per turn, runs up huge API bills, and causes LLM reasoning to degrade ("Lost in the Middle" effect).

Context Starvation โ€” Reading only file names or unstructured docs causes agents to hallucinate non-existent functions, reversed caller/callee directions, and phantom circular dependencies.

ContextLineage fixes both. It builds a structured AST knowledge graph of your codebase and serves it as actionable file:line pointers โ€” giving agents the exact 20โ€“50 lines they need to inspect directly from source.


What's Under the Hood

Your Python Codebase
        โ†“
   ctx setup src/
        โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  1. AST Dependency & Call Graph         โ”‚  Who calls what, what imports what
โ”‚  2. Pointer-First Navigation            โ”‚  Exact file.py:L1-L2 targets (ctx query -p)
โ”‚  3. Docstring Frontmatter Governance    โ”‚  Zero-drift CI/CD verification (ctx validate / ctx sync)
โ”‚  4. Anti-Hallucination Verifier         โ”‚  verify_claim checks facts before writing code
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ†“
   CLAUDE.md / .cursorrules / AGENTS.md
        โ†“
Claude Code / Cursor / Devin / Antigravity / Any Agent

2-Step Agent Navigation Workflow

[Agent Query]  โ†’  ctx query symbol <name> -p  โ†’  Returns: "engine.py:38-99 (process_claim)"
     โ†“
[Targeted Read] โ†’  Agent reads ONLY lines 38-99  โ†’  100% verified correctness, 92% token savings

Key CLI Commands

# 1. Pointer-first navigation (find exact file and line ranges)
ctx query symbol OrchestratorEngine.process_claim -d src/ -p

# 2. Trace call chains through your codebase with line pointers
ctx query lineage pipeline.orchestrator -d src/ -p

# 3. Understand blast radius before refactoring
ctx query impact pipeline.stages.extract -d src/

# 4. Verify a claim before writing code (prevents hallucinations)
ctx verify "run_pipeline calls extract_data" -d src/

# 5. Auto-sync docstring YAML frontmatter across the repo in one command
ctx sync src/

# 6. Check docstring drift in CI/CD (exits 1 if drift found)
ctx validate src/

Real-World Benchmark

Evaluated against an enterprise orchestration service:

Paradigm Complete & Correct Answers Tokens Consumed Cost Savings vs Baseline Hallucination Risk
1. Direct Whole-File Reads (Baseline) 5 / 5 34,073 tokens Baseline (0%) Low
2. Query Output Alone (No Source Reads) 0 / 5 (2 partial, 3 abstained) 2,614 tokens N/A (Failed correctness) High if agent guesses
3. ContextLineage Pointer Slices 5 / 5 (100%) 2,711 tokens 92.0% Reduction 0% (Verified from source)

โ†’ Full benchmark details ยท Comparison Report


Frequently Asked Questions

Have questions about how ContextLineage compares to Graphify, Tree-sitter tools, or how CI/CD governance works?

โ†’ Read the FAQ (Frequently Asked Questions)


Python API

from pathlib import Path
from contextlineage.agent_skill import create_code_explorer_skill
from contextlineage.context_packer import create_context_packer

skill = create_code_explorer_skill(Path("src/"), token_budget=3000)
skill.initialize()

# Verify a claim against AST ground truth
result = skill.verify_claim("run_pipeline calls extract_data")
# โ†’ {"verified": True, "confidence": 0.95, "evidence": ["AST verified: ..."]}

# Pack context for LLM prompt injection
packer = create_context_packer(skill, max_tokens=3000)
packed = packer.pack_for_task("trace_dataflow", "pipeline.orchestrator")
prompt = f"Codebase context:\n{packed.to_markdown()}\n\nTask: {user_task}"

LangChain & CrewAI

# LangChain
from contextlineage.integrations.langchain import FrontmatterLoader, FrontmatterRetriever
loader = FrontmatterLoader("manifest.json")
retriever = FrontmatterRetriever(loader.manifest, k=5, token_budget=8000)

# CrewAI
from contextlineage.integrations.crewai import create_frontmatter_tools
tools = create_frontmatter_tools("manifest.json")
agent = Agent(role="Code Explorer", tools=tools)

dbt Support (Coming Soon)

ContextLineage is expanding to dbt SQL/Jinja models โ€” parsing {{ ref() }} and {{ source() }} DAGs, extracting column contracts from schema.yml, and providing the same progressive disclosure for dimensional modeling projects.

โ†’ dbt Architecture Specification


Contributing

git clone https://github.com/swapnilwaramwar/ContextLineage.git
cd ContextLineage
pip install -e ".[dev]"
pytest tests/

See CONTRIBUTING.md for guidelines.


MIT License ยท Built for the age of autonomous coding agents

Download files

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

Source Distribution

context_lineage-0.2.0.tar.gz (148.0 kB view details)

Uploaded Source

Built Distribution

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

context_lineage-0.2.0-py3-none-any.whl (111.9 kB view details)

Uploaded Python 3

File details

Details for the file context_lineage-0.2.0.tar.gz.

File metadata

  • Download URL: context_lineage-0.2.0.tar.gz
  • Upload date:
  • Size: 148.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.13

File hashes

Hashes for context_lineage-0.2.0.tar.gz
Algorithm Hash digest
SHA256 73889ab48064a4af456a09029bddac5b6f6938a8ca04950f3500811b798c02e9
MD5 2f4dd827083472a401f1d462447f1d6d
BLAKE2b-256 e587074511644b9f0e3dc041b3c8dbacc501c19079153afef43e2b15532a0a95

See more details on using hashes here.

File details

Details for the file context_lineage-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: context_lineage-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 111.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.13

File hashes

Hashes for context_lineage-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ea024cd974711574670c812442847ffe0d96acd639276eca956040220266964
MD5 5b743932244e65e4c9e00eb4b905edbc
BLAKE2b-256 2d515fa79f73bc7c455fb632e538eee3348d4fa133da31c0d33647aa698d99ae

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.2

2 files

0.2.1

2 files

This release

0.2.0 This release

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