Unified agentic memory with lifecycle hooks and Neo4j

Three glowing glass spheres linked by threads of light, symbolizing unified agentic memory

The current AI “harness” ecosystem is a mess. I have watched development environments rot in plenty of ways over the last 14 years, but vendor lock-in through proprietary “memory” is a newer kind of technical debt. If your agent’s context lives inside a closed harness like Cursor or Claude Desktop, you don’t own your workflow. You are renting a brain.

The fix is Unified Agentic Memory: a shared, persistent layer that lives outside the IDE. Lifecycle hooks and Neo4j let your agent’s understanding of a project follow you from Cursor to Claude Code. Convenience is part of it, but the real point is that you keep control of your own context.

The harness vs. the model

Agentic AI has two parts: the model (the engine) and the harness (the car). The harness is everything else, meaning the agent loop, tool definitions, context management, and memory. Right now the industry is busy building better cars while welding the driver to the seat. Move from Cursor to Claude Code and you start from zero context. You lose how you like to work, your local environment quirks, and past architectural decisions.

Many developers reach for MCP (Model Context Protocol) here, but MCP tools are agent-initiated. The model has to remember to remember. It has to decide to query the database, and if it is busy solving a complex bug it may skip logging a preference you care about. That is not deterministic enough.

Why hooks beat MCP for memory

Hooks are shell commands that fire automatically on specific lifecycle events. Unlike an MCP tool, the agent does not decide to call them; they run programmatically. Passive, deterministic logging. It works like a WordPress filter hanging off template_redirect: it does not care what the theme is doing, it just executes.

Most modern AI harnesses support a standard set of events:

  • SessionStart: Fires before the system prompt is read.
  • UserPromptSubmit: Fires before the message hits the LLM.
  • PreToolUse / PostToolUse: Captures the input and output of every command.
  • Stop: Fires when the session terminates.

With those events wired up, every interaction lands in a graph database like Neo4j without bloating the context window or leaning on the model’s judgment.

Implementing a deterministic hook

Here is a simplified example of how a harness sends a payload to a hook. The hook receives JSON on stdin and can emit context back on stdout. This is the core mechanism for Unified Agentic Memory.

<!-- Hook payload received via stdin -->
{
  "event": "UserPromptSubmit",
  "sessionId": "wp-debug-123",
  "client": "cursor",
  "data": {
    "prompt": "Refactor the bbioon_cache_flush function to use transients."
  }
}

Here is the shell wrapper that handles the event. In production you want this fast, so no model calls here, just an append to the graph database.

#!/bin/bash
# A simple hook wrapper for Unified Agentic Memory

read -r PAYLOAD
EVENT=$(echo $PAYLOAD | jq -r '.event')

# Fast append to Neo4j via a simple POST request
curl -X POST http://localhost:7474/db/data/transaction/commit \
     -H "Content-Type: application/json" \
     -d "{ \"statements\": [ { \"statement\": \"CREATE (e:Event {type: '$EVENT', data: '$PAYLOAD'})\" } ] }"

# Inject memories if it's the start of a session
if [ "$EVENT" == "SessionStart" ]; then
    # Return JSON to the harness to prepend to the system prompt
    echo '{"context": "Remember: User prefers PSR-12 and prefers WP-CLI over manual SQL."}'
fi

The dream phase: distilling the graph

An audit trail of every event is useful, but you cannot dump 5,000 raw events back into a context window. That is what the offline “dream phase” is for: a batch job that runs every few hours.

The job reads the new events in Neo4j, asks a model (like Claude 3.5 Sonnet) to distill them into durable notes, and writes them back as structured markdown files. As I argued in my piece on why vector databases are overkill for AI agent memory, semantic paths such as project/architecture.md hold up better here than RAG-style vector search.

Determinism matters for the same reason. The moment you let an LLM decide your memory structure on the fly, as I covered in my guide on production-grade AI agents, you invite race conditions and hallucinations into your long-term context.

If this Unified Agentic Memory work is eating your dev hours, hand it to me. I have been wrestling with WordPress and complex backend integrations since the 4.x days.

Own your context

If you do not own your memory, you do not own your agent. Move from harness-proprietary storage to an external graph-backed system driven by hooks and the lock-in goes away. You can start a feature in Cursor, refine it in Claude Code, and audit it in Codex while your agent keeps one consistent picture of your project.

author avatar
Ahmad Wael
I'm a WordPress and WooCommerce developer with 15+ years of experience building custom e-commerce solutions and plugins. I specialize in PHP development, following WordPress coding standards to deliver clean, maintainable code. Currently, I'm exploring AI and e-commerce by building multi-agent systems and SaaS products that integrate technologies like Google Gemini API with WordPress platforms, approaching every project with a commitment to performance, security, and exceptional user experience.

Leave a Comment