>_ DevTrendsen

Language

Home

Languages

Sections

Frontend Backend Mobile DevOps AI / ML GameDev Blockchain Embedded Security
Rust

How to Switch Between Claude Code and Codex Without Losing Context

ai-memory

Familiar situation: you're sitting in the terminal with Claude Code, debugging a tricky bug in a distributed queue for an hour and a half, tried five non-working hypotheses, and finally found the right solution. Then the session grows, context compresses, or limits hit the ceiling. You switch to Codex or OpenCode in the same folder, and the circus begins. The new assistant needs to be briefed from scratch: why you can't touch the NGINX config, which tests have already failed, and what database structure we chose twenty minutes ago.

The ai-memory project aims to solve this problem once and for all. It was created by Fabio Akita (known in the community as AkitaOnRails). The idea is to give console AI agents shared long-term memory and automatic context handoff between sessions and different models.

What's the concept

Usually, "AI memory" means a vector database where raw dialog logs get dumped as embeddings. In practice, these logs are full of garbage: intermediate tool calls, repeated test runs, syntax errors.

The author of ai-memory took a different path, inspired by Karpathy's LLM Wiki concept. Here, memory is structured as a regular wiki made of Markdown files in a Git repository. The server intercepts agent lifecycle events, cleans them of unnecessary noise, and compiles a compressed summary at session end: what was done, what conclusions were reached, what tasks remain open.

When you open a new terminal with a different agent, the tool automatically feeds it a structured summary right before the first prompt. No manual clipboard copying.

Under the hood and in the terminal

The server is written in Rust. It spins up a local service with MCP (Model Context Protocol) support, lifecycle hooks, and a built-in web interface.

It supports virtually all current agent CLIs:

  • Claude Code
  • OpenAI Codex
  • Command Code
  • Devin CLI
  • OpenCode, Cursor, Zed
  • Gemini CLI, Grok Build CLI, Kimi Code, Kiro CLI, Pi / OMP

Data is stored locally in a single directory:

<data_dir>/
├── wiki/    # Markdown-страницы под версионным контролем Git
├── raw/     # очищенные сегменты сессий
├── db/      # SQLite с индексами FTS5, сущностями и эмбеддингами
└── logs/    # логи работы

Each project is isolated by repository path or via a marker file .ai-memory.toml. If you work with a monorepo or multiple Git worktrees, they're linked into a unified context.

Key features in practice

Seamless switching between agents

ai-memory has managed session mode ai-memory run. It works simply:

cd /path/to/project
ai-memory run claude

# Закончили работу в Claude Code, продолжаем задачу в Codex:
ai-memory run codex --yolo

# А потом возвращаемся к сессии через Command Code:
ai-memory run command-code

The agent reads the "where we left off" block on startup. It contains recent architectural decisions, open questions, and test results. If you don't specify an agent name, the ai-memory run command automatically picks up the most recent active session in the current folder.

The ai-memory continue command goes even further: you can call it from any folder, and it will take you back to the project you were last working on.

Wiki instead of log dumps

The entire knowledge base is stored as plain text. You can open it in Obsidian, read it with grep, or browse it in the built-in browser on port 127.0.0.1:49374/web.

If you want to record an important project rule, just tell the agent: "save to permanent memory that we use NATS JetStream for queues." The agent calls the MCP tool memory_write_page, and a versioned Markdown file appears in the repository.

Knowledge base search is hybrid. SQLite FTS5 full-text search runs first, then entity matching and graph connections between pages. If you connect an embeddings model, vector search is added as well.

At the same time, ai-memory can distinguish between stable architectural rules and temporary session notes, prioritizing stable pages from the _rules/ and decisions/ folders.

Working without external LLMs

An interesting detail: ai-memory starts without any neural network API keys at all. In "zero-LLM" mode, search works through FTS5 and entities, and session summaries are assembled using deterministic rules.

If you configure keys (Anthropic, OpenAI, Gemini, or local Ollama via a compatible endpoint), the tool enables smart page consolidation, knowledge base conflict detection, and background self-learning for the project.

Quick start via Docker

The fastest way to deploy the server on your workstation:

# 1. Запускаем локальный сервер
docker run -d --name ai-memory \
    --restart unless-stopped \
    -p 127.0.0.1:49374:49374 \
    -v ai-memory-data:/data \
    -e AI_MEMORY_LLM_PROVIDER=anthropic \
    -e ANTHROPIC_API_KEY=sk-ant-... \
    akitaonrails/ai-memory:latest

# 2. Подключаем MCP и хуки для Claude Code
ai-memory install-mcp   --client claude-code --apply
ai-memory install-hooks --agent  claude-code --apply

For Arch Linux users, ready-made packages ai-memory-bin with systemd units are available in AUR. Native binaries for Apple Silicon and Intel are released for macOS.

If the server is moved to a home server or local network, security is configured via Bearer tokens. The server listens for requests, verifies authorization, and separates memory between multiple developers through operator slots.

What it's useful for

The tool solves three specific tasks.

First — multi-agent development. It's faster to draft one task in Claude, refactor it in Codex, and do code review through Gemini. Without a shared memory layer, this workflow turns into endless context-copying routine.

Second — onboarding an agent to an old repository. The ai-memory bootstrap command reads commit history, README, and project documentation, generating initial knowledge base pages.

Third — local audit. At any moment you can open the web interface, check generated notes, revert a bad edit via ai-memory restore-page, or clean up stale data.

Summary

ai-memory appeals with its pragmatic approach. Instead of building another heavy stack with external vector databases, the author took fast Rust, reliable SQLite, and simple Git with Markdown.

If you actively use terminal AI assistants and are tired of re-explaining project context to models every day, the repository is definitely worth a look. Start with a local run paired with your main CLI agent to evaluate how convenient context transfer between tasks feels.

Related projects