Cognitree
Cognitree
AI Memory System  ยท  v0.1  ยท  Open Source

Every AI session starts from zero. Cognitree changes that.
Persistent memory. Versioned cognition. Branch-based error recovery.
For Claude Code, Qwen Code, and Gemini CLI.

โฌก  View on GitHub โ†“  How it works
10 Memory Layers Checkpoint Tree Time Travel Branch Recovery Delta Storage Zero Hallucination Token Efficient Claude Code Qwen Code Gemini CLI VS Code Extension Local First Model Agnostic Codebase Tracking 10 Memory Layers Checkpoint Tree Time Travel Branch Recovery Delta Storage Zero Hallucination Token Efficient Claude Code Qwen Code Gemini CLI VS Code Extension Local First Model Agnostic Codebase Tracking
โ†“70%
Hallucination reduction
10
Structured memory layers
โˆž
Cross-session persistence
3+
AI agent integrations
How it works

The Cognitree Pipeline

Five stages that run on every prompt โ€” turning a forgetful LLM into a precise, state-aware coding agent.

01
๐Ÿง 
LLM Completes a Task
Claude Code, Qwen Code, or Gemini CLI produces output โ€” code, a decision, a fix, an explanation. This output is the raw material Cognitree works from.
02
โš™๏ธ
Memory Extractor Parses Output
Cognitree scans the output and tags extracted data for the correct memory layer โ€” decisions, mistakes, progress, state changes โ€” each to its layer.
extract({ goal: "...", // active objective progress: [...], // what got done mistakes: [...], // what failed โ€” permanent decisions: [...], // why X over Y warnings: [...], // be careful about codebase: {...}, // added, deleted, modified, renamed files prompt_state: {} // what AI believes right now })
03
๐Ÿ—„๏ธ
Checkpoint Written to Store
An immutable checkpoint is created โ€” memory deltas, code deltas (diffs only), parent pointer, branch ID, confidence score. Full snapshot every 10 checkpoints. Deltas in between.
04
๐ŸŽฏ
Context Injector Fires Before Next Prompt
Only relevant layers retrieved and injected. The AI reads a structured block with everything it needs โ€” no re-derivation, no wasted tokens.
[COGNITREE โ€” VoidRoom ยท cp_010b ยท branch-b ยท confidence 0.91] GOAL: Implement self-destructing messages with TTL expiry PROGRESS: Auth done, schema defined, UI scaffolded NEXT: Verify TTL index fires correctly with a test document MISTAKES: mongoose.findByIdAndDelete() โ†’ use findOneAndDelete() [critical] WARNINGS: TTL needs MongoDB background process running [medium] DECISION: TTL index over cron โ€” atomic, native MongoDB (cp_010b) CODEBASE: /models/message.js [added cp_007] /models/user.js [added cp_003] /api/auth.js [added cp_004] /api/messages.js [added cp_010b] /client/src/App.js [added cp_002] /client/src/Chat.jsx [added cp_005] /utils/oldHelper.js [DELETED cp_008] /package.json /.env /README.md [/COGNITREE]
05
๐Ÿš€
AI Works with Perfect Precision
The model knows exactly what was built, what failed, what was decided, and what to do next. Zero tokens wasted. Zero repeated mistakes. Zero hallucinations of known-bad paths.
Architecture

Ten Memory Layers

Everything a developer holds in their head while coding โ€” now structured, persistent, and injected with precision before every prompt.

Layer 01 โ€” Active
Goal
What we are building right now. The active objective for this session.
Current feature or fix in progress
Success criteria for this task
Layer 02 โ€” Done
Progress
What is already completed. The AI never re-does finished work.
Completed features and merged logic
Files and modules already implemented
Layer 03 โ€” Permanent
Mistakes
What went wrong. Never cleared. Never forgotten. Never repeated.
Hallucinated APIs and functions
Logic errors that caused bugs
Layer 04 โ€” Blocked
Blockers
What is stuck or unresolved. Needs attention before moving forward.
Unsolved bugs or missing dependencies
Decisions waiting for input
Layer 05 โ€” Immediate
Next
The single immediate next step. One action at a time, always clear.
Exact next function or file to work on
Updated after every checkpoint
Layer 06 โ€” History
Changed
What was updated or refactored and when. Full change log across sessions.
Refactored files with checkpoint reference
API changes, renames, and restructures
Layer 07 โ€” Rationale
Decisions
Why X was chosen over Y. Architecture choices with full reasoning preserved.
Tech stack choices and trade-offs
Pattern choices with full reasoning
Layer 08 โ€” Caution
Warnings
Fragile areas and edge cases. Forwarded into every new branch automatically.
Sensitive files or race conditions
Known gotchas in the stack
Layer 09 โ€” Live
Prompt_State
The AI's active cognitive state. What it currently believes and assumes. Reset per checkpoint.
Active file and function in scope
Current approach and live assumptions
Layer 10 โ€” Codebase
Codebase
The full codebase architecture. Every file, every directory, every addition, deletion, modification, and rename โ€” tracked per checkpoint. Always fully injected. The AI never hallucinates a path that doesn't exist.
Full directory tree on every base checkpoint
Added files + directories with checkpoint ref
Deleted files stay in tree โ€” marked deleted forever
Modified + renamed files tracked explicitly
Versioned Cognition

Checkpoint & Branch System

Every prompt is a commit growing downward. Branch from any node, on any branch, at any depth. Every node stays intact forever โ€” unless you delete it manually.

// THE COGNITREE โ€” HOW IT GROWS
  โ— 1  โ† root ยท all sessions begin here
  โ”‚
  โ— 2
  โ”‚
  โ— 3
  โ”‚
  โ— 4
  โ”‚
  โ— 5
  โ”‚
  โ— 6
  โ”‚
  โ— 7  โ† developer rewinds here, not happy with direction
  โ”‚\
  โ”‚ \
  โ— 8 โ— 8a  โ† new branch from 7, trunk continues untouched
  โ”‚ โ”‚
  โ— 9 โ— 9a
  โ”‚ โ”‚\
  โ”‚ โ”‚ \
  โ—10 โœ•10a โ— 10b  โ† 10a failed ยท branch again from 9a ยท branch of a branch
  โ”‚      โ”‚
  โ—11     โ— 11b  โ† all nodes alive ยท developer switches freely
  โ”‚      โ”‚\
  โ”‚      โ”‚ \
  โ—12    โ—12b โ— 12c  โ† branch of branch of branch ยท unlimited depth
      

// SWITCHING TO ANY NODE
โ†’ Jump to 10b โ€” loads memory from 1โ†’2โ†’3...โ†’9aโ†’10b
โ†’ Jump to 8  โ€” loads memory from 1โ†’2โ†’3...โ†’7โ†’8
โ†’ Jump to 12c โ€” loads full lineage + all ancestor lessons
โ†’ Nothing on other branches is touched or broken
โ†’ Switch back anytime โ€” every node is self-contained
// WHAT EACH NODE CARRIES
โœ“ All 9 memory layers at that exact moment
โœ“ Mistakes + Warnings from every ancestor
โœ“ Warnings forwarded from failed sibling branches
โœ“ Code state delta from parent checkpoint
โœ— Sibling and descendant branches โ€” invisible to AI
Checkpoint Structure
id: "cp_12c_f7a2"
parent_id: "cp_11b_..."
branch_id: "branch-c"
depth: 3 // branch of branch of branch
is_base: false // full snap every 10
confidence: 0.91 // branch health 0โ€“1
memory_delta: {...} // changed layers only
code_delta: [...] // file diffs only
deleted: false // manual delete only
Delta Storage
โ— Full snapshot every 10 checkpoints
โ— Diffs only between base snapshots
โ— Unchanged files referenced, never copied
โ— Reconstruct = walk ancestors to nearest base
โ— All nodes permanent unless manually deleted
โ— ~95% storage reduction vs full snapshots
Compatibility

Works With Any Agent

Same memory engine, different injection adapters per tool. No lock-in. Use what you already have.

Claude Code
CLAUDE.md + MCP Server
Cognitree auto-writes memory into CLAUDE.md before each session. Also exposes all 9 memory layers as MCP tools Claude can read and write natively.
Qwen Code
Native Integration ยท Free
Open source โ€” Cognitree integrates directly into Qwen Code's prompt pipeline. 1000 free API requests per day. No cost to start. Primary integration target.
Gemini CLI
GEMINI.md + State API
Open source โ€” direct integration into prompt construction. GEMINI.md memory file plus Cognitree local state API. Bring your own Gemini API key.
Impact

Before vs After

The difference Cognitree makes in every session, on every project, with every AI tool.

Without Cognitree
โœ—Re-derives full project context every session
โœ—Repeats hallucinated API calls and wrong paths
โœ—No memory of prior decisions or rationale
โœ—~60% of tokens wasted re-establishing context
โœ—One error compounds into the whole session
โœ—No clean way to recover from a bad AI decision
With Cognitree
โœ“Instantly knows full project state from memory
โœ“Mistake layer permanently blocks known hallucinations
โœ“Understands WHY every decision was made
โœ“~85% of tokens used for actual productive work
โœ“Errors isolated per branch โ€” clean recovery always
โœ“Rewind to any checkpoint, branch, start fresh
Roadmap

What's Being Built

VS Code extension first โ€” zero friction for people already using Cursor and VS Code. IDE fork when the community is ready.

Phase 1
Memory Engine Core
Standalone memory store, 9 layers, checkpoint writer, delta storage, branch tree. No UI โ€” pure engine.
BUILDING
Phase 2
VS Code Extension
Sidebar checkpoint tree, time travel UI, memory diff viewer, context injector. Works inside VS Code and Cursor โ€” no IDE switch needed.
PLANNED
Phase 3
Agent Adapters
Native integration into Qwen Code and Gemini CLI source. CLAUDE.md + MCP server adapter for Claude Code. Bring your own key for Claude and Gemini.
PLANNED
Phase 4
Cognitree IDE
Code OSS fork with Qwen Code + Cognitree built in natively. Free forever for individuals. 1000 free Qwen requests/day. Claude and Gemini via API key.
PLANNED
Phase 5
Team Memory
Optional shared memory sync for collaborative projects. Organizational governance, audit, and compliance features. Individual core always free.
PLANNED