> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memoclaw.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenClaw Hooks

> Give your OpenClaw agent persistent cloud memory with a single install.

The `memoclaw-hooks` package integrates MemoClaw directly into OpenClaw's lifecycle. Your agent automatically recalls relevant memories on session start, stores important context when sessions end, and consolidates memories in the background.

No code changes. No prompt engineering. Just install and restart.

## Installation

<Steps>
  <Step title="Install the CLI">
    ```bash theme={null}
    npm install -g memoclaw
    ```
  </Step>

  <Step title="Install the hook pack">
    ```bash theme={null}
    openclaw hooks install memoclaw-hooks
    openclaw hooks enable memoclaw
    ```
  </Step>

  <Step title="Set your private key">
    Add `MEMOCLAW_PRIVATE_KEY` to your environment. If you don't have a wallet yet, run `memoclaw init` to generate one.

    ```bash theme={null}
    export MEMOCLAW_PRIVATE_KEY=0xYourPrivateKey
    ```

    Or add it to your OpenClaw config:

    ```yaml theme={null}
    env:
      MEMOCLAW_PRIVATE_KEY: "0xYourPrivateKey"
    ```
  </Step>

  <Step title="Restart your gateway">
    ```bash theme={null}
    openclaw gateway restart
    ```
  </Step>
</Steps>

Verify the hook is loaded:

```bash theme={null}
openclaw hooks list --verbose
openclaw hooks check
```

## What happens automatically

Once installed, the hook fires on five OpenClaw lifecycle events:

| Event                  | What it does                                                                                |
| ---------------------- | ------------------------------------------------------------------------------------------- |
| **Session start**      | Recalls memories relevant to the user's first message and injects them as context           |
| **`/new` command**     | Extracts important context from the current session and stores it before the session resets |
| **Context compaction** | Stores key information before the context window is compressed                              |
| **Heartbeat**          | Runs periodic consolidation to merge duplicate memories (every 6 hours)                     |
| **Gateway startup**    | Recalls the 3 most recent memories to restore agent continuity                              |

### What recall looks like

When your agent starts a session, it sees something like:

```text theme={null}
[MemoClaw] Relevant memories:
- (0.92) User prefers direct communication, no fluff
- (0.87) Project uses PostgreSQL with JSONB columns
- (0.81) Last session: shipped v2.1 auth migration
```

These are injected as system context — the agent doesn't need to do anything special.

## Configuration

All config is via environment variables. No config files needed.

| Variable                                | Required | Default                    | Description                              |
| --------------------------------------- | -------- | -------------------------- | ---------------------------------------- |
| `MEMOCLAW_PRIVATE_KEY`                  | Yes      | —                          | Wallet private key for auth and payments |
| `MEMOCLAW_URL`                          | No       | `https://api.memoclaw.com` | API endpoint                             |
| `MEMOCLAW_NAMESPACE`                    | No       | `default`                  | Memory namespace for isolation           |
| `MEMOCLAW_HOOK_CONSOLIDATE_INTERVAL_MS` | No       | `21600000` (6h)            | Min interval between consolidations      |

## Multi-agent memory

Use `MEMOCLAW_NAMESPACE` to control memory isolation between agents.

```bash theme={null}
# Each agent gets its own memory
MEMOCLAW_NAMESPACE=agent-frontend
MEMOCLAW_NAMESPACE=agent-backend

# Or share a namespace for cross-agent knowledge
MEMOCLAW_NAMESPACE=shared-project
```

Same wallet, different namespaces = isolated recall. Same wallet, same namespace = shared memory.

## Using with the skill

The hook handles the automatic lifecycle (session start/end, compaction, heartbeats). For manual memory operations — like storing specific facts or recalling on demand — install the [MemoClaw skill](https://clawhub.ai/anajuliabit/memoclaw) alongside the hook:

```bash theme={null}
clawhub install anajuliabit/memoclaw
```

The skill gives your agent `memoclaw store`, `memoclaw recall`, and other CLI commands it can call mid-conversation.

## Pricing

* **100 free calls** per wallet — no payment setup needed
* After that: **\$0.005–\$0.01** per call via x402 (USDC on Base)
* The hook typically makes 2–4 API calls per session lifecycle
* At normal usage, that's a few cents per day

## Source

* **npm**: [`memoclaw-hooks`](https://www.npmjs.com/package/memoclaw-hooks)
* **GitHub**: [`anajuliabit/memoclaw-hooks`](https://github.com/anajuliabit/memoclaw-hooks)
