totem-mcp
A totem stands watch over what a tribe has learned. Totem does the same for a codebase. It's a Git-aware memory server for coding agents: decisions, invariants, and gotchas persist across sessions, backed by evidence, and flagged the moment the code underneath them changes.
Why
AI coding agents lose engineering context between sessions. They re-discover the same gotchas, re-debate the same decisions, and forget invariants that were already established. totem persists this knowledge locally and serves it back to agents as structured context, ordered by relevance.
Install
Requires Python 3.13+.
npm install @emiliano-go/totem
npx @emiliano-go/totemThe npx command auto-installs or upgrades the Python MCP server, pins its version, and configures enforcement plugins for OpenCode, Claude Code, and Kimi Code. For Kimi Code it also registers a user-level MCP entry (~/.kimi-code/mcp.json) so totem is available in every project.
Supported agents
Agent | Hook type | Auto-configured? |
OpenCode |
| Yes |
Claude Code |
| Yes |
Kimi Code |
| Yes |
Features
14 memory types with type-specific metadata validation
31 MCP tools (16 core + 15 typed wrappers)
Staleness detection via SHA256 content hashing on evidence
Conflict detection on overlapping evidence and contradictory claims
Full-text search via Turso FTS5
Hybrid memory (project + user databases)
Context assembly with scored pipeline and token budget
Agent enforcement blocks reads/grep/bash when memory exists, forces search-first workflow
Commit gates block all tools until agent registers file reads and writes
History audit on every create, update, and delete
How it works
Agent reads file for the first time
→ commit-gate blocks → agent registers read → memory stored → done
Agent reads file again (memory exists)
→ blocked → redirected to memory tools
→ searches memory → finds context → done
Agent writes a file
→ commit-gate blocks → agent registers write with reason → change documented → done
Agent reads file but finds nothing in memory
→ allowed to read → commit-gate requires registration → doneSetup
OpenCode
Add to ~/.config/opencode/opencode.json (or let npx @emiliano-go/totem write it):
{
"plugin": ["@emiliano-go/totem"],
"mcp": {
"totem": {
"type": "local",
"command": ["uvx", "totem-mcp==<version>"],
"enabled": true
}
}
}The installer pins <version> to the npm package version and pre-warms the uvx cache, so agent startups use the cached environment and never hit the network.
Claude Code
claude mcp add totem -- totem-mcpKimi Code
MCP server and hooks are auto-configured by npx @emiliano-go/totem: the MCP server goes in user-level ~/.kimi-code/mcp.json (every project), and the hooks go in ~/.kimi-code/config.toml.
Manual setup
If you prefer manual configuration:
# Initialize totem in your project
totem init
# For a different project
totem init --project /path/to/otherQuick start
MCP tools (from your agent)
# Store a decision
memory_create_tool(type="decision", title="Use FTS5 for search",
statement="SQLite FTS5 is sufficient for our search needs",
tags=["search", "sqlite"],
metadata={"rationale": "No external dependency needed"})
# Get full context for a task
engineering_context_tool(tags=["api", "database"],
current_task="Adding JWT refresh endpoint")
# Search memory
memory_search_tool(query="authentication", tags=["auth"])
# Store a command outcome
memory_create_tool(type="gotcha", title="uv pip install -e . works",
statement="Editable install works with uv pip on PEP 668 systems",
tags=["cmd:uv-pip-install", "python"])CLI
# Create a memory item
totem create --type decision --title "Use FTS5 for search" \
--statement "SQLite FTS5 is sufficient for our search needs" \
--tags "search,sqlite" --metadata '{"rationale": "No external dependency needed"}'
# Search
totem search --query "FTS5" --tags "sqlite"
# Assemble context
totem context --tags "search,sqlite" --current-task "Implementing search" --budget 4096
# Export/import
totem export -o backup.json
totem import backup.jsonMemory types
Type | Purpose | Required metadata |
| A choice that was made |
|
| A rule that must hold |
|
| A non-obvious pitfall | (none) |
| A proposal declined |
|
| A claim with epistemic status |
|
| An unresolved question |
|
| An ambiguous requirement |
|
| Observable behavior |
|
| Implementation restriction |
|
| Plausible explanation |
|
| Something seen in code |
|
| A defect with state machine |
|
| Component mapping |
|
| Codebase facts |
|
MCP tools (31)
Tool | Description |
| Initialize totem for a project |
| Create a memory item (warns on duplicate title) |
| Retrieve by ID with staleness check |
| Update any field (provides audit trail) |
| Soft-delete (requires |
| Filtered listing with sort and type/tag filters |
| List recently created memories |
| List in-progress task memories ( |
| List command outcomes ( |
| FTS5 full-text search with type/tag filters |
| Mark conflict as resolved |
| Scored context assembly with task relevance |
| Export all memories as JSON |
| Import memories from JSON (skips duplicates) |
| Store facts learned from reading a file (auto-hashes) |
| Register file changes with reason (auto-hashes) |
| Typed wrappers for each memory type |
| Convenience wrapper for ambiguity creation |
CLI commands (14)
Command | Description |
| Initialize totem and install agent instructions |
| Create a new memory item |
| Retrieve by ID |
| Update an item |
| Soft-delete (requires |
| List with filters |
| List recently created memories |
| List in-progress task memories |
| List command outcomes |
| Mark conflict as resolved |
| Full-text search |
| Export memories as JSON |
| Import memories from JSON |
| Assemble scored context |
Context assembly
Scoring formula:
score = 0.30*tag_match + 0.20*task_similarity + 0.25*importance
+ 0.15*confidence + 0.10*recencyInvariants, constraints, and ambiguities get a 1.25x multiplier. Potentially stale items get a 0.5x penalty.
Output sections (BLOCKING AMBIGUITIES, CONFLICTS, and STALE WARNINGS are never budget-truncated):
TASK (if provided)
BLOCKING AMBIGUITIES
CONTEXT CONFLICTS
CRITICAL CONSTRAINTS
CRITICAL INVARIANTS
RELEVANT CONTRACTS
ARCHITECTURE
DECISIONS
KNOWN AMBIGUITIES (non-blocking)
OBSERVATIONS
GOTCHAS
KNOWN BUGS
HYPOTHESES
CODEBASE FACTS
OPEN QUESTIONS
REJECTED IDEAS
STALE KNOWLEDGE WARNINGS
Workspace scoping
totem auto-detects your project root via git rev-parse --show-toplevel. Override with --project <path> on any CLI command or project parameter on any MCP tool.
Hybrid memory
Project memories:
.totem/totem.dbUser memories:
~/.local/share/totem/totem.db
engineering_context searches both, with project memories taking precedence.
Tag conventions
task:<name>: In-progress work. Query withmemory_tasks_tool.cmd:<command>: Command outcomes. Query withmemory_commands_tool.architecture:<module>: Structural facts about a module.outcome:<what>: Measurable results (performance wins, bug fix impact, etc.).
Companion skill
The skills/precision-first/ directory contains a precision-first software engineering methodology designed to pair with totem.
Development
# Run JS tests
cd plugins/totem-enforce && node test-tokenize.js
# Run Python package tests
uv run pytest
# Run Python hook tests
cd plugins/totem-enforce && python3 test-enforce.pyLicense
MIT