v2.24.3 · Technical Architecture

How Monomind
Is Actually Built

A 9-package monorepo that adds a code knowledge graph, persistent memory, a picker and standing agent teams to the AI coding tools you already use. Every number below was checked against the v2.24.3 source and its generated doc counts, not carried over from an old design.

9Packages
38CLI Commands
39Org Subcommands
19Agent Runners
198MCP Tools (full)

Architecture

System Overview

Your coding tool talks to the CLI package over MCP, a hand-rolled stdio JSON-RPC loop. The CLI loads the other packages as it needs them. Most are libraries, not always-running services.

CLAUDE CODE · OPENCODE · ANTIGRAVITY · KIMI CODE · CODEXMCP over stdio JSON-RPC ↔ @monoes/monomindcli (packages/@monomind/cli/)@monoes/monomindcli38 commands · org runtime · loads the packages below@monoes/hooksRegistry + 9 workers@monoes/memorySQLite + local embeddings@monoes/monographtree-sitter + SQLite graphmonofence-ailocal manipulation scanner.monomind/metrics/worker JSON outputsmemory.db (SQLite)memories · Second Brain · memory graph.monomind/monograph.dbnodes · edges · communitiesAlso: @monoes/mcp (http/ws) · @monoes/routing (legacy) · @monoes/monobrowse (CDP) · @monoes/monodesignorg roles run on up to 19 agent runners, from Claude in-process to subprocess CLIs

Modules

9 Packages

Six live under packages/@monomind/ (cli, hooks, mcp, memory, monograph, routing) and publish under the @monoes/ npm scope. Two live under packages/@monoes/ (monobrowse, monodesign), and monofence-ai is unscoped. Users install the monomind umbrella.

⌨

CLI Entry Point

@monoes/monomindcli

packages/@monomind/cli/

The published CLI engine, installed through the monomind umbrella. 38 top-level commands, the MCP server, init, doctor, the org runtime and the local dashboard. Its stdio JSON-RPC loop is hand-rolled, so the default transport needs no separate MCP process.

38 commandsstdio JSON-RPCorg runtime
🪝

Hooks & Workers

@monoes/hooks

packages/@monomind/hooks/

Typed HookEvent registry and executor plus a WorkerManager for 9 on-demand workers. Claude Code reaches it through the .claude/helpers handlers; if the package is not built, the hook quietly does nothing.

20 HookEvent types9 workersregistry + executor
🔌

MCP Framework

@monoes/mcp

packages/@monomind/mcp/

Standalone MCP framework for the http and websocket transports, with a connection pool and tool registry. It is an optional peer: the default stdio server inside the CLI does not need it.

http / websockettool registryoptional peer
💾

Memory Backend

@monoes/memory

packages/@monomind/memory/

SQLite memory store (better-sqlite3, sql.js WASM fallback) with embeddings, a pure-JS HNSW index and the JSON pattern store. The CLI's memory bridge calls it. LanceDB was removed in v2.3.1, dropping about 600 MB of native dependencies.

SQLitelocal embeddingsHNSW at scale
🗺

Knowledge Graph

@monoes/monograph

packages/@monomind/monograph/

Tree-sitter and SQLite code graph in .monomind/monograph.db. 14 grammar modules cover 25 file extensions, 5 regex extractors cover Scala, Lua, Zig, PowerShell and Elixir. FTS5 search, Louvain communities and incremental builds. 19 default tools, 27 more behind MONOGRAPH_MCP_ADVANCED=1.

14 grammars46 toolsgraph-neighbour rerank
🔀

Legacy Routing

@monoes/routing

packages/@monomind/routing/

The older semantic RouteLayer behind route semantic, now deprecated in favour of pick. Jev picker, keyword rules, embeddings in an isolated worker, then a Haiku fallback.

deprecatedout-of-process embeddings
🌐

Browser Automation

@monoes/monobrowse

packages/@monoes/monobrowse/

Chrome DevTools Protocol client with no Playwright, Puppeteer or Selenium dependency. Powers monomind browse and the agent-browser-testing workflow.

native CDPno external binary
🎨

Design Intelligence

@monoes/monodesign

packages/@monoes/monodesign/

Design tokens, antipattern detection and the monodesign skill, exposed over MCP as monodesign_detect, monodesign_fix and monodesign_palette.

design tokensantipattern detection
🛡

Manipulation Defense

monofence-ai

packages/monofence-ai/

Local defense against prompt manipulation: an input cap, an evasion normaliser, 50+ patterns across 9 threat categories, multi-turn escalation tracking and an output scanner. Loads on first use from ~/.monomind/deps, pinned and hash-checked.

localpinned + hash-checkedoutput scanner

Memory

Local SQLite, Not a Vector Cloud Service

Several mechanisms share the word memory in this codebase. Here is what each one actually is, and where the Second Brain fits.

01

A local SQLite store, not a cloud vector DB

better-sqlite3 is primary, sql.js WASM is the fallback. The file is memory.db under ~/.monomind/projects/<name>-<hash>/ (the folder keeps its old lancedb name for path compatibility). Embeddings run locally with gte-modernbert-base (768 dimensions, about 90 MB, downloaded once). LanceDB was removed in v2.3.1.

02

The Second Brain lives in the same store

Document chunks are rows in knowledge:<scope> namespaces: 22 file types, chunked at 3,200 characters with 400 overlap, deduplicated by SHA-256. knowledge_search fuses chunks, the knowledge graph, rules and memory with reciprocal-rank fusion over dense and BM25 retrieval. A personal global brain at ~/.monomind/global-brain is merged into every search.

03

A memory knowledge graph on top

memory_kg_ingest, memory_kg_search, memory_kg_stats and memory_kg_rollback keep entities and relations in the same database, and memory_feedback records whether a recalled item helped. Ingesting a document does not add it to the graph.

04

HNSW only kicks in at scale

Search is brute-force cosine similarity below 100,000 embedded entries (MONOMIND_HNSW_THRESHOLD). Above that an HNSW index builds automatically, is cached next to the SQLite file and is reused until entries change. --build-hnsw forces an early build.

05

JSON files still feed hooks and episodes

Hook learning keeps auto-memory-store.json (capped at 200 entries) and episodic/episodes.jsonl for episodic recall. These are separate from the SQLite store, so the word memory covers SQLite, the memory graph, these JSON files and Monograph.

Picking

Pick First, Route Only If Needed

Choosing the right specialist is a ranking problem, not a model call. The picker does it locally, and the older semantic router is deprecated.

1
monomind pick ranks agents and skills

One index of 83 agents, 82 skills and 560 Org skills, scored with BM25 keyword ranking and an optional Jev decision model. History can re-rank near-ties by at most 15 percent; nothing is learned by reinforcement.

↓
2
The prompt hook injects a [PICK] line

The best-fit agent and skill land in the model's context before it answers. The pick MCP tool returns the same ranking on request, and org_skill_show loads an Org skill.

↓
3
Bare monomind route "task" runs pick

The old keyword-only stub is gone. route and route task now print the output of monomind pick --agents.

↓
4
The semantic RouteLayer is deprecated

route semantic, hooks_route_semantic and agent spawn --task still run Jev, 24 regex rules, keyword ranking, embeddings in an isolated worker (Snowflake arctic-embed-xs, about 88 MB, downloaded only on request, with a hash-encoder fallback) and then a Haiku call. Outcomes go to route-outcomes.jsonl, read by route stats and doctor -c pick.

Hook System

Two Different Things Called “Hooks”

28 CLI subcommands and 20 typed registry events are different mechanisms that share a name, with 9 on-demand workers underneath both.

28 hooks CLI subcommands

  • pre-edit / post-edit, pre-command / post-command, pre-task / post-task
  • session-end, session-restore, notify (session-start is deprecated)
  • route (through the keyword picker), explain, pretrain, transfer, metrics
  • intelligence (train, patterns, predict, optimize, export, import)
  • worker, statusline, list, coverage-route, coverage-suggest, coverage-gaps
  • model-route, model-outcome, model-stats; pre-bash and post-bash are aliases

20 typed HookEvent values

  • A lower-level mechanism in @monoes/hooks: PreToolUse, PostToolUse, PreEdit, PostEdit, PreRead, PostRead, PreCommand, PostCommand, PreTask, PostTask, TaskProgress, SessionStart, SessionEnd, SessionRestore, AgentSpawn, AgentTerminate, PreRoute, PostRoute, PatternLearned, PatternConsolidated.
  • These are registry event types, not CLI subcommand names. The live .claude/helpers path bridges into this package.

9 on-demand workers

  • health · ddd · security · cache · progress · map · audit · consolidate · reflexion
  • They run at session start and refresh when their output is missing or older than 6 hours.

How hooks reach each tool

  • Claude Code: settings.json drives .claude/helpers/hook-handler.cjs, which dispatches to handlers (pick, router, session, memory, intelligence) and lazily imports @monoes/hooks.
  • OpenCode: .opencode/plugins/monomind-hooks.ts runs the pre-bash and pre-write gates in tool.execute.before.
  • Kimi Code: plugin/hooks/monomind-gate.mjs bridges the PreToolUse event to the same gates.

Runtimes

Five Tools In, Nineteen Runners Out

Monomind plugs into the coding tool you already use, and its org roles can run on a different set of agent runtimes through one protocol.

Init targets

5 coding tools

monomind init detects Claude Code, Antigravity, OpenCode, Kimi Code and Codex on your machine and sets up only those. MCP entries are pinned to the installed version.

Org role runners

19 runners

Claude and the Vercel AI SDK run in-process. The other 17 are subprocess CLIs: Codex, agy, Kimi Code, OpenCode, Grok, Qwen, Crush, Copilot, Pi, Hermes, Cline, Aider, DSH, Kilo and Freebuff.

Mixed teams

Per-role runtime

A role's runtime beats the org's runtime, which beats MONOMIND_RUNTIME, so one org can mix Claude, Codex and local models.

Agent exec protocol

v1, rev 29

Capability handshake, NDJSON events, --access scoped|read|full, --sandbox modes, --effort off..max, --resume, --budget-usd. Unknown cost is null, not 0.

What `monomind init` writes for each tool
Claude Code
.claude/ (helpers, settings, skills), .mcp.json, CLAUDE.md
Antigravity (agy)
GEMINI.md, .gemini/rules/monomind.md, .gemini/settings.json, a .gemini/helpers mirror and a statusline
OpenCode
opencode.json, .opencode/{agent,command,skills,plugins}, a /monomind-status command, AGENTS.md
Kimi Code
.kimi-code/{mcp.json,agents,skills}, a plugin with commands and the gate hook, AGENTS.md
Codex
.codex/config.toml (loaded for trusted projects only), AGENTS.md, .agents/skills/
  • -Kilo is full-access only and Freebuff is a discovery stub with no headless transport. Both are refused in sections orgs.
  • -Runtimes other than Claude and Vercel receive org tools as text and are capped at 10 tool rounds per message by default.
  • -Codex, agy, Kimi Code, Vercel, Hermes, Qwen and DSH do not report cost, so budget_usd cannot close those roles.

Org Runtime

SDK-Backed Agent Orgs

monomind org run replaced the old prompt-orchestrated path. Each role is a live agent session with a budget, a policy and an approval path, not a scripted prompt loop.

Runtime

SDK-backed daemon

monomind org run/serve. Claude roles are live in-process Agent SDK sessions; other runtimes run as subprocess CLIs.

Subcommands

39

run, stop, pause, resume, reload, status, serve, logs, events, costs, inbox, approvals, gates, replay, branch, decisions, create, validate, sign, role and more.

Inter-agent channel

org_send / mailbox

Roles message each other with org:role addresses. ask_human queues a question, and org_recall, org_remember and org_learn keep cross-run memory.

Tasks

Dependency DAG

org_task, org_plan_graph and org_task_done. Ready tasks dispatch on their own, summaries are capped, and typed briefs and context packets are opt-in.

Config

.monomind/orgs/<name>.json

A zod schema: goal, schedule, run_config (1M token budget, 4 concurrent agents, verify_writes and lead_watch on by default) and per-role policy. Sections and documents are generally available.

Signed definitions

org sign

The operator HMAC-signs a definition and it is checked on run, serve, resume and reload. The key lives outside every role's sandbox, and an unsigned change is refused.

Checks and audit

One checklist

validate, run, reload, create and the dashboard share the same caveat checks. Skipped scheduled ticks are written to schedule-audit.jsonl.

Dashboard

monomind ui

Now, Sessions, Projects, Orgs, Monograph and Documents tabs on 127.0.0.1:4242, behind a token. Loopback only.

Security and Trust

What Is Protected, and What Is Not

Monomind keeps its own state on your machine, but the AI tools it drives talk to their model providers. These are the guarantees as the docs state them, limits included.

01

The scanner is local, and its gate fails open

monofence-ai sends no user data anywhere. In Claude Code the deterministic destructive-command and secrets gates fail closed, but the monofence layer fails open when the package is missing, slow or errors, so it is a safety net, not a guarantee. MONOMIND_MONOFENCE_GATE=off disables it.

02

Coder mode is full access, and it says so

--access full is human-CLI-only, refuses root, needs an explicit --cwd and writes an audit line per turn. The docs state the limits: full access is not a sandbox, fetched web content is not filtered, and background jobs can outlive a stop.

03

Org sandboxes are opt-in and fail closed

policy.sandbox can deny a role exec (denyExec), reads (denyRead) and writes to $HOME (homeWriteAllow) inside a bubblewrap layer that fails closed without bubblewrap. Claude roles also get a hard budget_usd stop. A plain agent exec is not sandboxed by default.

04

What stays local, and what does not

Memory, the code graph, the document index and org state stay on your machine. The AI tools Monomind drives send prompts and code, including recalled memory, to their model providers. Monomind's own calls are the embedding download, first-use installs of the Claude SDK and Chrome, update checks and dashboard CDNs. MONOMIND_NO_AUTO_INSTALL=1 stops the installs.

05

Local models for org roles, not fully offline

Ollama, llama.cpp and LM Studio work for org roles through an OpenAI-compatible endpoint. That is not the same as fully offline: embeddings need a one-time download, the Claude SDK installs on first use, tool calling is weaker on small models and cost shows as $0.

Honesty Notes

What We Won’t Overclaim

A short list of things that are easy to overstate. We would rather say them plainly here than have you find out later.

  • -Monoswarm and autopilot were removed in v2.22.0, including the swarm topologies and vote counting. No consensus feature remains. Coordination is Claude Code's Task tool or monomind org run.
  • -The semantic RouteLayer is deprecated and bare monomind route now runs pick. New routing work goes through the picker.
  • -HNSW is automatic above 100,000 embedded entries, not before. Below that, search is brute-force cosine similarity.
  • -The former @monomind/security package was deleted. Input validation lives in packages/@monomind/cli/src/utils/input-guards.ts, and manipulation scanning lives in monofence-ai.
  • -The monofence layer of the pre-bash and pre-write gates fails open on purpose. The deterministic gates are the ones that fail closed.
  • -Full access (--access full) is not a sandbox, and a signing key can be read by a role that has no sandbox and no bubblewrap mask.
  • -We cite the pattern count (50+ across 9 categories) as the docs state it. We have not independently counted individual rules.