working-memory 0.2.2

Working memory for AI coding assistants
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# wm — Working Memory for AI Coding Assistants

**wm** automatically captures tacit knowledge from your coding sessions and surfaces relevant context for each new task. It's the memory layer that helps AI assistants learn how *you* work.

**Supported platforms:**
- **Claude Code** - Full support via plugin
- **OpenAI Codex CLI** - Alpha support via skill (agent-invoked)

## The Problem

LLMs have amnesia. Every conversation starts fresh. The patterns you've established, the constraints you've discovered, the preferences you've revealed—all forgotten.

You end up repeating yourself:
- "Remember, we always use X pattern here"
- "Don't forget the constraint about Y"
- "I prefer Z approach for this kind of problem"

## The Solution

wm runs silently in the background:

1. **Extract**: After each conversation turn, captures tacit knowledge—the wisdom that emerges from *how* you work, not just what you say
2. **Compile**: Before each new prompt, filters accumulated knowledge for relevance and injects it as context

The result: AI assistants that remember your patterns across sessions.

## What Gets Captured

**Tacit knowledge** is the unspoken wisdom in how someone works:

- Rationale behind decisions (WHY this approach, not just WHAT was done)
- Paths rejected and why (the judgment in pruning options)
- Constraints discovered through friction
- Preferences revealed by corrections
- Patterns followed without stating

**Not captured:**
- What happened ("Fixed X", "Updated Y")
- Explicit requests or questions
- Tool outputs or code snippets
- Content from CLAUDE.md (already explicit)

## Quickstart: Claude Code

### Prerequisites

- [Claude Code]https://claude.com/code CLI
- [superego]https://github.com/cloud-atlas-ai/superego (optional, but recommended for extraction triggers)

### Option 1: Homebrew (macOS)

```bash
brew tap cloud-atlas-ai/wm
brew install wm
```

### Option 2: Cargo (all platforms)

```bash
cargo install wm
```

### Option 3: From Source

```bash
git clone https://github.com/cloud-atlas-ai/wm.git
cd wm
cargo install --path .
```

### Install the Claude Code Plugin

```bash
claude plugin install wm
```

### Initialize in Your Project

```bash
cd /your/project
wm init
```

This creates a `.wm/` directory to store accumulated knowledge.

## Quickstart: OpenAI Codex CLI (Alpha)

Codex support uses agent skills that can be invoked at decision points. Most features work, but session auto-discovery is limited due to Codex's different session storage format.

**What works:**
- ✅ Manual knowledge capture/review (state.md, working_set.md)
- ✅ Dive prep with context gathering
- ✅ Compress and pause operations
- ⚠️ Distill requires manual transcript paths (no auto-discovery yet)

```bash
# 1. Install the binary (choose one)
brew install cloud-atlas-ai/wm/wm           # macOS
cargo install wm                            # All platforms

# 2. Install the skills
mkdir -p ~/.codex/skills
ln -s /path/to/wm/plugin ~/.codex/skills/wm

# Or download agents individually:
mkdir -p ~/.codex/skills/wm/agents
BASE_URL="https://raw.githubusercontent.com/cloud-atlas-ai/wm/main/plugin/agents"
curl -L -o ~/.codex/skills/wm/agents/dive-prep.md $BASE_URL/dive-prep.md
curl -L -o ~/.codex/skills/wm/agents/review.md $BASE_URL/review.md
curl -L -o ~/.codex/skills/wm/agents/distill.md $BASE_URL/distill.md
curl -L -o ~/.codex/skills/wm/agents/compress.md $BASE_URL/compress.md
curl -L -o ~/.codex/skills/wm/agents/pause.md $BASE_URL/pause.md
```

**Available Agent Skills:**

| Skill | Support | When to Use |
|-------|---------|-------------|
| `$wm:dive-prep` | ✅ Full | Prepare focused work session with intent, context, and workflow |
| `$wm:review` | ✅ Full | Review accumulated knowledge and current context |
| `$wm:compress` | ✅ Full | Synthesize state.md to higher-level abstractions |
| `$wm:pause` | ✅ Full | Pause/resume operations (extract, compile, or both) |
| `$wm:distill` | ⚠️ Manual | Batch extract (requires manual transcript paths) |

**Typical Workflows:**

```bash
# Session start - prepare dive context
$wm:dive-prep --intent fix

# Mid-session - review what wm knows
$wm:review

# Maintenance - compress accumulated knowledge
$wm:compress

# Sensitive work - pause extraction
$wm:pause extract

# Manual extraction from Codex session (since auto-discovery isn't supported yet)
# Find your sessions:
ls ~/.codex/sessions/2026/01/*/rollout-*.jsonl
# Extract from specific transcript:
wm extract --transcript ~/.codex/sessions/2026/01/06/rollout-<timestamp>-<uuid>.jsonl
```

**Why limited session discovery?**

Codex stores sessions in `~/.codex/sessions/YYYY/MM/DD/` with different naming and structure than Claude Code's `~/.claude/projects/<project-id>/`. Auto-discovery support for Codex sessions is tracked in [#11](https://github.com/cloud-atlas-ai/wm/issues/11).

**Manual Commands:**

All CLI commands work normally: `wm init`, `wm show state`, `wm show working`, etc.

See [plugin/agents/](plugin/agents/) for detailed documentation on each skill.

## Usage

Once installed, wm works automatically:

1. **You write prompts** → wm injects relevant context
2. **You work with Claude** → conversation happens normally
3. **Turn ends** → wm extracts any tacit knowledge learned

### Manual Commands

```bash
# View accumulated knowledge
wm show state

# View what context would be injected
wm show working

# List all sessions
wm show sessions

# View session-specific working set
wm show working --session-id <id>

# Manually trigger extraction
wm extract

# Manually compile for a specific intent
wm compile --intent "implement authentication"

# Compress state.md (synthesize to higher abstractions)
wm compress
```

### Compressing Knowledge

Over time, `state.md` accumulates knowledge and can grow unwieldy. The `compress` command distills it down by:

- **Merging** related items into broader principles
- **Abstracting** specific instances into general patterns
- **Removing** obsolete or superseded knowledge
- **Preserving** critical constraints and preferences

```bash
wm compress
# Compressed: 42 → 18 lines (57% reduction)
# Backup saved to .wm/state.md.backup
```

Run periodically when state feels bloated, not after every session.

## Dive Sessions

A **dive** is a focused work session with explicit grounding. The metaphor: you don't just splash around—you *dive* into work with a clear purpose, knowing what you're after and what constraints apply.

**Without a dive**, AI sessions often drift:
- You start coding without clarity on the goal
- Constraints surface mid-work ("oh wait, we can't do that because...")
- Related knowledge sits unused because nothing surfaced it
- The session ends without capturing what was learned

**With a dive**, you start grounded:
- **Intent** is explicit (fix, plan, explore, review, ship)
- **Context** is curated (relevant knowledge, constraints, mission)
- **Workflow** is suggested (what steps this intent typically follows)
- **Focus** is documented (what specifically you're working on)

This isn't overhead—it's the 30 seconds of setup that saves 30 minutes of drift.

### The `/dive-prep` Skill

Invoke `/dive-prep` in Claude Code to prepare a focused work session:

```bash
/dive-prep                          # Interactive - prompts for intent
/dive-prep --intent fix             # Fix a bug
/dive-prep --intent plan            # Design an approach
/dive-prep --intent explore         # Understand something
/dive-prep --intent review          # Reflect on recent work
/dive-prep --intent ship            # Get something deployed
```

**What it does:**

1. **Detects context** — Reads CLAUDE.md, git state, existing `.wm/` knowledge
2. **Checks for OH** — If [Open Horizons]https://github.com/cloud-atlas-ai/open-horizons MCP is connected, offers to link to an endeavor for strategic context (missions, guardrails, learnings)
3. **Asks for intent** — If not provided, prompts for what you're trying to accomplish
4. **Builds workflow** — Suggests steps based on intent type
5. **Writes manifest** — Creates `.wm/dive_context.md` with curated grounding

**With Open Horizons (recommended):**
```bash
/dive-prep --intent fix --oh bd9d6ace
```

OH provides the strategic layer: *why* you're doing this (mission), *what not to do* (guardrails), and *what you've learned* (metis).

**Without OH:**
```bash
/dive-prep --intent explore
# Prompts: "What are you exploring?"
```

Still valuable—you get explicit intent, workflow guidance, and documented focus.

### The `wm dive` Commands

Manage dive context directly:

```bash
wm dive load <pack-id>    # Load a pre-built dive pack from OH
wm dive show              # Display current dive context
wm dive clear             # Remove dive context
```

**Dive packs** are curated context bundles stored in Open Horizons. They're useful for recurring work patterns—load a pack instead of rebuilding context each time.

**Configuration:**
```bash
# Set OH API key (required for wm dive load)
export OH_API_KEY=your-key

# Or configure in ~/.config/openhorizons/config.json:
{
  "api_key": "your-key",
  "api_url": "https://app.openhorizons.me"
}
```

## Batch Distillation

The `distill` command extracts knowledge from all your Claude Code sessions at once, instead of per-turn extraction:

```bash
wm distill                    # Process all sessions
wm distill --dry-run          # Preview what would be processed
wm distill --force            # Re-extract even cached sessions
```

**How it works:**

1. **Discovers sessions** — Finds all Claude Code transcripts for this project
2. **Extracts incrementally** — Caches results, only processes new/changed sessions
3. **Accumulates knowledge** — Writes raw extractions to `.wm/distill/raw_extractions.md`

**When to use:**
- Initial setup: extract knowledge from existing sessions
- Periodic catchup: if per-turn extraction was paused
- Audit: see what knowledge exists across all sessions

**Output:**
```
.wm/distill/
├── raw_extractions.md    # Accumulated knowledge from all sessions
├── cache.json            # Extraction cache (enables incremental runs)
└── errors.log            # Any extraction failures
```

## Pause and Resume

Temporarily disable wm operations without uninstalling:

```bash
wm pause                  # Pause both extract and compile
wm pause extract          # Pause only extraction
wm pause compile          # Pause only context injection

wm resume                 # Resume both operations
wm resume extract         # Resume only extraction
wm resume compile         # Resume only context injection

wm status                 # Show current state
```

**When to use:**
- **Sensitive work**: Pause extraction when working on confidential code
- **Debugging**: Isolate issues by disabling one operation
- **Performance**: Skip context injection on simple tasks

### Debugging

```bash
# Watch hooks fire in real-time
tail -f .wm/hook.log

# Check what's being captured
cat .wm/state.md
```

## How It Works

### Architecture

```
┌─────────────────────────────────────────────────────────────┐
│                    Claude Code Session                       │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  [User Prompt]                                              │
│       │                                                     │
│       ▼                                                     │
│  ┌─────────────────┐                                        │
│  │ wm compile      │◄── Reads state.md                      │
│  │ (hook)          │    Filters for relevance               │
│  └────────┬────────┘    Injects as context                  │
│           │                                                 │
│           ▼                                                 │
│  [Claude Processes with Context]                            │
│           │                                                 │
│           ▼                                                 │
│  ┌─────────────────┐                                        │
│  │ sg evaluate     │◄── Superego evaluates turn             │
│  │ (stop hook)     │    Calls wm extract in background      │
│  └────────┬────────┘                                        │
│           │                                                 │
│           ▼                                                 │
│  ┌─────────────────┐                                        │
│  │ wm extract      │◄── Reads transcript                    │
│  │ (background)    │    Extracts tacit knowledge            │
│  └─────────────────┘    Updates state.md                    │
│                                                             │
└─────────────────────────────────────────────────────────────┘
```

### Storage

```
.wm/
├── state.md              # Accumulated tacit knowledge (the "memory")
├── working_set.md        # Last compiled context
├── hook.log              # Debug log
└── sessions/
    └── <session-id>/     # Per-session state (prevents cross-session bleed)
```

## Integration with Superego

wm is designed to work with [superego](https://github.com/cloud-atlas-ai/superego), a metacognitive advisor for AI assistants. When both are installed:

- **superego** evaluates Claude's work and provides feedback
- **superego's stop hook** triggers wm extraction in the background
- **wm** captures knowledge, superego captures concerns—complementary roles

They compose via shell calls with no shared state (Unix philosophy).

## Configuration

### Environment Variables

| Variable | Purpose |
|----------|---------|
| `WM_DISABLED=1` | Skip all wm operations |
| `CLAUDE_PROJECT_DIR` | Project root (auto-set by Claude Code) |

### What to Expect

- **First few sessions**: Little or no knowledge captured (normal)
- **Over time**: Patterns accumulate in state.md
- **Context injection**: Only relevant items surface per-task
- **LLM costs**: Each extract/compile makes one LLM call (~$0.01-0.05)

## Troubleshooting

### Hooks not firing

1. Check if wm is in PATH: `which wm`
2. Check if `.wm/` exists in project
3. Reinstall plugin after updates:
   ```bash
   claude plugin uninstall wm
   claude plugin install ./plugin
   # Restart Claude Code
   ```

### No knowledge being captured

- Most sessions genuinely have no tacit knowledge worth capturing
- Check `.wm/hook.log` for extraction activity
- Verify superego is installed (it triggers extraction)

### State.md has wrong content

- System reminders (CLAUDE.md content) should be stripped
- If seeing explicit instructions, check transcript reader is up to date

## License

Source-available. See [LICENSE.md](LICENSE.md) for details.

## Part of Cloud Atlas AI

wm is part of the [Cloud Atlas AI](https://github.com/cloud-atlas-ai) ecosystem:

- **[Open Horizons]https://github.com/cloud-atlas-ai/open-horizons** — Strategic alignment platform
- **[superego]https://github.com/cloud-atlas-ai/superego** — Metacognitive advisor
- **[wm]https://github.com/cloud-atlas-ai/wm** — Working memory (this project)
- **[oh-mcp-server]https://github.com/cloud-atlas-ai/oh-mcp-server** — MCP bridge to Open Horizons