MCPcopy
hub / github.com/letta-ai/claude-subconscious

github.com/letta-ai/claude-subconscious @v2.1.1 sqlite

repository ↗ · DeepWiki ↗ · release v2.1.1 ↗
117 symbols 299 edges 14 files 40 documented · 34%
README

[!IMPORTANT] Claude Subconscious is demo app built using the Letta Code SDK, and is not intended to be used in production.

If you want to use a coding agent that runs background subconscious agents, use Letta Code, which is also fully open source.

Install the Letta Code CLI with npm install -g @letta-ai/letta-code, then use letta to launch.

Claude Subconscious

A background agent that whispers to Claude Code. A subconcious agent that watches your sessions, reads your files, builds up memory over time, and whispers guidance back.

evil claude

What Is This?

Claude Code forgets everything between sessions. Claude Subconscious is a second agent running underneath — watching, learning, and whispering back:

  • Watches every Claude Code session transcript
  • Reads your codebase — explores files with Read, Grep, and Glob while processing transcripts
  • Remembers across sessions, projects, and time
  • Whispers guidance — surfaces context, patterns, and reminders before each prompt
  • Never blocks — runs in the background via the Letta Code SDK

Not just a memory layer — a background agent with real tool access that gets smarter the more you use it.

Using Letta's Conversations feature, a single agent can serve multiple Claude Code sessions in parallel with shared memory across all of them.

How It Works

After each response, the transcript is sent to a Letta agent via the Letta Code SDK. The agent reads files, searches the web, updates its memory — then whispers back before the next prompt. Nothing is written to CLAUDE.md.

┌─────────────┐          ┌──────────────────────────┐
│ Claude Code │◄────────►│ Letta Agent (background)  │
└─────────────┘          │                          │
       │                 │  Tools: Read, Grep, Glob │
       │                 │  Memory: persistent       │
       │                 │  Web: search, fetch       │
       │                 └──────────────────────────┘
       │                        │
       │   Session Start        │
       ├───────────────────────►│ New session notification
       │                        │
       │   Before each prompt   │
       │◄───────────────────────┤ Whispers guidance → stdout
       │                        │
       │   Before each tool use │
       │◄───────────────────────┤ Mid-workflow updates → stdout
       │                        │
       │   After each response  │
       ├───────────────────────►│ Transcript → SDK session (async)
       │                        │  ↳ Reads files, updates memory

Installation

Install from GitHub:

/plugin marketplace add letta-ai/claude-subconscious
/plugin install claude-subconscious@claude-subconscious

Updating

/plugin marketplace update
/plugin update claude-subconscious@claude-subconscious

Install from Source

Clone the repository:

git clone https://github.com/letta-ai/claude-subconscious.git
cd claude-subconscious
npm install

Enable the plugin (from inside the cloned directory):

/plugin enable .

Or enable globally for all projects:

/plugin enable --global .

If running from a different directory, use the full path to the cloned repo.

Linux: tmpfs Workaround

If plugin installation fails with EXDEV: cross-device link not permitted, your /tmp is likely on a different filesystem (common on Ubuntu, Fedora, Arch). Set TMPDIR to work around this Claude Code bug:

mkdir -p ~/.claude/tmp
export TMPDIR="$HOME/.claude/tmp"

Add to your shell profile (~/.bashrc or ~/.zshrc) to make permanent.

Configuration

Required

export LETTA_API_KEY="your-api-key"

Get your API key from app.letta.com.

Optional

export LETTA_MODE="whisper"    # Default. Or "full" for blocks + messages, "off" to disable
export LETTA_AGENT_ID="agent-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
export LETTA_BASE_URL="http://localhost:8283"  # For self-hosted Letta
export LETTA_MODEL="anthropic/claude-sonnet-4-5"  # Model override
export LETTA_CONTEXT_WINDOW="1048576"             # Context window size (e.g. 1M tokens)
export LETTA_HOME="$HOME"      # Consolidate .letta state to ~/.letta/
export LETTA_SDK_TOOLS="read-only"       # Or "full", "off"
  • LETTA_MODE - Controls what gets injected. whisper (default, messages only), full (blocks + messages), off (disable). See Modes.
  • LETTA_AGENT_ID - If not set, the plugin automatically imports a default "Subconscious" agent on first use.
  • LETTA_BASE_URL - For self-hosted Letta servers. Defaults to https://api.letta.com.
  • LETTA_MODEL - Override the agent's model. Optional - the plugin auto-detects and selects from available models. See Model Configuration below.
  • LETTA_CONTEXT_WINDOW - Override the agent's context window size (in tokens). Useful when LETTA_MODEL is set to a model with a large context window that differs from the server default. Example: 1048576 for 1M tokens.
  • LETTA_HOME - Base directory for plugin state files. Creates {LETTA_HOME}/.letta/claude/ for session data and conversation mappings. Defaults to current working directory. Set to $HOME to consolidate all state in one location.
  • LETTA_SDK_TOOLS - Controls client-side tool access for the Subconscious agent. read-only (default), full, or off. See SDK Tools.

Modes

The LETTA_MODE environment variable controls what gets injected into Claude's context:

Mode What Claude sees Use case
whisper (default) Only messages from Sub Lightweight — Sub speaks when it has something to say
full Memory blocks + messages Full context — blocks on first prompt, diffs after
off Nothing Disable hooks temporarily

Subconscious never writes to CLAUDE.md in any mode. All content is injected via stdout into the prompt context. If you have an existing CLAUDE.md with <letta> content from an older version, it will be cleaned up automatically.

Agent Resolution Order

  1. Environment variable - LETTA_AGENT_ID if set
  2. Saved config - ~/.letta/claude-subconscious/config.json if exists
  3. Auto-import - Imports bundled Subconscious.af agent, saves ID for future use

This means zero-config setup: just set LETTA_API_KEY and the plugin handles the rest.

Multi-Project Usage

One agent, many projects. The Subconscious agent is stored globally at ~/.letta/claude-subconscious/config.json. When you use the plugin in different repos, they all share the same agent brain.

~/.letta/claude-subconscious/config.json  →  ONE agent ID (shared brain)
                                               ↓
project-a/.letta/claude/                  →  Project A's conversation threads
project-b/.letta/claude/                  →  Project B's conversation threads
project-c/.letta/claude/                  →  Project C's conversation threads

The .letta/claude/ directories in each project are conversation bookkeeping (mapping Claude Code sessions to Letta conversations), not separate agents. Memory blocks are shared across all projects.

To use a different agent per project, set LETTA_AGENT_ID in your shell or via direnv:

# .envrc in project directory
export LETTA_AGENT_ID="agent-xxx-for-this-project"

Model Configuration

The plugin automatically detects available models on your Letta server and configures the agent appropriately:

  1. Queries available models from your Letta server (GET /v1/models/)
  2. Checks if the agent's model is available on that server
  3. Auto-selects a fallback if the current model isn't available

Auto-Selection Priority

When the agent's model isn't available, the plugin selects from available models in this order: 1. anthropic/claude-sonnet-4-5 (recommended - best for agents) 2. openai/gpt-4.1-mini (good balance, 1M context, cheap) 3. anthropic/claude-haiku-4-5 (fast Claude option) 4. openai/gpt-5.2 (flagship fallback) 5. google_ai/gemini-3-flash (Google's balanced option) 6. google_ai/gemini-2.5-flash (fallback) 7. First available model on the server

Manual Override

To specify a particular model, set LETTA_MODEL:

export LETTA_MODEL="anthropic/claude-sonnet-4-5"

The model handle format is provider/model. Common options:

Provider Example Models
openai gpt-5.2, gpt-5-nano, gpt-4.1-mini
anthropic claude-sonnet-4-5, claude-opus-4-5, claude-haiku-4-5
google_ai gemini-3-flash, gemini-2.5-flash, gemini-2.5-pro
zai glm-5 (Letta Cloud default, free)

If LETTA_MODEL is set but not available on the server, the plugin will warn you and fall back to auto-selection.

The default bundled agent uses zai/glm-5 (free on Letta Cloud). For better tool usage and reasoning, consider switching to a stronger model. You can change the model at any time via the Agent Development Environment (ADE) or by setting LETTA_MODEL.

Note: Ensure your Letta server has the appropriate API key configured for your chosen provider (e.g., OPENAI_API_KEY for OpenAI models).

Default Subconscious Agent

When no agent is configured, the plugin auto-imports a bundled "Subconscious" agent designed specifically for this use case.

What It Does

The default agent is a background agent that:

  • Reads your code — uses Read, Grep, and Glob to explore your codebase while processing transcripts
  • Learns your preferences from corrections, explicit statements, and patterns
  • Tracks project context — architecture decisions, known gotchas, pending items
  • Provides guidance via the <letta_message> block when it has something useful
  • Searches the web — can look things up to augment its context

Memory Blocks

The default agent Subconscious maintains 8 memory blocks:

Block Purpose
core_directives Role definition and behavioral guidelines
guidance Active guidance for the next session (syncs to Claude Code before each prompt)
user_preferences Learned coding style, tool preferences, communication style
project_context Codebase knowledge, architecture decisions, known gotchas
session_patterns Recurring behaviors, time-based patterns, common struggles
pending_items Unfinished work, explicit TODOs, follow-up items
self_improvement Guidelines for evolving memory architecture over time
tool_guidelines How to use available tools (memory, filesystem, web search)

If you set an alternative agent using LETTA_AGENT_ID, your agent will use its existing memory architecture.

Communication Style

Subconscious is configured to be:

  • Observational - "I noticed..." not "You should..."
  • Concise - Technical, no filler
  • Present but not intrusive - Empty guidance is fine; it won't manufacture content

Two-Way Communication

Claude Code can address the Subconscious agent directly in responses. The agent sees everything in the transcript and may respond on the next sync. It's designed for ongoing dialogue, not just one-way observation.

Hooks

The plugin uses four Claude Code hooks:

Hook Script Timeout Purpose
SessionStart session_start.ts 5s Notifies agent, cleans up legacy CLAUDE.md
UserPromptSubmit sync_letta_memory.ts 10s Injects memory + messages via stdout
PreToolUse pretool_sync.ts 5s Mid-workflow updates via additionalContext
Stop send_messages_to_letta.ts 120s Spawns SDK worker to send transcript (async)

SessionStart

When a new Claude Code session begins: - Creates a new Letta conversation (or reuses existing one for the session) - Sends session start notification with project path and timestamp - Cleans up any legacy <letta> content from CLAUDE.md - Saves session state for other hooks to reference

UserPromptSubmit

Before each prompt is processed: - Fetches agent's current memory blocks and messages - In full mode: injects all blocks on first prompt, diffs on subsequent prompts - In whisper mode: injects only messages from Sub

PreToolUse

Before each tool use: - Checks for new messages or memory changes since last sync - If updates found, injects them via additionalContext - Silent no-op if nothing changed

SDK Tools

By default, the Subconscious agent now gets client-side tool access via the Letta Code SDK. Instead of being limited to memory operations, Sub can read your files, search the web, and explore your codebase while processing transcripts.

Configuration via LETTA_SDK_TOOLS:

Mode Tools Available Use Case
read-only (default) Read, Grep, Glob, web_search, fetch_webpage Safe background research and file reading
full All tools (Bash, Edit, Write, Task, etc.) Full autonomy — Sub can make changes and spawn sub-agents
off None (memory-only) Listen-only — Sub processes transcripts but has no client-side tools

In full mode, Sub can spawn sub-agents via the Task tool — dispatching parallel research or delegating work to other agents while Claude Code continues working.

Note: Requires @letta-ai/letta-code-sdk (installed as a dependency).

Stop

Uses an async hook pattern — runs in the background without blocking Claude Code:

  1. Main hook (send_messages_to_letta.ts) runs quickly:
  2. Parses the session transcript (JSONL format)
  3. Extracts use

Extension points exported contracts — how you extend this code

HookInput (Interface)
(no doc)
scripts/pretool_sync.ts
HookInput (Interface)
(no doc)
scripts/session_start.ts
SyncState (Interface)
(no doc)
scripts/conversation_utils.ts
ContentBlock (Interface)
(no doc)
scripts/transcript_utils.ts
SdkPayload (Interface)
(no doc)
scripts/send_worker_sdk.ts
HookInput (Interface)
(no doc)
scripts/send_messages_to_letta.ts
LettaMessage (Interface)
(no doc)
scripts/sync_letta_memory.ts
Config (Interface)
(no doc)
scripts/agent_config.ts

Core symbols most depended-on inside this repo

log
called by 65
scripts/session_start.ts
writeTty
called by 41
scripts/session_start.ts
log
called by 27
scripts/send_messages_to_letta.ts
log
called by 21
scripts/send_worker_sdk.ts
isValidAgentId
called by 21
scripts/agent_config.ts
buildLettaApiUrl
called by 15
scripts/letta_api_url.ts
findModel
called by 8
scripts/agent_config.ts
buildLlmConfig
called by 8
scripts/agent_config.ts

Shape

Function 90
Interface 27

Languages

TypeScript100%

Modules by API surface

scripts/conversation_utils.ts31 symbols
scripts/agent_config.ts25 symbols
scripts/session_start.ts17 symbols
scripts/pretool_sync.ts12 symbols
scripts/sync_letta_memory.ts11 symbols
scripts/transcript_utils.ts9 symbols
scripts/send_messages_to_letta.ts5 symbols
scripts/send_worker_sdk.ts4 symbols
scripts/letta_api_url.ts3 symbols

Dependencies from manifests, versioned

@letta-ai/letta-code-sdk0.1.0 · 1×
@types/node20.10.0 · 1×
tsx4.7.0 · 1×
typescript5.3.0 · 1×
vitest3.0.0 · 1×

For agents

$ claude mcp add claude-subconscious \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact