How to Share Memory Between Claude Code and Codex
- Authors

- Name
- Nino
- Occupation
- Senior Tech Editor
As AI-driven development evolves, the ability to maintain context across different tools becomes a critical bottleneck. Developers often find themselves repeating instructions or context when switching from Claude Code's terminal interface to the Codex environment. By leveraging Cairn.ink Memory in conjunction with high-performance LLM access via n1n.ai, you can create a unified cognitive layer for your development workflow.
The Importance of Cross-Tool Context
In a standard RAG (Retrieval-Augmented Generation) or agentic workflow, context is usually ephemeral. When you ask Claude Code to refactor a component and then switch to Codex to generate unit tests, the latter has no inherent knowledge of the logic discussed in the previous session. This fragmentation leads to "hallucinations by omission," where the AI makes assumptions based on outdated or incomplete data. Integrating a shared memory system ensures that every architectural decision and preference is synchronized. To power these sophisticated interactions, many enterprises rely on n1n.ai for stable, low-latency access to the latest models like Claude 3.5 Sonnet and GPT-4o.
Prerequisites for Implementation
Before initiating the setup, ensure your environment meets the following technical requirements:
- Node.js: Version 22.16 or later is mandatory for the Cairn.ink installer.
- CLI Accessibility: Both
claude(Claude Code) andcodexcommand-line interfaces must be present in your system's PATH. - API Access: High-speed API endpoints from n1n.ai are recommended to ensure the memory tools can process semantic embeddings without timeout issues.
Step 1: Automated Installer Setup
The most efficient way to link these tools is through the Cairn.ink Memory installer. This tool handles the complexities of hook registration and MCP (Model Context Protocol) configuration.
Run the following command to start the interactive setup:
npx @cairn-ink/memory setup
You will be prompted to choose a storage location. For most users, Cloud mode is the preferred choice as it enables automatic conversation capture and cross-device synchronization. If you prefer a direct approach, use the flag:
npx @cairn-ink/memory setup --cloud
The installer will scan your environment for Claude Code and Codex. You must approve the connections for both. Critical Pro-Tip: Before finalizing the installation, ensure both Claude Code and Codex are fully closed. Background processes can lock configuration files, leading to incomplete hook registration.
Step 2: Authentication and Identity Linking
After running the setup, a browser window will open for OAuth authentication. Cairn.ink uses a single browser grant to authorize both tools.
A unique Memory ID is generated for your project. This ID acts as the primary key for the shared database. If you are updating an existing installation and the tool detects two independent IDs, it will prompt you to choose one as the primary. The other will be preserved as a backup, ensuring you don't lose previous context.
Step 3: Configuring Codex Hooks
Once the installer finishes, reopen your clients. Codex requires an additional step to activate the integration. You must review and allow four specific hooks located in the /hooks directory. These hooks are client-side actions triggered by session events, allowing Codex to automatically "listen" to the conversation and store relevant facts without manual intervention.
To verify the status of your local installation at any time, use:
npx @cairn-ink/memory status
Step 4: Verification of Shared Memory
To confirm that the tools are communicating, perform a cross-tool read/write test. We recommend using personal scope for initial testing to avoid project-matching complexities.
In Claude Code: Ask the AI to save a specific preference using the remember_memory tool:
Use remember_memory to save this in personal scope:
"For the fictional Harbor demo, I want review summaries to start with test results."
Note the Memory ID and Source Receipt returned by the tool. The Source Receipt is a metadata object containing the original excerpt and client identifiers.
In Codex: Open a fresh session (do not copy-paste the previous answer) and ask:
Use recall_memory to find my review-summary preference for the Harbor demo.
If configured correctly, Codex will return the exact same Memory ID and content stored by Claude Code. This demonstrates a successful bridge between the two distinct LLM environments.
Advanced Usage: Local vs. Cloud Modes
| Feature | Cloud Mode | Local Mode |
|---|---|---|
| Storage | Encrypted Cloud | ~/.cairn-memory/data/memory.sqlite |
| Sync | Cross-computer | This computer only |
| Privacy | Masked local upload | Plaintext local storage |
| Cost | Subscription-based | Free |
| OS Support | All | Linux/WSL/macOS (Claude), Linux/WSL (Codex) |
For local-only setups, use:
npx @cairn-ink/memory setup --local
Note that semantic recall in Local Mode requires a valid model key. If the local server detects an OPENAI_API_KEY, it will utilize OpenAI for generating embeddings. For users who prioritize privacy, you can disable automatic capture entirely during setup:
npx @cairn-ink/memory setup --local --no-capture
Managing Project Rules with AGENTS.md
You don't always need a database server to share instructions. For static project rules, maintaining an AGENTS.md file is a best practice. Claude Code can import this file via an adjacent CLAUDE.md using the following syntax:
@AGENTS.md
This ensures that high-level architectural constraints are respected by both tools, while Cairn.ink handles the dynamic, evolving context of the current coding session.
Troubleshooting and Quotas
If memory retrieval fails, check the following:
- Scope Mismatch: Ensure both tools are operating in the same scope (personal vs. project).
- Daily Caps: Codex defaults to 200 automatic captures per day. You can adjust this using:
npx @cairn-ink/memory config --codex-daily-cap 300. - Pause State: Check if the capture is paused with
npx @cairn-ink/memory status.
By integrating these tools, you transform your AI assistants from isolated chat-bots into a cohesive development team.
Get a free API key at n1n.ai