Part 11: Auto-Capture Hook (Stop Manually Writing Memory) banner
OnlyTerp OnlyTerp

Part 11: Auto-Capture Hook (Stop Manually Writing Memory)

Data & AI community intermediate

Description

*By Terp - [Terp AI Labs](https://x.com/OnlyTerp)* --- The vault system from Part 9 is powerful, but there's a gap: you have to manually write knowledge to vault files. In practice, after a long sessi

Installation

Terminal
claude install-skill https://github.com/OnlyTerp/openclaw-optimization-guide

README

Part 11: Auto-Capture Hook (Stop Manually Writing Memory)

*By Terp - [Terp AI Labs](https://x.com/OnlyTerp)*


The vault system from Part 9 is powerful, but there's a gap: you have to manually write knowledge to vault files. In practice, after a long session, you forget. Insights from debugging sessions, configuration discoveries, architectural decisions — they disappear when the context compacts or you reset.

**⚠️ This is NOT the same as OpenClaw's built-in `session-memory` hook.** The built-in hook just dumps raw conversation text to a dated markdown file. It does NOT extract knowledge — no decisions, no lessons, no claim-named files. If you enabled `session-memory` and thought you were done, you're not. You need THIS custom hook for real auto-capture. The built-in one is a session saver, not a knowledge extractor.

ByteRover (a community plugin on ClawHub) solves this with an `afterTurn` hook that curates every conversation turn. But it depends on an external `brv` binary that inherits your full environment and conversation content. We built the same thing natively using OpenClaw's hook system — no external binary, no trust issues, your own models.


How It Works

The auto-capture hook fires on three events:

    undefined

On each trigger it:

    undefined

Runs entirely async — fires and forgets. You never feel it.


Installation

1. Create the hook directory

mkdir -p ~/.openclaw/hooks/auto-capture
cd ~/.openclaw/hooks/auto-capture
git init  # Codex requires a git repo

2. Copy the hook files

Copy [`hooks/auto-capture/HOOK.md`](./hooks/auto-capture/HOOK.md) and [`hooks/auto-capture/handler.ts`](./hooks/auto-capture/handler.ts) from this repo into `~/.openclaw/hooks/auto-capture/`.

Or clone this repo and symlink:

ln -s /path/to/openclaw-optimization-guide/hooks/auto-capture ~/.openclaw/hooks/auto-capture

3. Set environment variables

The handler reads config from environment variables. Set these before starting your gateway:

**Option A: Cerebras (free, recommended)**

# Get a free key at https://cloud.cerebras.ai/
export CEREBRAS_API_KEY="csk-your-key-here"

**Option B: Anthropic (if you're on Claude Max and don't want another provider)**

export AUTOCAPTURE_API_URL="https://api.anthropic.com/v1/messages"
export AUTOCAPTURE_API_KEY="sk-ant-your-key-here"
export AUTOCAPTURE_MODEL="claude-sonnet-4-20250514"

**Option C: Any OpenAI-compatible API** ```