Brain init

From coco-research/coco · View interactive version

Brain init is an AI agent skill from the GitHub repository coco-research/coco. Use when setting up project memory in a new folder or on the first brain:init in a project. Creates project_brain.db, registers the project, and bootstraps it from CLAUDE.local.md, memory files, docs, and emails; safe to re-run.

How to use this skill

Skill file

/brain:init --- Initialize Project Brain

Sets up a new project_brain.db in the current working directory and bootstraps it from existing project knowledge.

Procedure

Step 1: Check existing state

Run:

python3 ~/.claude/skills/brain/scripts/brain/brain_cli.py info

Step 2: Create the database and project record

Run:

python3 ~/.claude/skills/brain/scripts/brain/brain_cli.py init

Ask the user:

Then run:

python3 ~/.claude/skills/brain/scripts/brain/brain_cli.py add-project "{name}" --slug {slug} --desc "{description}"

If the project has sub-scopes (like ProjectA-Phase1 and ProjectA-Phase2 under one umbrella), ask if the user wants multiple project records.

Step 3: Scan the project folder

Run the scanner to discover what's available:

python3 ~/.claude/skills/brain/scripts/brain/brain_cli.py scan

This returns a JSON report with:

Show the user a summary:

FOLDER SCAN
===========
First scan:     yes/no
Files found:    NN total (NN new, NN changed, NN unchanged)

Knowledge sources detected:
  CLAUDE.local.md:  found / not found
  CLAUDE.md:        found / not found
  Memory files:     N files (list names)
  Documents:        N files in docs/
  Emails:           N files in emails/
  Reference docs:   N files

If nothing to process (all unchanged): "Everything up to date. No new knowledge to extract." → done.

Step 4: Extract knowledge from sources (Claude-driven)

Process sources in priority order. For each source, read the file, extract structured knowledge, and collect proposed writes. Do NOT write to the brain yet — collect everything first.

Priority 1: CLAUDE.local.md

If found, read the full file. Extract:

Priority 2: Memory files (~/.claude/projects/.../memory/*.md)

Each memory file has frontmatter (name, description, type) and content. Read each file:

Priority 3: Document inventory

For each file in docs/, emails/, and Reference Doc/:

Priority 4: CLAUDE.md (project-level, if exists)

Same extraction as CLAUDE.local.md but lower priority (may overlap).

Step 5: Present extraction summary

Show proposed writes:

BRAIN BOOTSTRAP SUMMARY
========================
Project: {name} ({slug})

From CLAUDE.local.md:
  Entities:    N (list: name [type])
  Decisions:   N (list: short text)
  Events:      N (list: title)

From memory files:
  Decisions:   N (list: short text)
  Entities:    N (list: name [type])

Document inventory:
  Documents:   N (list: filename [doc|email|reference])

Total proposed writes: NN

Ask: "Write all to brain? [Y/n/adjust]"

Step 6: Execute writes

On confirmation, write in this order using Python:

import sys
sys.path.insert(0, '$HOME/.claude/skills/brain/scripts')
from brain.schema import get_db
from brain.operations import *
  1. Entities — use upsert_entity (idempotent, safe to re-run)
  2. Relationships — use create_relationship (also idempotent)
  3. Decisions — use create_decision (check for duplicates by matching decision text before inserting)
  4. Events — use create_event (check for duplicates by matching title + date)
  5. Document entities — use upsert_entity with type="document"

After all writes, sync to MemPalace and brain.json:

from brain.memory_bridge import full_sync
full_sync("project_brain.db", project_slug)

After writes complete, update the manifest:

python3 ~/.claude/skills/brain/scripts/brain/brain_cli.py scan-update

Step 7: Report

BRAIN INITIALIZED
=================
DB:            {path}/project_brain.db
Project:       {name} ({slug})
Schema:        v1 (11 tables)

Bootstrapped from existing knowledge:
  Entities:      +N (total: N)
  Decisions:     +N (total: N)
  Events:        +N (total: N)
  Documents:     +N (total: N)
  Relationships: +N (total: N)

Manifest updated: N files tracked

Next: Run /brain-update at end of session, or /brain-rescan when files change.

Step 8: Generate knowledge articles

After completing brain writes (Step 6) and confirming the manifest is updated (Step 6

scan-update), initialize the knowledge engine for this project.

First, register the project with the knowledge engine:

import sys, os
sys.path.insert(0, os.path.expanduser("~/.coco/knowledge"))
from engine import KnowledgeEngine

engine = KnowledgeEngine()
engine.register_project("{slug}", os.path.abspath("project_brain.db"))

This is required before the cron can harvest the project. (FIX M1: register_project

must be called before running any cron phases.)

Then, bootstrap article generation:

engine.full_refresh("{slug}")

Or equivalently via CLI:

python3 ~/.coco/knowledge/cron.py --run --project {slug} --phases 2,3,5

This runs:

Show the user:

KNOWLEDGE ENGINE
================
Articles generated:  N
FTS5 indexed:        N
Estimated cost:      $0.XXX

Articles written to: ~/.coco/knowledge/articles/
Search with: /brain-wiki search "{project_name}"

Skip this step silently if:


Important Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.