AI tools editing your code make mistakes because they have no context. CodeDNA embeds it directly in the files — like DNA in every cell. Zero RAG. Minimal drift.
Imagine asking a contractor to renovate your apartment without showing them the floor plan. Same problem with AI editing your code. CodeDNA is the floor plan.
Every AI coding agent relies on multiple memory layers. Most of them are external to the code. CodeDNA is the only layer that lives inside the source files themselves — it travels with every clone, fork, and CI pipeline.
| Layer | Examples | Where it lives | Shared across tools? |
|---|---|---|---|
| LLM / Agent | Claude, GPT-4, Cursor, Copilot | Cloud | — |
| External memory | Chat history, Memory API | Cloud / external DB | ✗ tool-specific |
| Markdown / Config | CLAUDE.md, .cursorrules, AGENTS.md | Repo (outside source files) | partial |
| CodeDNA | exports, rules, agent, message, .codedna | Inside every source file + repo root | always |
One command installs CodeDNA rules for any AI coding assistant. Or pick the file for your tool and paste it into your project.
bash <(curl -fsSL https://raw.githubusercontent.com/Larens94/codedna/main/integrations/install.sh) claude-hooks # or: cursor-hooks copilot-hooks cline-hooks opencode windsurf
pip install git+https://github.com/Larens94/codedna.git # set ANTHROPIC_API_KEY first codedna init ./ # first-time: annotates every .py file codedna update ./ # incremental: only unannotated files codedna check ./ # coverage report, no changes
.py write automatically..cursor/hooks/: validates on every file edit, reminds at session end. Requires v1.7+..github/hooks/: session start context, post-write validation, session end reminder..clinerules/hooks/: TaskStart context injection, PostToolUse validation. Requires v3.36+.AGENTS.md + JS plugin in .opencode/plugins/. Validates 11 languages on every write..windsurfrules to your project root. Cascade reads it automatically..agents/workflows/codedna.md to your project. Compatible with Antigravity and custom agent frameworks.Like biological DNA: cutting it in half produces two fragments that still carry the complete information. With CodeDNA, 10 random lines from anywhere in a file are enough for the AI to act correctly.
"""pricing.py — Pricing engine with tier discounts.
exports: apply_discount(cents, tier) -> int
used_by: checkout.py → build_cart
rules: NEVER exceed MAX_DISCOUNT_RATE from config.py;
apply_discount() must cap before returning.
DB: discount_tiers(tier, multiplier).
"""
def apply_discount(cents: int, tier: str) -> int: """Apply tier discount to price in cents. Rules: MUST cap discount before returning — exceeding MAX_DISCOUNT_RATE is a financial compliance bug. After fix #42: also check tier != 'internal'. """ discount = get_multiplier(tier) discount = min(discount, MAX_DISCOUNT_RATE) return int(cents * (1.0 - discount))
# ❌ Ambiguous — euros? cents? price = request.json.get("price") data = get_users() # ✅ CodeDNA — type, domain, origin are clear int_cents_price_from_request = request.json.get("price") list_dict_users_from_db = get_users()
# 1. Read .codedna — project structure # 2. Read module docstring (8–12 lines each) # 3. Filter: used_by mentions target? Include # rules mentions task domain? Include # 4. Build exports → used_by graph # 5. Open in full ONLY the relevant files # Cost: ~50 tok × N files = complete map
5 scenarios that illustrate the categories of errors AI agents make without architectural context. For measured results, see the SWE-bench benchmark below.
used_by:, the AI only updates utils.py and leaves main.py with a runtime KeyError.price = 1999 — euros or cents? Without semantic naming the AI gets the unit wrong. With CodeDNA: int_cents_price_from_request — zero ambiguity.format_revenue() → format_currency(). The rules: field records the rename. The Control calls the old name: crash.exports: → used_by: graph it identifies exactly the 2 files.5 real Django issues from SWE-bench, tested across multiple LLMs. Same prompt, same tools, same tasks. Gemini 2.5 Flash: +13pp F1, p=0.040 · DeepSeek Chat: +9pp F1, p=0.11 · Gemini 2.5 Pro: +9pp F1, p=0.11. All 3 models improve.
Navigation Demo — django__django-11808 · DeepSeek Chat · 5 runs
Without CodeDNA: agent opens random files, stops early — 2/10 critical files found. |
With CodeDNA: follows used_by: chain — 6/10 critical files found.
🔬 Methodology: 5 SWE-bench Django tasks × 3 models (Gemini 2.5 Flash ✓, DeepSeek Chat ✓, Gemini 2.5 Pro ✓). 5 runs/task at T=0.1. Identical system prompt, same 3 tools (read_file, list_files, grep), max 30 turns. Metric: File Localization F1 (ground-truth files from patch). Statistical test: Wilcoxon signed-rank (one-tailed). Script: benchmark_agent/swebench/run_agent_multi.py.
| Approach | Token overhead | Context drift | Retrieval latency | Sliding-window | Infrastructure |
|---|---|---|---|---|---|
| CLAUDE.md / CursorRules | Low | Medium | Zero | No | External file |
| RAG / Vector DB | Low | Medium | High | No | DB + embedding |
| MemGPT | Medium | Low | Medium | No | Complex system |
| CodeDNA ✦ | Low (inline) | Low | Zero | Yes ✓ | None |
<type>_<shape>_<domain>_<origin>. Manifest-Only Planner Read.codedna init, codedna update, codedna check · pip installable · Claude Code Challenge: 7/7 patch files in ~8 min vs 6/7 in ~10–11 min (control). Results →M1–M5 are part of a funding application to NLnet NGI0 Commons Fund. If you find CodeDNA useful, ⭐ the repo and share it.