agentleFS
SpillwaveSolutionsSpillwaveSolutions/agent-brain/CLAUDE.md

agent-brain

CLAUDE.md120 starsChanged 6 months agoMITView on GitHub

Instructions for Claude Code when working on this repository. Planning rule: after any planning step, save the plan to docs/plans/<name>.md before doing work. ABSOLUTE RULE: You MUST run task before-push BEFORE EVERY git push. NO EXCEPTIONS. This runs format, lint, typecheck, and tests. Do NOT push code that fails this check. Why this matters: PRs trigger expensive CI pipelines. Pushing broken code wastes time and money. Every single push failure that could have been caught locally is unacceptable. Enforcement checklist…

  • Reads credentials
  • Installs packages
  • Commits and pushes

The file

Show its rules and text

We split this CLAUDE.md into the rules it gives an agent

14 rules. About 0 are common, 7 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    No lint errors (Ruff)

    line 25
  2. Distinctive:

    No type errors (mypy)

    line 26
  3. Very specific:

    IMPORTANT: Always use uv instead of pip for installing packages.

    line 60
  4. Distinctive:

    Keep functions focused and testable

    line 161
  5. Very specific:

    Check .gitignore excludes all sensitive files

    line 293
  6. Distinctive:

    After ANY code changes — no matter how small — you MUST:

    line 306
  7. Very specific:

    Run task before-push and verify it passes with exit code 0

    line 307
  8. Very specific:

    Run task pr-qa-gate before creating or updating PRs

    line 308
  9. Very specific:

    Use conventional commits: feat:, fix:, docs:, test:, refactor:

    line 320
  10. Distinctive:

    Create feature branches from main

    line 321
  11. Very specific:

    MANDATORY: Run task before-push before pushing to any branch

    line 322
  12. Distinctive:

    No linting errors (Ruff)

    line 335
  13. Distinctive:

    All tests pass with coverage report

    line 337
  14. Very specific:

    Import order — run ruff check --fix to auto-fix

    line 344

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

Agent Brain Development Guidelines

Instructions for Claude Code when working on this repository.

Planning rule: after any planning step, save the plan to docs/plans/<name>.md before doing work.

CRITICAL: NEVER PUSH WITHOUT TESTING

ABSOLUTE RULE: You MUST run task before-push BEFORE EVERY git push. NO EXCEPTIONS.

task before-push

This runs format, lint, typecheck, and tests. Do NOT push code that fails this check.

Why this matters: PRs trigger expensive CI pipelines. Pushing broken code wastes time and money. Every single push failure that could have been caught locally is unacceptable.

Enforcement checklist (verify ALL pass before pushing):

  1. task before-push exits with code 0
  2. No lint errors (Ruff)
  3. No type errors (mypy)
  4. All tests pass
  5. Code is formatted (Black)

If task before-push fails, DO NOT push. Fix the issues first.

Project Overview

Agent Brain is a RAG-based document indexing and semantic search system. It's a monorepo containing:

PackagePathPyPI NameDescription
agent-brain-serveragent-brain-server/agent-brain-ragFastAPI REST API server
agent-brain-cliagent-brain-cli/agent-brain-cliCLI management tool
agent-brain-udsagent-brain-uds/agent-brain-udsUnix domain socket transport
agent-brain-mcpagent-brain-mcp/agent-brain-ag-mcpMCP server (tools, resources, prompts)
agent-brain-skillagent-brain-skill/—Claude Code skill
agent-brain-pluginagent-brain-plugin/—Claude Code plugin (commands, agents, skills)

PyPI rename note: the MCP package publishes as agent-brain-ag-mcp (renamed in v10.1.2 — PyPI typosquatting filter rejected the original name). The console script is still agent-brain-mcp and the import path is still agent_brain_mcp.

Technology Stack

  • Python: 3.10+
  • Build System: Poetry
  • Package Installer: uv (preferred over pip)
  • Server: FastAPI + Uvicorn
  • CLI: Click + Rich
  • Vector Store: ChromaDB
  • Embeddings: OpenAI text-embedding-3-large
  • Indexing: LlamaIndex

Package Installation

IMPORTANT: Always use uv instead of pip for installing packages. It's faster and handles dependencies better.

# Build packages
cd agent-brain-server && poetry build
cd agent-brain-cli && poetry build

# Install with uv (NOT pip)
uv pip install dist/agent_brain_rag-*.whl --force-reinstall
uv pip install dist/agent_brain_cli-*.whl --force-reinstall

# Deploy plugin to cache
cp -r agent-brain-plugin/* ~/.claude/plugins/agent-brain/

Build and Test Commands

agent-brain-server

cd agent-brain-server
poetry install                    # Install dependencies
poetry run agent-brain-serve      # Run server
poetry run pytest                 # Run tests
poetry run pytest --cov=agent_brain_server       # Tests with coverage
poetry run mypy agent_brain_server               # Type checking
poetry run ruff check agent_brain_server         # Linting
poetry run black agent_brain_server              # Format code

agent-brain-cli

cd agent-brain-cli
poetry install                    # Install dependencies
poetry run agent-brain --help     # Show CLI help
poetry run pytest                 # Run tests
poetry run mypy agent_brain_cli               # Type checking
poetry run ruff check agent_brain_cli         # Linting
poetry run black agent_brain_cli              # Format code

Full Quality Check

# Run from package directory
poetry run black agent_brain_server tests && poetry run ruff check agent_brain_server tests && poetry run mypy agent_brain_server && poetry run pytest

Known Issues

  • Run task commands from the repo root, not from inside a package directory — per-package cwd causes scope leaks across the monorepo's shared Taskfile.yml includes.
  • Flaky sentence-transformer warm-up test: the first model-download/warm-up assertion can intermittently fail on a cold cache; re-run task test once before assuming a real regression.

Project Structure

agent-brain/                          # Monorepo root (Taskfile orchestrates all packages)
├── agent-brain-server/               # FastAPI server  (PyPI: agent-brain-rag)
│   ├── agent_brain_server/
│   │   ├── api/                      # REST endpoints (main.py + routers/)
│   │   ├── config/                   # Settings (Pydantic)
│   │   ├── indexing/                 # AST-aware document processing
│   │   ├── models/                   # Request/response models
│   │   ├── services/                 # Business logic (indexing, query)
│   │   └── storage/                  # ChromaDB integration
│   └── tests/
├── agent-brain-cli/                  # CLI tool  (PyPI: agent-brain-cli)
│   ├── agent_brain_cli/
│   │   ├── cli.py                    # Main entry point
│   │   ├── client/                   # Transport clients (HTTP, UDS, MCP)
│   │   └── commands/                 # CLI command implementations
│   └── tests/
├── agent-brain-uds/                  # Unix domain socket transport  (PyPI: agent-brain-uds)
│   ├── agent_brain_uds/
│   └── tests/
├── agent-brain-mcp/                  # MCP server  (PyPI: agent-brain-ag-mcp; import: agent_brain_mcp)
│   ├── agent_brain_mcp/              # Tools, resources, prompts; stdio + Streamable HTTP
│   └── tests/
├── agent-brain-plugin/               # Claude Code plugin (commands, agents, skills) — markdown
│   ├── commands/  agents/  skills/
│   └── plugin.json                   # version owned by the release process
├── agent-brain-skill/                # Standalone Claude Code skill — markdown
│   └── SKILL.md
├── Taskfile.yml                      # Monorepo task runner (run `task` from repo root)
├── scripts/                          # Release, lock-guard, quick-start validation
└── docs/                             # Documentation

Code Style

Python Standards

  • Formatter: Black (line length 88)
  • Linter: Ruff
  • Type Checker: mypy (strict mode)
  • Type Hints: Required for all function signatures

Style Guidelines

  1. Use Google-style docstrings
  2. Sort imports with Ruff/isort
  3. Type hint all function parameters and returns
  4. Keep functions focused and testable

API Endpoints

EndpointMethodDescription
/healthGETHealth check
/health/statusGETIndexing status
/queryPOSTSemantic search
/query/countGETDocument count
/indexPOSTStart indexing
/index/addPOSTAdd documents
/indexDELETEClear index

CLI Commands

Project Commands

CommandDescription
agent-brain initInitialize a new Agent Brain project (creates .agent-brain/)
agent-brain startStart an Agent Brain server for this project
agent-brain stopStop the Agent Brain server for this project
agent-brain listList all running Agent Brain instances

Server Commands

CommandDescription
agent-brain statusCheck Agent Brain server status and health
agent-brain query "text"Search indexed documents
agent-brain index /pathIndex documents from a folder (queued)
agent-brain inject /path --script enrich.pyIndex documents with content injection
agent-brain reset --yesClear all indexed documents
agent-brain doctorDiagnose installation, configuration, and server state

MCP & Transport Commands

CommandDescription
agent-brain mcp startStart the MCP server (agent-brain-mcp) for this project
agent-brain mcp stopStop the MCP server
agent-brain prompt <name>Render a registered MCP prompt (e.g. find-callers, explain-architecture)
agent-brain resources listList available corpus:// MCP resources
agent-brain resources read <uri>Read a corpus:// resource (e.g. corpus://status)

Transport is selectable via the global --transport {auto,http,uds,mcp} flag (or AGENT_BRAIN_TRANSPORT); auto prefers UDS and falls back to HTTP. The MCP package publishes to PyPI as agent-brain-ag-mcp but the console script stays agent-brain-mcp.

Job Queue Commands

CommandDescription
agent-brain jobsList all jobs in queue
agent-brain jobs --watchWatch queue with live updates (refresh every 3s)
agent-brain jobs JOB_IDShow job details
agent-brain jobs JOB_ID --cancelCancel a job

Cache Commands

CommandDescription
agent-brain cache statusShow embedding cache statistics
agent-brain cache clearClear all cached embeddings

Folder Commands

CommandDescription
agent-brain folders listList all indexed folders with chunk counts
agent-brain folders add /pathIndex a new folder (alias for index)
agent-brain folders remove /pathRemove all indexed chunks for a folder

File Type Commands

CommandDescription
agent-brain types listList available file type presets and extensions

Configuration Commands

CommandDescription
agent-brain config showDisplay active provider configuration
agent-brain config pathShow config file location

Runtime Installation Commands

CommandDescription
agent-brain install-agent --agent claudeInstall for Claude Code
agent-brain install-agent --agent opencodeInstall for OpenCode
agent-brain install-agent --agent codexInstall for Codex (+ AGENTS.md)
agent-brain install-agent --agent cursorInstall for Cursor
agent-brain install-agent --agent grokInstall for Grok Build
agent-brain install-agent --agent skill-runtime --dir <path>Install for any skill-based runtime
agent-brain install-agent --agent <runtime> --dry-runPreview installation
agent-brain install-agent --agent <runtime> --globalInstall globally

Other Commands

CommandDescription
agent-brain uninstallRemove all global Agent Brain data and stop running servers

Environment Variables

Server (agent-brain-server/.env)

VariableRequiredDefaultDescription
OPENAI_API_KEYYes-OpenAI API key for embeddings
ANTHROPIC_API_KEYYes-Anthropic API key for summarization
EMBEDDING_MODELNotext-embedding-3-largeOpenAI embedding model
CLAUDE_MODELNoclaude-haiku-4-5-20251001Claude summarization model
API_HOSTNo127.0.0.1Server host
API_PORTNo8000Server port
DEBUGNofalseDebug mode
AGENT_BRAIN_STATE_DIRNo-Override state directory for multi-instance
AGENT_BRAIN_MODENoprojectInstance mode: 'project' or 'shared'
AGENT_BRAIN_STRICT_MODENofalseFail on critical validation errors
AGENT_BRAIN_STORAGE_BACKENDNo-Override YAML storage config ('chroma' or 'postgres')

CLI

VariableDescription
AGENT_BRAIN_URLServer URL (default: http://127.0.0.1:8000)

Security Notes

  • Never commit .env files or API keys
  • .env.example files are safe to commit (no real keys)
  • Check .gitignore excludes all sensitive files

Documentation

  • User Guide - End-user documentation
  • Developer Guide - Development setup
  • API Reference - Full API docs
  • Original Spec - Project specification

Quality Assurance

NEVER PUSH WITHOUT TESTING. NEVER. NOT EVEN "JUST A SMALL CHANGE".

After ANY code changes — no matter how small — you MUST:

  1. Run task before-push and verify it passes with exit code 0
  2. Run task pr-qa-gate before creating or updating PRs
  3. Fix ALL errors before pushing — do not push hoping CI will catch it
task before-push    # MUST pass before ANY push
task pr-qa-gate     # MUST pass before ANY PR

MANDATORY: Any feature or task is not considered done unless task pr-qa-gate passes successfully.

Git Workflow

  • Use conventional commits: feat:, fix:, docs:, test:, refactor:
  • Create feature branches from main
  • MANDATORY: Run task before-push before pushing to any branch
  • PRs will fail CI if code coverage is below 50%

Pre-Push Requirement (MANDATORY — READ THIS)

NEVER PUSH CODE WITHOUT RUNNING task before-push FIRST.

task before-push

This is a mandatory step that ensures:

  1. Code is properly formatted (Black)
  2. No linting errors (Ruff)
  3. Type checking passes (mypy)
  4. All tests pass with coverage report

If it fails, FIX IT. Then run it again. Only push when it passes.

Common failures to watch for:

  • Line too long (>88 chars) — run black to auto-fix
  • Missing type stubs — install with pip install types-XXX
  • Import order — run ruff check --fix to auto-fix

Active Technologies

  • Python 3.10+ + FastAPI, LlamaIndex, ChromaDB, OpenAI, rank-bm25 (100-bm25-hybrid-retrieval)
  • ChromaDB (Vector Store), Local Persistent BM25 Index (LlamaIndex) (100-bm25-hybrid-retrieval)
  • Python 3.10+ + LlamaIndex (CodeSplitter, SummaryExtractor), tree-sitter parsers, ChromaDB (101-code-ingestion)
  • ChromaDB (unified vector store), Disk-based BM25 index (101-code-ingestion)
  • Python 3.10+ + LlamaIndex (CodeSplitter, SummaryExtractor), tree-sitter (AST parsing), OpenAI/Anthropic (embeddings/summaries) (101-code-ingestion)
  • ChromaDB vector store (existing) (101-code-ingestion)
  • Python 3.10+ + FastAPI, uvicorn, Pydantic, Click, ChromaDB, LlamaIndex (109-multi-instance-architecture)
  • ChromaDB (vector), disk-based BM25 index, LlamaIndex persistence (109-multi-instance-architecture)
  • Python 3.10+ + Poetry (packaging), Click (CLI), FastAPI (server) (112-agent-brain-naming)
  • N/A (naming changes only) (112-agent-brain-naming)
  • Python 3.10+ (existing: ^3.10 in pyproject.toml) + FastAPI, LlamaIndex (llama-index-core ^0.14.0), ChromaDB, langextract (new), llama-index-graph-stores-kuzu (optional) (113-graphrag-integration)
  • ChromaDB (vector), disk-based BM25 index (existing), SimplePropertyGraphStore/Kuzu (new graph storage) (113-graphrag-integration)
  • Markdown (Claude Code plugin format) + Claude Code plugin system, agent-brain-cli v1.2.0+, agent-brain-rag v1.2.0+ (114-agent-brain-plugin)
  • N/A (plugin is markdown files only) (114-agent-brain-plugin)
  • Python 3.10+ (existing: ^3.10 in pyproject.toml) + FastAPI, LlamaIndex, Pydantic, httpx (async HTTP), anthropic, openai, google-generativeai (new) (103-pluggable-providers)

Recent Changes

  • 100-bm25-hybrid-retrieval: Added Python 3.10+ + FastAPI, LlamaIndex, ChromaDB, OpenAI, rank-bm25

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.