๐ฒ 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.
Setup โ 2 Commands
pip install context-lineage
ctx setup . <project dir>
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.
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 context_lineage-0.2.1.tar.gz.
File metadata
- Download URL: context_lineage-0.2.1.tar.gz
- Upload date:
- Size: 149.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2744b59bee03b4a38c6f96afb8ccdbcf2420a2479d4ac76480e3e595f56e99cb
|
|
| MD5 |
faa1dff0ac48df4b6094964088528be9
|
|
| BLAKE2b-256 |
29e5a7acb48b1c3c83934841673a7ae7c6494e352e37ffcd1eec3ea1b57e72ca
|
File details
Details for the file context_lineage-0.2.1-py3-none-any.whl.
File metadata
- Download URL: context_lineage-0.2.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85e9be7e9a84fd21c2214072ca310c11c3d8254f23a4f7dfcdceded011749934
|
|
| MD5 |
e706f243b90aeccc5c9b49e196a96255
|
|
| BLAKE2b-256 |
c0a59fd540d925f40913c7918910e4c2621208b9a77c21bbcf7ef8cead06588d
|