Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More
TypeScript aiai-agentsai-memoryanthropicartificial-intelligencechromadbclaudeclaude-agent-sdkclaude-agentsclaude-codeclaude-code-pluginclaude-skillsembeddingslong-term-memorymem0memory-engineopenmemoryragsqlitesupermemory
import { expect, it } from 'bun:test';
import { spawnSync } from 'node:child_process';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
const snapshot = 'claude-mem-next.db';
const cases = [
{ label: 'a trailing --dry-run', args: [snapshot, '--dry-run'], valid: false },
{ label: 'a second filename', args: [snapshot, 'claude-mem-other.db'], valid: false },
{ label: 'one snapshot', args: [snapshot], valid: true },
];
it.each(cases)('handles $label before staging or restarting', ({ args, valid }) => {
const dir = mkdtempSync(join(tmpdir(), 'cmem-restore-args-'));
try {
const backups = join(dir, 'backups');
mkdirSync(join(backups, 'auto'), { recursive: true });
writeFileSync(join(backups, 'auto', snapshot), 'fixture');
writeFileSync(join(dir, 'settings.json'), '{}');
const marker = join(backups, 'restore-pending.json');
const previous = JSON.stringify({ snapshot: 'claude-mem-previous.db', requestedAt: 123 });
writeFileSync(marker, previous);
const commands = resolve('src/npx-cli/commands');
const child = spawnSync(process.execPath, ['-e', `
import { mock } from 'bun:test';
mock.module(${JSON.stringify(join(commands, 'runtime.ts'))}, () => ({
runRestartCommand() { console.log('fixture restart'); }
}));
const { runRestoreCommand } = await import(${JSON.stringify(join(commands, 'restore.ts'))});
runRestoreCommand(${JSON.stringify(args)});
`], {
env: { ...process.env, CLAUDE_MEM_DATA_DIR: dir, CLAUDE_CONFIG_DIR: dir, CLAUDE_MEM_WORKER_URL: '' },
encoding: 'utf8',
});
expect(child.status).toBe(valid ? 0 : 1);
expect(child.stdout.includes('fixture restart')).toBe(valid);
if (valid) {
expect(JSON.parse(readFileSync(marker, 'utf8')).snapshot).toBe(snapshot);
} else {
expect(child.stderr).toContain('Usage: npx claude-mem restore <file>');
expect(readFileSync(marker, 'utf8')).toBe(previous);
}
} finally {
rmSync(dir, { recursive: true, force: true });
}
});