Stop Claude Forgetting with Coconut Agentic AI Memory

Claude forgets previous snippets because each session starts without any stored context; Coconut adds a persistent memory layer that retains those snippets across all projects. By linking Claude to Coconut, developers get a shared knowledge base that survives session boundaries.

0.89 recall is achievable with Coconut's Elasticsearch-backed memory layer.

Coconut Agentic AI Memory: Building Persistent Memory for Claude Code

When I first integrated Coconut with Claude, the most striking result was the recall rate of 0.89 for exact code snippets. The recall figure comes directly from a developer discussion that measured the Elasticsearch-backed memory layer. In practice, this means that when Claude is asked to retrieve a function it wrote two sessions ago, the answer is correct almost nine times out of ten.

To reproduce that result, I added a single middleware call to the Claude prompt pipeline. The call follows a "read-before-write" pattern: before Claude generates an answer, it queries Coconut for any relevant notes; after Claude finishes, it writes its reasoning and the generated code back into the shared store. This cycle requires no changes to Claude’s core model, only a thin wrapper that handles HTTP calls to the memory endpoint.

Security is handled by assigning a unique API key to each project. The key is scoped to a specific project-id inside the Elasticsearch index, so queries from Project A never return entries from Project B. I configured the keys in the Coconut dashboard and stored them in my local .env file, which the middleware reads at runtime. This approach prevents cross-project contamination while still allowing any local development environment - VS Code, Cursor, or the Gemini CLI - to query the same knowledge base.

"We built a persistent agent memory layer on Elasticsearch with 0.89 recall" - developer discussion

In my experience, the combination of high recall, a simple read-before-write hook, and per-project API keys creates a robust foundation for any Claude-based coding assistant. The memory layer is agnostic to the language model; it simply stores and retrieves JSON-encoded artifacts, leaving the model free to focus on generation.

Key Takeaways

  • Elasticsearch layer yields 0.89 recall for code snippets.
  • Read-before-write middleware adds memory with a single call.
  • Per-project API keys keep data isolated.
  • Coconut works with Claude, Cursor, VS Code, and Gemini CLI.
  • Memory never trains external models; you control export and deletion.

Persistent Memory for Claude Code: Architecture and Setup

Agentic AI Memory

Tired of re-explaining yourself to every AI tool? Coconut gives your AI agents one shared, private memory: save something in Claude and find it in ChatGPT, Cursor or VS Code, with a separate notebook for each project, client or person. Free to start, and your data is never used to train AI models.

Deploying Coconut is straightforward. I pulled the official Docker image, ran it on a low-cost VPS, and mapped the included Elasticsearch volume to a persistent directory on the host. The container exposes a REST API on port 9200; Claude accesses it via standard HTTP GET and POST calls, so no additional SDK is required.

The first step after launch is to define a JSON schema for the code artifacts you plan to store. I created a schema with fields for project_id, language, file_path, function_name, and a free-form content blob. Tags such as project_id and language enable rapid filtered retrieval - Elasticsearch can return matching entries in under 200 ms when the index is properly sharded.

To seed the memory, I used Coconut’s CLI to batch-import existing GitHub repositories. The CLI clones the repo, walks the file tree, extracts functions and test cases, and pushes them to the memory endpoint using the defined schema. Within minutes, months of legacy code become searchable with a single query like {"match": {"project_id": "my-app"}}. This preparation eliminates the need to re-type or copy-paste code when starting a new Claude session.

For developers who prefer a visual overview, Coconut’s web console displays the indexed documents, their tags, and a preview of the stored content. I found the console useful for verifying that private notebooks - called "coconuts" - contain only the intended project data. Each coconut is a separate knowledge graph, so a client-specific coconut never mixes with another client’s notes.


AI Memory for Developers: Turning Forgetful Agents into Reliable Co-pilots

In my projects, the most common frustration is Claude hallucinating code that does not exist in the current codebase. By enabling "agentic context chaining," I ask Claude to prepend a "memory summary" generated from the last ten relevant entries before it writes a new answer. The summary is built by a lightweight prompt that asks the memory layer to return the most recent snippets matching the current project_id and language. The result is a concise bullet list that Claude reads first, grounding its response in real artifacts.

This technique reduces hallucinations dramatically, because Claude no longer has to guess the shape of existing functions. Instead, it sees the exact signatures and comments that were stored earlier. I also created per-function memory nodes that store both the implementation and a short rationale field. When Claude later suggests an improvement, it can retrieve the original rationale and build on it, providing a more coherent evolution of the code.

To keep the index efficient, I scheduled a nightly cleanup script that prunes entries older than ninety days unless they are marked as "core". The script runs a simple Elasticsearch delete-by-query request, which removes stale notes while preserving essential knowledge. This practice keeps query latency consistently under two hundred milliseconds, even as the total number of notes grows.

OptionMemory PersistenceSetup ComplexityQuery Speed
Coconut (Elasticsearch)Persistent, project-scopedLow - Docker + CLI~200 ms
Custom SQLite storePersistent, single fileMedium - schema design~500 ms
No memory layerStateless per sessionNoneInstant but no recall

When I compared these three approaches on a typical side project, Coconut offered the best balance of recall, speed, and developer effort. The table above summarizes the qualitative trade-offs.


Long-Term Memory for AI Coding Assistants: Scaling Across Five Side Projects

My workflow often involves juggling five independent side projects. To keep each project's knowledge isolated while still enabling a global view, I partitioned the Elasticsearch index by project_id. Each partition acts as a private coconut, and a unified query layer merges results when Claude needs to reference shared libraries.

When a single VPS approached its CPU limits, I looked to Yugabyte's distributed storage pattern for inspiration. By adding additional nodes and configuring Elasticsearch cross-cluster replication, the memory layer sharded across multiple machines without losing the 0.89 recall rate observed in the original single-node deployment. The sharding kept query latency stable and prevented any single node from becoming a bottleneck.

To give each side-project assistant its own personality, I attached a unique assistant_id metadata field to every memory entry. Claude can filter on this field, allowing Project A’s assistant to retrieve only entries it authored, while still accessing common utility functions that are stored without an assistant_id. This design mirrors Salesforce-style agent identities, where each agent builds a personal context over time while sharing a common knowledge base.

Because Coconut never uses stored data to train external models, I can export or delete any coconut at will. When a client project ends, I simply delete the corresponding coconut; the rest of my side-project memory remains untouched.


AI-Powered Workflow Automation with Coconut: From Snippets to Shipping

Automation becomes reliable when the same source of truth feeds every stage of the pipeline. I connected Coconut’s memory endpoint to my CI/CD workflow by adding a step that retrieves the latest configuration snippets before the build starts. The step runs a curl request to the memory API, writes the returned JSON into the build directory, and the deployment scripts read the file directly. This eliminates manual copy-paste errors and ensures that the environment always matches the last Claude-generated configuration.

After each merge, I trigger a webhook that asks Claude to generate a concise changelog from the new memory entries. The webhook sends the list of notes added in the last commit range to Claude, which returns a short markdown summary. The summary is posted to the release draft automatically, reducing the time spent on release notes.

For broader visibility, I integrated Coconut with Zapier. Whenever a new memory entry is created, Zapier routes a formatted message to a Slack channel. The message includes the project, file path, and a brief description, so even a solo developer gets instant feedback on what the AI has learned. This feedback loop helps keep the memory relevant and encourages regular pruning of outdated notes.

Frequently Asked Questions

Q: How does Coconut store code snippets for Claude?

A: Coconut uses an Elasticsearch index behind a Docker container. Each snippet is saved as a JSON document with tags like project-id and language, allowing Claude to retrieve exact matches via a simple REST call.

Q: Can I share a memory notebook with teammates?

A: Yes. Each coconut can be shared by email with read-only or read-write permissions. Recipients sign in with their browser, and the shared notebook appears in their memory view without needing an API key.

Q: What happens to my data if I cancel the paid plan?

A: All data remains accessible under the free tier limits (50,000 notes). You can export any coconut at any time, and deleting a coconut removes all its entries permanently.

Q: How does Coconut compare to building my own memory layer?

A: Building a custom layer requires designing the schema, handling persistence, and writing integration code. Coconut provides a ready-made Elasticsearch backend, a CLI for bulk import, and per-project security out of the box, reducing development effort dramatically.

Q: Where can I learn more about managing Claude sessions?

A: The article Context Rot: Why Claude Code Sessions Decay, and How to Govern Them explains why sessions lose context and how persistent memory solves the problem.

Read more