ContextWeave hooks into Claude Code's lifecycle to persist traces into Beads and rehydrate working context after compaction.
- Beads CLI installed and
bdon your PATH - Node.js (any modern version)
From this repo:
node install.jsThis copies all hook scripts to ~/.contextweave/, installs dependencies, and links search-beads onto your PATH.
Stealth mode runs Beads locally without git integration — ideal for personal use on shared or open-source projects.
cd /path/to/your/project
BEADS_DIR="$(pwd)/.beads" bd init --quiet --stealth
echo ".beads/" >> .gitignoreBEADS_DIR tells Beads where to store the database (in --stealth mode git discovery is disabled, so you must specify the path explicitly). ContextWeave detects .beads/ in the project root and enables tracing automatically.
Persistent access:
bdcommands run in Claude Code hooks inherit Claude's shell environment. If you want to runbdcommands in your own terminal too (e.g.bd list,bd prime), exportBEADS_DIRin your shell profile for that project or use a tool likedirenv:# .envrc (direnv) export BEADS_DIR="$(pwd)/.beads"
Merge the following into ~/.claude/settings.json (under the top-level "hooks" key). Running node install.js prints the exact snippet with your real install path:
{
"hooks": {
"SessionStart": [
{ "matcher": "", "hooks": [{ "type": "command", "command": "node ~/.contextweave/1-context-start.js" }] }
],
"UserPromptSubmit": [
{ "matcher": "*", "hooks": [{ "type": "command", "command": "node ~/.contextweave/2-context-before-agent.js" }] }
],
"PreToolUse": [
{ "matcher": "*", "hooks": [{ "type": "command", "async": true, "command": "node ~/.contextweave/7-context-after-tool.js" }] }
],
"PostToolUse": [
{ "matcher": "*", "hooks": [{ "type": "command", "async": true, "command": "node ~/.contextweave/7-context-after-tool.js" }] }
],
"PostToolUseFailure": [
{ "matcher": "*", "hooks": [{ "type": "command", "async": true, "command": "node ~/.contextweave/7-context-after-tool.js" }] }
],
"PreCompact": [
{ "matcher": "*", "hooks": [{ "type": "command", "command": "node ~/.contextweave/3-context-precompress.js" }] }
],
"Stop": [
{ "matcher": "*", "hooks": [{ "type": "command", "async": true, "command": "node ~/.contextweave/6-context-after-agent.js" }] }
],
"SessionEnd": [
{ "matcher": "*", "hooks": [{ "type": "command", "async": true, "command": "node ~/.contextweave/5-context-end.js" }] }
]
}
}Key design decisions:
SessionStartusesmatcher: ""(empty) so it fires on ALL session starts:startup,resume,clear, andcompact. This is critical — a"startup"matcher silently skips context injection after compaction restarts.- Trace-only hooks (
PreToolUse,PostToolUse,Stop,SessionEnd) areasync: trueso they don't add latency to every tool call. PreCompactoutput becomescustomInstructionsfor the compaction LLM, guiding it to preserve Beads state in its summary.
Run the doctor from your project directory to verify everything is wired correctly:
cd /path/to/your/project
node ~/.contextweave/doctor.jsIt checks:
- Prerequisites (Node.js, bd CLI)
- All scripts installed in
~/.contextweave/ ~/.claude/settings.jsonhook config (correct matchers, async flags, script paths)- Beads workspace initialized in the current directory
- Dry-runs all hook scripts with mock Claude payloads to verify exit 0
Then restart Claude Code in the project — on session start you should see a system reminder with your Beads context (bd prime --full output + open issues).
Beads is powered by Dolt (a version-controlled SQL database).
No configuration needed. Dolt runs in-process with data stored at .beads/embeddeddolt/. Single-writer only, file-locked.
Connect to an external dolt sql-server for multi-writer support:
export BEADS_DOLT_SERVER_HOST=localhost
export BEADS_DOLT_SERVER_PORT=3307 # defaultStart a Dolt server:
dolt sql-server --port 3307| Hook | Event | Purpose |
|---|---|---|
1-context-start.js |
SessionStart | Injects bd prime output + open issues into session |
2-context-before-agent.js |
UserPromptSubmit | Rehydrates after compact, injects Beads reminder |
7-context-after-tool.js |
Pre/PostToolUse | Logs tool calls to Beads (async, non-blocking) |
3-context-precompress.js |
PreCompact | Writes .needs_rehydrate marker; guides compaction LLM |
6-context-after-agent.js |
Stop | Logs final response to Beads (async) |
5-context-end.js |
SessionEnd | No-op cleanup (async) |
When /compact runs:
3-context-precompress.jswrites.needs_rehydratein the session state dir- The compaction LLM receives instructions to preserve Beads issue IDs in its summary
- On the next prompt after restart,
2-context-before-agent.jsdetects.needs_rehydrate, injects a full context pack, and removes the marker
The search-beads binary (installed to PATH) performs semantic search over your Beads store using an ONNX embedding model (~90 MB, auto-downloaded on first install). Claude can invoke it directly:
search-beads "authentication refactor"
search-beads resolves the store location from BEADS_DIR (checked first) then falls back to .beads/ in the current directory. In stealth mode you must have BEADS_DIR set — either export it in your shell profile or prefix the command:
BEADS_DIR="$(pwd)/.beads" search-beads "authentication refactor"Claude Code hooks already inherit
BEADS_DIRfrom the environment set up duringbd init. This only matters when runningsearch-beadsmanually in a terminal.