Have you ever spent two days refining architecture decisions with Claude Code, then closed the terminal and reopened it to find it knows nothing about your project again? You're back to re-explaining directory structure, tech stack, and team conventions from scratch. This isn't a model problem — it's that context persistence has never been properly solved.
Semantica is a long-term memory framework designed specifically for Claude Code in 2026. It lets Claude Code retain codebase understanding, project preferences, and user habits across multiple sessions. This guide walks you through everything from "what is Semantica" to "how to configure it end to end," with pitfall notes and Cloud Mac recommendations you can follow directly.
1. What Is Semantica
Semantica is a persistent memory middleware designed for AI coding assistants. It open-sourced in Q1 2026 and quickly gained traction in the Claude Code community. The core idea: rather than relying on the model's context window to "remember things," Semantica maintains a structured memory database outside the model, and at the start of each session automatically retrieves the most semantically relevant memory fragments to inject.
Architecturally, Semantica has three components:
- Memory Store: The underlying persistent storage. Defaults to Postgres + pgvector (Qdrant and Weaviate are also supported)
- Memory Manager: Handles memory writes, deduplication, merging, and expiration
- Retrieval Engine: Semantically retrieves the most relevant memories at each session start and builds the injection prompt
For Claude Code, Semantica hooks into the PreToolUse, PostToolUse, and Stop events via the hooks mechanism, automatically handling memory reads and writes — no changes to native Claude Code configuration required.
2. Claude Code's Memory Problem
Claude Code has no built-in cross-session memory. The officially recommended CLAUDE.md file is a workaround — write project notes there and they load automatically each session. But CLAUDE.md has clear limitations:
- Full load, no relevance filtering: Regardless of the current task, the entire CLAUDE.md consumes tokens
- Static, no automatic updates: New project decisions, bug-fix history, and user preferences don't accumulate automatically
- No personalization: Different developers' habits and preferences can't be stored separately
- Single node: In team collaboration, memories accumulated by developer A aren't visible to developer B
Semantica addresses all four of these: semantic retrieval (only relevant fragments injected), automatic writes (sessions auto-summarize new memories on end), multi-user namespaces, and team memory sync via a shared Memory Store.
3. The Three-Tier Memory Model
Semantica draws on cognitive science memory tiers, dividing Claude Code memory into three layers:
Short-Term Memory
The current session's context window. This is managed natively by Claude Code; Semantica doesn't intervene but extracts valuable fragments to write into long-term memory when the session ends.
Working Memory
Temporary state related to the current task — for example, "currently refactoring the auth module" or "got stuck on JWT refresh logic last time." Working memory lives longer than a session (spanning days-long tasks) but shorter than long-term memory (archived when the task is done). Semantica uses a lightweight task_context table to maintain working memory; it has highest priority and is always injected during retrieval.
Long-Term Memory
Persistent project knowledge and user preferences, including:
| Memory Type | Example Content | Suggested TTL |
|---|---|---|
| Codebase knowledge | "auth module uses Passport.js; JWT TTL is 15 minutes" | Permanent (auto-updated with code changes) |
| Architecture decisions | "Database is Postgres; no ORMs allowed" | Permanent |
| User preferences | "code comments in English"; "prefer Result type for error handling" | Permanent |
| Bug history | "Race condition in concurrent Redis writes in July 2026; fixed with distributed lock" | 1 year |
| Task progress | "payment refactor 60% done; webhook handling remaining" | Archive on completion |
4. Integrating with Claude Code
Installation and Initialization
# Install Semantica CLI
npm install -g @semantica/cli
# Initialize in your project root
cd /your/project
semantica init
# Creates .semantica/config.json and .semantica/hooks/
After initialization, the .semantica/ directory looks like:
.semantica/
├── config.json # Main configuration
├── hooks/
│ ├── pre-session.sh # Fires at session start (injects memories)
│ └── post-session.sh # Fires at session end (writes memories)
└── memory/
└── local.db # SQLite for local dev (swap for Postgres in production)
Configuring the Memory Store
Semantica supports three backends — choose based on your use case:
| Backend | Use Case | Config Complexity |
|---|---|---|
| SQLite (local) | Solo local dev, quick validation | Zero config |
| Postgres + pgvector | Team collaboration, Cloud Mac nodes | Low (one docker command) |
| Semantica Cloud | Zero-ops, multi-device sync | Minimal (fill in API key) |
Recommended setup (Postgres + pgvector):
# Start Postgres + pgvector
docker run -d \
--name semantica-db \
-e POSTGRES_PASSWORD=yourpassword \
-e POSTGRES_DB=semantica \
-p 5432:5432 \
pgvector/pgvector:pg16
# .semantica/config.json
{
"memory_store": {
"backend": "postgres",
"connection_string": "postgresql://postgres:yourpassword@localhost:5432/semantica",
"embedding_model": "text-embedding-3-small",
"vector_dimensions": 1536
}
}
Share a Postgres instance on Cloud Mac
On Vuncloud Cloud Mac, run Postgres on one dedicated node and connect other development machines to the same Memory Store over the internal network. Team memories are automatically shared — no extra sync steps needed.
Configuring the Retrieval Layer
The Retrieval layer controls how many memories are injected each session and how they are ranked. Key parameters:
{
"retrieval": {
"top_k": 15,
"similarity_threshold": 0.72,
"recency_weight": 0.3,
"relevance_weight": 0.7,
"max_tokens": 2000,
"namespace": "project:my-app"
}
}
top_k: Max memories retrieved per session. 10–20 recommended; too many dilutes signal-to-noisesimilarity_threshold: Semantic similarity cutoff; memories below this aren't injected. 0.72 is a good starting valuerecency_weight/relevance_weight: Balance between freshness and relevance. Conversational tasks favor recency; architecture queries favor relevancemax_tokens: Token budget for injected memories — protects your context windownamespace: Memory namespace for isolating by project, user, or environment
Session Persistence
Semantica uses Claude Code's hooks mechanism for session-level memory reads and writes. Add to ~/.claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": ".*",
"hooks": [
{
"type": "command",
"command": "semantica inject --session-id $CLAUDE_SESSION_ID"
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "semantica consolidate --session-id $CLAUDE_SESSION_ID --auto-extract"
}
]
}
]
}
}
semantica inject retrieves relevant memories before each tool call and injects them into the system prompt. semantica consolidate extracts valuable new information at session end and writes it to the Memory Store.
PreToolUse or PreCompact?
If your sessions frequently trigger context compaction, also run semantica inject in a PreCompact hook to ensure important context isn't lost before compression.
5. Configuration Best Practices
After months of real-world use, here are the most effective practices:
-
Tag your memories: Include
tagswhen writing memories, e.g.,["auth", "architecture", "bug-fix"]. Filter by tags during retrieval for much higher precision.semantica add "JWT refresh token TTL shortened from 7d to 24h after security audit" \ --tags auth,security --importance high -
Use separate namespaces per project: Prevents project A's memories from contaminating project B's context.
# config.json "namespace": "project:my-saas-backend:v2" -
Compact memories regularly: Merge multiple memories on the same topic to reduce redundant injections.
semantica compact --namespace project:my-saas-backend:v2 --dry-run -
Manually add important decisions: Auto-extraction is good at "what was done," not "why it was done that way." For architecture decisions and tech choices, use
semantica addmanually with full context and rationale. -
Keep
max_tokensconservative: Claude Code's context window is finite. Limit injected memories to 1,500–2,000 tokens; preserve the remainder for the actual task.
6. Common Pitfalls
Pitfall 1: Hardcoded hook paths break cross-machine setups
If the command in settings.json uses an absolute path like /Users/noah/.nvm/bin/semantica, the hook silently fails on other machines. Use npx semantica or ensure semantica is on PATH.
Pitfall 2: Vector dimension mismatch
Switching embedding models (e.g., from text-embedding-3-small to text-embedding-3-large) causes old memories with different vector dimensions to return errors or empty results. Run semantica migrate --reembed to regenerate vectors, or clear and rebuild.
Pitfall 3: Low similarity_threshold injects noise
Below 0.60, stale memories barely related to the current task get injected and actually disrupt Claude Code. Start at 0.72 and tune from there based on real results.
Pitfall 4: Duplicate consolidate writes
If the Stop hook fires multiple times (Claude Code sometimes emits multiple Stop events), the same session's memories get written repeatedly. Add the --idempotent flag to the consolidate command; Semantica will deduplicate automatically.
7. Semantica vs. Mem0 vs. Zep
| Framework | Design Focus | Claude Code Integration | Self-hosting | Best For |
|---|---|---|---|---|
| Semantica | Built for AI coding assistants | Native hooks, zero config | Postgres / SQLite | Claude Code long-term memory |
| Mem0 | General-purpose AI memory layer | Manual SDK integration | Yes (OSS) | General AI apps, chatbots |
| Zep | Conversation history + fact extraction | Manual SDK integration | Yes (OSS) | Multi-turn dialogue, CRM-style apps |
Decision guide:
- Primary tool is Claude Code → Semantica; lowest integration cost
- Need shared memory across multiple AI tools (Claude Code + custom agents) → consider Mem0 (more universal API)
- Main need is conversation summarization and fact extraction → Zep is more mature here
8. Advantages on Cloud Mac
The biggest problem with running Semantica locally is: shutdown = disconnect. The Postgres service backing the Memory Store stops when your laptop sleeps, requiring a restart on the next boot — breaking the continuity that makes long-term memory useful.
Vuncloud Cloud Mac offers clear advantages here:
- 24/7 uptime: Memory Store nodes run continuously, unaffected by shutdown
- Multi-node sharing: Multiple Cloud Mac machines connect to one Postgres instance; memories sync automatically
- Fixed IP / internal network: Configure
connection_stringonce and it stays valid across all sessions permanently - SSD persistence: 1TB/2TB additional storage options let you keep the memory database off the system disk
- CI/CD integration: After a CI build, automatically write new architecture changes to Semantica so Claude Code picks them up next development session
Recommended Cloud Mac deployment: run a dedicated node with Postgres + pgvector (docker compose up -d), with other development nodes connecting via internal IP. Mount the Memory Store to an additional storage volume, decoupled from the system image — data survives node resets.
Need a stable environment for Claude Code + Semantica?
Cloud Mac runs 24/7 so your Memory Store never goes offline. One dedicated M4 node runs Postgres; other development machines share the same long-term memory. Ideal for solo developers and small teams.
View Cloud Mac Plans · 2026 AI Agent Memory Framework Comparison
FAQ
What is the difference between Semantica and CLAUDE.md?
CLAUDE.md is a static project description loaded in full every session. Semantica is a dynamic memory system that semantically retrieves only the most relevant memory fragments, saving tokens and enabling personalization. The two aren't mutually exclusive — use CLAUDE.md for fixed project standards and Semantica for dynamic task progress and user preferences.
Is Semantica free?
The core SDK is open-source and free. The hosted Memory Store offers a free tier (~100,000 memories/month) with pay-as-you-go beyond that. Self-hosting with Postgres/pgvector is completely free.
Where is memory data stored? Is it secure?
By default, data is hosted on Semantica Cloud (SOC 2 certified). You can configure self-hosted Postgres + pgvector so data never leaves your network, ideal for teams with strict code confidentiality requirements.
Will memories be lost when Claude Code restarts?
Not with Semantica. Memories are written to the Memory Store (a persistent database). The next session automatically retrieves and injects them via hooks, fully decoupled from the session lifecycle.
What are the advantages of running Semantica on Cloud Mac?
Cloud Mac nodes run 24/7, so the Memory Store never goes offline from shutdown. Multiple nodes can share one Postgres instance for automatic team memory sync. Cross-session persistence requires no local disk mounting.
Conclusion
Claude Code's "amnesia" problem is fundamentally about context persistence — models keep getting smarter, but every session still starts from zero. Semantica offers a practically deployable engineering solution: externalize memory to a persistent database, replace full loads with semantic retrieval, and integrate via hooks with zero code changes.
Configuration checklist:
- Choose Postgres + pgvector for Memory Store — balances performance with self-hosting flexibility
- Start with defaults:
top_k=15,similarity_threshold=0.72; tune after a week of real use - Register hooks in both Stop and PreCompact to prevent memory loss during context compaction
- Manually add important architecture decisions — don't rely solely on auto-extraction
- Cloud Mac users: run Postgres on a dedicated node with additional storage mounted; decouple the memory store from the system disk
Related Articles
- Best AI Agent Memory Frameworks in 2026
- Best AI Coding Tools Ranked 2026
- Does CLAUDE.md Work? Testing Karpathy Skills on 10 Real Tickets
- How I Cut My Claude Code Bill from $800 to $150
Framework versions and APIs subject to official Semantica documentation. Last updated: August 11, 2026.