Skip to main content

Knowledge graph CLI for structured memory in Claude Code

Project description

brain

Give your AI coding agent a knowledge graph that compounds.
Entities, relationships, signals. All local. Zero config.


Quick Start

pip install xarc-brain
cd your-project
brain init

That's it. Your agent maintains the graph automatically.


How It Works

Every conversation follows a cognitive loop:

  1. Scan -- query the graph for context before responding
  2. Respond -- with full awareness of entities, relationships, and history
  3. Write -- capture new information back to the graph

This loop is enforced by hooks that fire automatically. You don't need to remember to use the brain. It's architecturally guaranteed.

brain scan


What It Tracks

Brain stores entities (projects, people, goals, tasks, blockers, decisions, events), relationships between them (who owns what, what blocks what, what depends on what), and temporal signals (what's stale, what's stuck, what just shipped).

brain signals


What It Looks Like in Production

This is the actual brain of CCL, the AI agent that built this tool. 320 nodes, 975 edges, 6 months of compounding memory across multiple companies, projects, and people.

CCL's production brain -- 320 nodes, 975 edges

Your agent builds this over time. Every conversation adds to the graph.


Type System

Nodes are organized in three tiers:

Tier Purpose Default Types
Structural Long-lived entities project, person
Operational Active work items goal, task, decision, blocker
Temporal Immutable records event, observation, status_change

Add your own types:

brain config add-type service structural
brain config add-type feature operational

Signals

brain signals computes what needs attention:

Signal What It Detects
Stale Nodes not verified/updated in 7/14/30+ days
Velocity zero Tasks/goals stuck in non-terminal status
Dependency changed Upstream node updated since you last checked
Recently completed Items done in last 7 days (check what they unblock)
Recurring overdue Recurring activities past their frequency threshold

CLI Reference

Top-level commands

Command Purpose
brain init Bootstrap brain for a project
brain get <id> Show a single node + its edges
brain scan <id> 3-hop topology view
brain context <id> Node + neighbors with content
brain search "<term>" Keyword search across title/content/id
brain search-semantic "<term>" Vector search (requires [embeddings])
brain signals Compute all freshness/decay signals
brain stats Counts by type
brain verify <id> Mark node as verified
brain dream Run full maintenance cycle
brain viz Open browser visualization
brain export --format <fmt> Export graph (cytoscape, json, or batch)

Write group

  • brain write node --json-data '<json>' -- create or update a node
  • brain write edge --json-data '<json>' -- create or update an edge
  • brain write batch --file <path> -- bulk import operations

Delete group

  • brain delete node --id <id> -- archive a node
  • brain delete edge --from <id> --to <id> --verb '<verb>' -- end an edge

Query group

  • brain query cypher "<cypher>" -- raw Cypher (use --read-only for safety)
  • brain query depends-on <id> -- what this node depends on
  • brain query blast-radius <id> -- what depends on this node
  • brain query chain <id> -- full dependency chain
  • brain query changed-since <date> -- nodes modified since
  • brain query stale [--threshold N] -- nodes past threshold (default 14 days)
  • brain query person <id> -- full person assessment subgraph

Embed group

  • brain embed backfill -- generate embeddings for nodes missing them
  • brain embed status -- coverage report

Hygiene group

  • brain hygiene dedup -- find potential duplicates
  • brain hygiene orphans -- disconnected nodes
  • brain hygiene verbs -- verb usage audit
  • brain hygiene completeness -- schema rule violations
  • brain hygiene file-paths -- broken / missing file_path checks
  • brain hygiene content-drift -- brain content vs source file drift
  • brain hygiene readiness -- operational readiness checks

Config group

  • brain config show -- show current config
  • brain config add-type <type_name> <tier> -- register a custom type (tier: structural, operational, or temporal)

JSON schemas

Node:

{
  "id": "my_node_id",
  "type": "project",
  "title": "Display name",
  "status": "active",
  "content": "Optional markdown content",
  "file_path": "optional/relative/path.md",
  "properties": {"any": "nested object"}
}

Edge (note: field names are from, to, verb -- not from_id/source):

{
  "from": "source_node_id",
  "to": "target_node_id",
  "verb": "depends on",
  "since": "2026-04-07",
  "source": "human",
  "note": "optional context"
}

Global flags

--json-output is a global flag and must come before the subcommand:

  • brain --json-output stats (correct)
  • brain stats --json-output (errors with No such option)

Optional Features

Semantic Search

pip install 'xarc-brain[embeddings]'
# Set OPENAI_API_KEY in your environment
brain embed backfill
brain search-semantic "authentication flow"

Conversation History Replay

pip install xarc-memory
# brain init and brain dream will index past Claude Code conversations

Architecture

your-project/
  .brain/              Brain data (add to .gitignore)
    db/                Kuzu embedded graph database
    exports/           Visualization data
    viz/               Cytoscape.js graph visualization
    hooks/             Enforcement hooks (stable across upgrades)
    config.json        Type tiers, custom settings
  .claude/
    settings.local.json   Hooks (auto-installed by brain init)
  CLAUDE.md            Brain instructions (auto-installed)

How It's Built

  • Kuzu -- embedded graph database, no server
  • Rich -- terminal formatting
  • Click -- CLI framework
  • Cytoscape.js -- graph visualization (bundled offline)

~3,500 lines of Python. Fully auditable. No magic.

Nothing leaves your machine. No cloud services. No telemetry. The only optional external call is OpenAI for semantic search embeddings, and that's opt-in via pip install 'xarc-brain[embeddings]'.


Roadmap

v0.1 (current): Core engine, Rich TUI, visualization, hooks, brain init, brain dream

Next:

  • Graph diff (what changed since last session)
  • Auto-dream on session boundaries (Claude Code Stop hook)
  • Multi-agent graph sharing
  • MCP server for native tool integration

Contributions welcome. See CONTRIBUTING.md.


How This Was Built

This project was built by CCL, an AI agent deployed on X-Arc's CCX platform. CCL manages operations, builds tools, and ships code across multiple projects. You can see CCL as a contributor on this repo.

Brain started as CCL's internal memory system. After 6 months of daily use (320 nodes, 975 edges, 5 signal types, 7 hygiene checks running nightly), CCL packaged and open-sourced it.

X-Arc deploys AI agents that ship real work. Manage it like a hire. It works like ten.

x-arc.ai | GitHub

Project details


Download files

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

Source Distribution

xarc_brain-0.3.0.tar.gz (187.8 kB view details)

Uploaded Source

Built Distribution

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

xarc_brain-0.3.0-py3-none-any.whl (174.8 kB view details)

Uploaded Python 3

File details

Details for the file xarc_brain-0.3.0.tar.gz.

File metadata

  • Download URL: xarc_brain-0.3.0.tar.gz
  • Upload date:
  • Size: 187.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for xarc_brain-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e7411dc574bb625e64824477762f32d239a3af046018a16e090eb9d9b2b64f9a
MD5 e88fea6952d90812f1cd71bc9e112f79
BLAKE2b-256 99edfdd4def861c413ee656e6418627f49deb304249c18a4af60020edc53b434

See more details on using hashes here.

File details

Details for the file xarc_brain-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: xarc_brain-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 174.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for xarc_brain-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c70f1d8b0e217534c29b9d36e6e42d587bbca97de50ede410444fe946a3711dc
MD5 11a8a9bec719ecef5c31ae53c76f32d5
BLAKE2b-256 c1eda3b6b979b5ee20525811ed154680ad14df5251f7593d5a60018ddcddf75c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page