James Lee

Building Lattice: A Knowledge Graph for Claude Code


I’ve been deep into AI-assisted development with Claude Code, and one thing became clear: AI assistants work best when they have context. But context scattered across dozens of markdown files is hard to search and even harder to connect.

So I built Lattice - a knowledge graph that integrates directly with Claude Code through slash commands, turning your documentation into searchable, connected knowledge.

The Problem with Documentation

Most documentation systems treat files as isolated units. You have a folder full of markdown files, maybe a search that does keyword matching, and that’s it. But knowledge isn’t isolated - it’s connected.

When I research a topic, I create multiple related documents:

These documents reference the same concepts, tools, and decisions. But traditional documentation tools don’t capture these relationships.

What Makes Lattice Different

Human-Initiated Extraction

Most knowledge graph tools (like GraphRAG or LightRAG) use a “pipeline-auto” approach - they automatically extract entities whenever you add a document. This sounds convenient, but it means:

Lattice takes a different approach: human-initiated extraction. You decide when to extract entities, you can review what was extracted, and you commit changes to your graph explicitly - all through Claude Code commands.

Entities in YAML Frontmatter

Instead of hiding extracted entities in a database, Lattice stores them in your document’s YAML frontmatter:

---
title: Authentication Architecture
entities:
  - name: JWT
    type: Technology
    relationships:
      - target: User Authentication
        type: IMPLEMENTS
  - name: OAuth2
    type: Protocol
    relationships:
      - target: Third-Party Login
        type: ENABLES
---

This means:

Powered by DuckDB

Early versions of Lattice used FalkorDB (a Redis-based graph database). It worked, but required Docker and external services. Then I migrated everything to DuckDB:

DuckDB gives us:

The Workflow: Claude Code Slash Commands

The primary interface for Lattice is through Claude Code slash commands. Here’s my typical workflow:

1. Research a Topic with /research

When I want to research something, I use the /research command in Claude Code:

/research embedding models comparison

Claude Code then:

2. Sync to Graph with /graph-sync

After creating or updating documentation, I sync everything to the knowledge graph:

/graph-sync

This single command handles the entire pipeline:

The key insight: you don’t need to manually call entity extraction. /graph-sync handles it all - detecting what changed, extracting entities, and syncing to the graph in one step.

Now the knowledge graph powers search across all my documentation. When I ask Claude Code a question, it can search the graph for related concepts, past decisions, and connected documents.

Why Claude Code Integration Matters

The key insight is that the user experience is the Claude Code conversation, not a separate CLI tool. The Lattice CLI exists to support Claude Code agents - it’s the backend that powers the slash commands.

This means:

Technical Architecture

┌─────────────────────────────────────────────────────────────────────┐
│                    LATTICE + CLAUDE CODE                            │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│   User                     Claude Code                   Backend    │
│   ┌─────────┐             ┌──────────┐              ┌─────────┐    │
│   │/research│ ─────────▶  │  Slash   │ ──────────▶  │ Lattice │    │
│   │         │             │ Commands │              │   CLI   │    │
│   │/graph-  │             │          │              │         │    │
│   │  sync   │             │          │              │         │    │
│   └─────────┘             └──────────┘              └─────────┘    │
│        │                       │                         │         │
│        │                       ▼                         ▼         │
│        │                  ┌──────────┐              ┌─────────┐    │
│        │                  │  Claude  │              │ DuckDB  │    │
│        │                  │  Haiku   │              │  + VSS  │    │
│        │                  │(extract) │              │         │    │
│        │                  └──────────┘              └─────────┘    │
│        │                       │                         │         │
│        ▼                       ▼                         ▼         │
│   ┌─────────┐             ┌──────────┐              ┌─────────┐    │
│   │Response │ ◀────────── │   YAML   │ ◀─────────── │ Voyage  │    │
│   │  with   │             │ Front-   │              │ Embed-  │    │
│   │ context │             │ matter   │              │ dings   │    │
│   └─────────┘             └──────────┘              └─────────┘    │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Key Components

  1. Slash Commands: /research and /graph-sync - the user interface
  2. Lattice CLI (@zabaca/lattice): Backend for Claude Code agents
  3. Extractor: Uses Claude Haiku for entity extraction
  4. Graph Store: DuckDB with VSS extension for vector search
  5. Embeddings: Voyage AI for semantic similarity

Why Not Just Use [X]?

Obsidian: Great for personal notes, but the knowledge graph is based on explicit links, not semantic relationships. You have to manually create connections.

Notion: No real knowledge graph. Search is keyword-based.

GraphRAG/LightRAG: Pipeline-auto approach with no human review. Also Python-only (I wanted TypeScript/Bun).

Neo4j: Requires server setup. Overkill for personal documentation.

Lattice fills a specific niche: Claude Code users who want a knowledge graph for their markdown documentation with human-initiated extraction and local-first storage.

What’s Next

I’m currently working on:

Getting Started

If you use Claude Code and want to try Lattice:

1. Install the CLI

bun add -g @zabaca/lattice

2. Initialize Lattice

lattice init

This single command sets up everything:

3. Start Researching

Now you can use the slash commands in Claude Code:

/research your topic here

4. Sync to Graph

After creating documentation, sync it to the knowledge graph:

/graph-sync

That’s it - your knowledge graph is ready to use.

Source code: github.com/Zabaca/lattice

The real power comes from the Claude Code integration - your research becomes a conversation, and the knowledge graph builds naturally as you work.