Give Claude Code a memory with Relate

Save the people, objects, locations and events from a Claude Code conversation to a Relate graph as it happens, with a skill, a hook and the Relate command line.

Claude Code forgets a conversation when the session ends. This guide gives it a memory in a Relate graph, using a skill that saves the people, objects, locations and events from a discussion as it happens, and a hook that reminds the agent to use it.

Everything runs through the relate command line tool, and the memory is one file.

1. Install Relate and its skill

Install the relate binary:

bash
curl -sSfL https://relatedb.ai/install.sh | bash

Then install the Relate skill for Claude Code. It teaches the agent the command line, the output modes and the exit codes, so it can write Cypher without guessing at flags:

bash
relate skill install --agent claude-code

2. Create the memory file

The memory is a graph with four labels. A Person, an Object and a Location each have a name, and an Event has an id, a summary and a date. An event is linked to the people it INVOLVES, the objects it is ABOUT and the location it happened AT.

Constraints keep one node per name, which matters because the agent will mention the same person many times. Save them as schema.cypher:

cypher
CREATE CONSTRAINT person_name IF NOT EXISTS FOR (p:Person) REQUIRE p.name IS UNIQUE;
CREATE CONSTRAINT object_name IF NOT EXISTS FOR (o:Object) REQUIRE o.name IS UNIQUE;
CREATE CONSTRAINT location_name IF NOT EXISTS FOR (l:Location) REQUIRE l.name IS UNIQUE;
CREATE CONSTRAINT event_id IF NOT EXISTS FOR (e:Event) REQUIRE e.id IS UNIQUE;

Run the script into a new store. Relate creates memory.rl because nothing is there yet:

bash
mkdir -p ~/.claude/memory
relate query --database ~/.claude/memory/memory.rl < schema.cypher

3. Write the skill

A skill is a folder with a SKILL.md. The description is what Claude Code reads to decide when to use it, so it says what the skill does. Create ~/.claude/skills/remember/SKILL.md:

markdown
---
name: remember
description: Extract the people, objects, locations and events from this discussion and save them to the memory graph.
---
 
Save what was just discussed to the memory graph at `~/.claude/memory/memory.rl`.
 
1. List the people, objects, locations and events in the exchange. Skip anything that was only hypothetical.
2. Write one Cypher statement that saves them. Use `MERGE` for every node so a name that is already in the graph is reused. Give each event a short, stable `id` such as `lisbon-offsite-2026-03`.
3. Link each event to the people it `INVOLVES`, the objects it is `ABOUT` and the location it happened `AT`.
4. Run the statement with `relate --database ~/.claude/memory/memory.rl "<statement>"`.
 
For example, "Priya and Tom ran the Lisbon offsite on 12 March and demoed Relate":
 
```bash
relate --database ~/.claude/memory/memory.rl "MERGE (priya:Person {name: 'Priya'}) MERGE (tom:Person {name: 'Tom'}) MERGE (lisbon:Location {name: 'Lisbon'}) MERGE (relate:Object {name: 'Relate'}) MERGE (e:Event {id: 'lisbon-offsite-2026-03'}) SET e.summary = 'Team offsite in Lisbon', e.date = date('2026-03-12') MERGE (e)-[:INVOLVES]->(priya) MERGE (e)-[:INVOLVES]->(tom) MERGE (e)-[:AT]->(lisbon) MERGE (e)-[:ABOUT]->(relate)"
```
 
To recall something, query the same file with `--read-only`.

4. Add a hook

A skill only runs when the agent decides to use it. To save memories as the conversation happens, add a hook that tells the agent to use it after every reply. In ~/.claude/settings.json, a UserPromptSubmit hook runs a command each time you send a prompt, and what the command prints is added to the agent's context:

json
{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo 'After you reply, use the remember skill to save any people, objects, locations or events from this exchange.'"
          }
        ]
      }
    ]
  }
}

5. Recall a memory

Tell Claude Code about the offsite, and the skill saves it. In a later session you can ask "Who was at the Lisbon offsite?", and the agent queries the file. You can run the same query yourself:

bash
relate --database ~/.claude/memory/memory.rl --read-only --mode table "MATCH (e:Event)-[:AT]->(:Location {name: 'Lisbon'}), (e)-[:INVOLVES]->(p:Person) RETURN e.summary AS event, p.name AS person ORDER BY person"
text
+--------------------------+---------+
| event                    | person  |
+--------------------------+---------+
| "Team offsite in Lisbon" | "Priya" |
| "Team offsite in Lisbon" | "Tom"   |
+--------------------------+---------+

Use it with other agents

Any agent that can run shell commands can use the same memory file and the same statements. relate skill install with no --agent installs the Relate skill for every agent it detects, and relate skill lists them with the folder each one reads. For OpenCode, put the steps from the remember skill in the project's AGENTS.md.

Next steps

Relate publishes a task skill for this, relate-agent-memory, which models memory as entities, episodes and facts with provenance and two time axes. Install it with the skills CLI:

bash
npx skills add https://relatedb.ai --skill relate-agent-memory

Give an agent a memory builds that model step by step, and Model agent memory explains each label.

Try it yourself

GraphAcademy's GenAI Fundamentals course covers how graphs give language models context to work with.

Get Started with Relate

Install Relate, the embedded Cypher database. Seed a graph from a script and a CSV file, write data by hand and with an agent, then read it back.

Comments (0)

Loading comments...