cc-brain 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # cc-brain
2
+
3
+ Persistent memory for [Claude Code](https://github.com/anthropics/claude-code). Remembers context across sessions.
4
+
5
+ ## What It Does
6
+
7
+ Claude Code sessions are ephemeral - when context fills up or you start a new session, everything is forgotten. cc-brain fixes this by:
8
+
9
+ - **Loading** your profile and project context on every session start
10
+ - **Saving** important learnings before context compaction
11
+ - **Searching** past sessions for decisions and context
12
+
13
+ ## Installation
14
+
15
+ Choose your preferred method:
16
+
17
+ ### Option 1: npm (recommended)
18
+
19
+ ```bash
20
+ npm install -g cc-brain
21
+ cc-brain install
22
+ ```
23
+
24
+ ### Option 2: npx/bunx (no install)
25
+
26
+ ```bash
27
+ npx cc-brain install
28
+ # or
29
+ bunx cc-brain install
30
+ ```
31
+
32
+ ### Option 3: Claude Plugin
33
+
34
+ ```bash
35
+ claude plugins add cc-brain
36
+ ```
37
+
38
+ ### Option 4: Git Clone
39
+
40
+ ```bash
41
+ git clone https://github.com/tripzcodes/cc-brain.git
42
+ cd cc-brain
43
+ node scripts/install.js
44
+ ```
45
+
46
+ ## Memory Tiers
47
+
48
+ ```
49
+ ~/.claude/brain/
50
+ ├── user.md # T1: Your profile (always loaded)
51
+ ├── preferences.md # T1: Code preferences (always loaded)
52
+ └── projects/{id}/
53
+ ├── context.md # T2: Current project state
54
+ └── archive/ # T3: Session history
55
+ └── 2025-01-31.md
56
+ ```
57
+
58
+ | Tier | What | Limit | Loaded |
59
+ |------|------|-------|--------|
60
+ | T1 | User identity & preferences | 80 lines | Always |
61
+ | T2 | Project context | 120 lines | Current project |
62
+ | T3 | Archive | Unlimited | On-demand |
63
+
64
+ ## Skills
65
+
66
+ | Command | Description |
67
+ |---------|-------------|
68
+ | `/save` | Save session context to brain |
69
+ | `/recall <query>` | Search archive for past context |
70
+ | `/brain` | View current brain state |
71
+
72
+ ## CLI
73
+
74
+ ```bash
75
+ cc-brain install # Install hooks
76
+ cc-brain uninstall # Remove hooks
77
+ cc-brain uninstall --purge # Remove everything
78
+
79
+ cc-brain recall "query" # Search archive
80
+ cc-brain archive list # List archive entries
81
+ cc-brain archive stats # Show statistics
82
+ cc-brain archive prune --keep 20 # Keep last 20
83
+
84
+ cc-brain project-id --init # Create stable .brain-id
85
+ cc-brain save --dry-run --json '{"t2": {"focus": "testing"}}'
86
+ ```
87
+
88
+ ## How It Works
89
+
90
+ 1. **SessionStart hook** runs on every session:
91
+ - Loads T1 (user profile + preferences)
92
+ - Loads T2 (current project context)
93
+ - Auto-prunes archives older than 90 days
94
+
95
+ 2. **PreCompact hook** triggers before context dies:
96
+ - Analyzes session for important learnings
97
+ - Saves to appropriate tier using structured format
98
+
99
+ 3. **Skills** for manual control:
100
+ - `/save` - capture context anytime
101
+ - `/recall` - search past sessions
102
+ - `/brain` - see what's loaded
103
+
104
+ ## Project Identity
105
+
106
+ By default, projects are identified by directory name. For stable identity that survives renames:
107
+
108
+ ```bash
109
+ cc-brain project-id --init
110
+ ```
111
+
112
+ This creates a `.brain-id` file with a UUID. Commit it to your repo.
113
+
114
+ ## Uninstall
115
+
116
+ ```bash
117
+ cc-brain uninstall # Remove hooks, keep brain data
118
+ cc-brain uninstall --purge # Remove everything
119
+ ```
120
+
121
+ Or if installed via npm:
122
+
123
+ ```bash
124
+ npm uninstall -g cc-brain
125
+ ```
126
+
127
+ ## Requirements
128
+
129
+ - Node.js >= 18 or [Bun](https://bun.sh)
130
+ - [Claude Code](https://github.com/anthropics/claude-code) CLI
131
+
132
+ ## License
133
+
134
+ MIT
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * cc-brain CLI
5
+ * Persistent memory for Claude Code
6
+ */
7
+
8
+ import { spawn, execSync } from 'child_process';
9
+ import { fileURLToPath } from 'url';
10
+ import { dirname, join } from 'path';
11
+
12
+ const __dirname = dirname(fileURLToPath(import.meta.url));
13
+ const ROOT = join(__dirname, '..');
14
+
15
+ const command = process.argv[2];
16
+ const args = process.argv.slice(3);
17
+
18
+ // Check for bun, fallback to node
19
+ let runtime = 'node';
20
+ try {
21
+ execSync('bun --version', { stdio: 'ignore' });
22
+ runtime = 'bun';
23
+ } catch {
24
+ // bun not available, use node
25
+ }
26
+
27
+ const commands = {
28
+ install: 'scripts/install.js',
29
+ uninstall: 'scripts/uninstall.js',
30
+ load: 'src/loader.js',
31
+ save: 'src/saver.js',
32
+ recall: 'src/recall.js',
33
+ archive: 'src/archive.js',
34
+ 'project-id': 'src/project-id.js',
35
+ };
36
+
37
+ function showHelp() {
38
+ console.log(`cc-brain - Persistent memory for Claude Code
39
+
40
+ Usage: cc-brain <command> [options]
41
+
42
+ Commands:
43
+ install Install hooks to Claude Code
44
+ uninstall Remove hooks (--purge to delete data)
45
+ load Load brain (usually run by hook)
46
+ save Save to brain (--json '{}' --dry-run)
47
+ recall Search archive (query)
48
+ archive Manage archive (list|stats|prune)
49
+ project-id Manage project identity (--init|--path)
50
+
51
+ Examples:
52
+ cc-brain install
53
+ cc-brain uninstall --purge
54
+ cc-brain recall "authentication"
55
+ cc-brain archive stats
56
+ cc-brain project-id --init
57
+
58
+ More info: https://github.com/tripzcodes/cc-brain`);
59
+ }
60
+
61
+ if (!command || command === '--help' || command === '-h') {
62
+ showHelp();
63
+ process.exit(0);
64
+ }
65
+
66
+ if (command === '--version' || command === '-v') {
67
+ const pkg = await import('../package.json', { assert: { type: 'json' } });
68
+ console.log(pkg.default.version);
69
+ process.exit(0);
70
+ }
71
+
72
+ if (!commands[command]) {
73
+ console.error(`Unknown command: ${command}`);
74
+ console.error('Run cc-brain --help for usage');
75
+ process.exit(1);
76
+ }
77
+
78
+ const script = join(ROOT, commands[command]);
79
+ const child = spawn(runtime, [script, ...args], {
80
+ stdio: 'inherit',
81
+ cwd: process.cwd(),
82
+ env: { ...process.env, CLAUDE_PROJECT_DIR: process.cwd() }
83
+ });
84
+
85
+ child.on('exit', (code) => process.exit(code || 0));
@@ -0,0 +1,13 @@
1
+ # Code & Tool Preferences
2
+
3
+ ## Code Style
4
+
5
+
6
+ ## Frameworks & Tools
7
+
8
+
9
+ ## Patterns
10
+
11
+
12
+ ## Avoid
13
+
File without changes
@@ -0,0 +1,16 @@
1
+ # Project Context
2
+
3
+ ## What
4
+ (One-liner: what this project is)
5
+
6
+ ## Current Focus
7
+ (What we're actively working on)
8
+
9
+ ## Decisions
10
+ (Key choices made + why)
11
+
12
+ ## Key Files
13
+ (Important files and their purposes)
14
+
15
+ ## Blockers
16
+ (Known issues or questions)
package/brain/user.md ADDED
@@ -0,0 +1,13 @@
1
+ # User Profile
2
+
3
+ ## Communication Style
4
+
5
+
6
+ ## Thinking Patterns
7
+
8
+
9
+ ## Preferences
10
+
11
+
12
+ ## Pet Peeves
13
+
@@ -0,0 +1,27 @@
1
+ {
2
+ "SessionStart": [
3
+ {
4
+ "matcher": "startup|resume|compact",
5
+ "hooks": [
6
+ {
7
+ "type": "command",
8
+ "command": "bun \"$CLAUDE_PROJECT_DIR/src/loader.js\"",
9
+ "timeout": 5,
10
+ "statusMessage": "Loading brain..."
11
+ }
12
+ ]
13
+ }
14
+ ],
15
+ "PreCompact": [
16
+ {
17
+ "hooks": [
18
+ {
19
+ "type": "agent",
20
+ "prompt": "Context is being compacted. Save important information using the structured saver.\n\nANALYZE this session for:\n- New user insights (T1 - rare)\n- New preferences (T1 - rare)\n- Project decisions + rationale (T2)\n- Current focus/state (T2)\n- Session summary (T3 - if significant)\n\nBUILD JSON payload:\n```json\n{\n \"t2\": {\n \"what\": \"Project description\",\n \"focus\": [\"current tasks\"],\n \"decisions\": {\"decision\": \"rationale\"}\n },\n \"t3\": \"Session summary if significant work done.\"\n}\n```\n\nSAVE using:\n```bash\nbun src/saver.js --json '<payload>'\n```\n\nRules:\n- Only include tiers with new info\n- T2 updates are common, T1 updates are rare\n- Decisions need rationale\n- Keep it concise",
21
+ "timeout": 120,
22
+ "statusMessage": "Saving to brain..."
23
+ }
24
+ ]
25
+ }
26
+ ]
27
+ }
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "cc-brain",
3
+ "version": "0.1.0",
4
+ "description": "Persistent memory system for Claude Code - remembers context across sessions",
5
+ "type": "module",
6
+ "bin": {
7
+ "cc-brain": "./bin/cc-brain.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "scripts",
13
+ "skills",
14
+ "hooks",
15
+ "brain",
16
+ "plugin.json"
17
+ ],
18
+ "scripts": {
19
+ "postinstall": "node scripts/install.js",
20
+ "preuninstall": "node scripts/uninstall.js",
21
+ "test": "node src/loader.js"
22
+ },
23
+ "keywords": [
24
+ "claude",
25
+ "claude-code",
26
+ "memory",
27
+ "context",
28
+ "ai",
29
+ "persistent",
30
+ "brain"
31
+ ],
32
+ "author": "",
33
+ "license": "MIT",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/tripzcodes/cc-brain.git"
37
+ },
38
+ "homepage": "https://github.com/tripzcodes/cc-brain#readme",
39
+ "bugs": {
40
+ "url": "https://github.com/tripzcodes/cc-brain/issues"
41
+ },
42
+ "engines": {
43
+ "node": ">=18.0.0"
44
+ }
45
+ }
package/plugin.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "cc-brain",
3
+ "version": "0.1.0",
4
+ "description": "Persistent memory system for Claude Code",
5
+ "skills": [
6
+ "skills/save.md",
7
+ "skills/recall.md",
8
+ "skills/brain.md"
9
+ ],
10
+ "hooks": "hooks/hooks.json"
11
+ }
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Install cc-brain
5
+ * Sets up brain directory and hooks
6
+ */
7
+
8
+ import { existsSync, mkdirSync, copyFileSync, readFileSync, writeFileSync, unlinkSync } from 'fs';
9
+ import { join } from 'path';
10
+ import { homedir } from 'os';
11
+
12
+ const HOME = homedir();
13
+ const CLAUDE_DIR = join(HOME, '.claude');
14
+ const BRAIN_DIR = join(CLAUDE_DIR, 'brain');
15
+ const PROJECT_ROOT = join(import.meta.dirname, '..');
16
+
17
+ console.log('Installing cc-brain...\n');
18
+
19
+ // Create brain directory structure
20
+ const dirs = [
21
+ BRAIN_DIR,
22
+ join(BRAIN_DIR, 'projects')
23
+ ];
24
+
25
+ for (const dir of dirs) {
26
+ if (!existsSync(dir)) {
27
+ mkdirSync(dir, { recursive: true });
28
+ console.log(`Created: ${dir}`);
29
+ }
30
+ }
31
+
32
+ // Clean up legacy files from previous versions
33
+ const legacyFiles = [
34
+ join(BRAIN_DIR, 'load-brain.sh'),
35
+ ];
36
+
37
+ for (const file of legacyFiles) {
38
+ if (existsSync(file)) {
39
+ unlinkSync(file);
40
+ console.log(`Removed: ${file} (legacy)`);
41
+ }
42
+ }
43
+
44
+ // Copy template brain files if they don't exist
45
+ const templates = ['user.md', 'preferences.md'];
46
+ for (const file of templates) {
47
+ const dest = join(BRAIN_DIR, file);
48
+ if (!existsSync(dest)) {
49
+ copyFileSync(join(PROJECT_ROOT, 'brain', file), dest);
50
+ console.log(`Created: ${dest}`);
51
+ } else {
52
+ console.log(`Exists: ${dest} (skipped)`);
53
+ }
54
+ }
55
+
56
+ // Add hooks to settings.json
57
+ const settingsPath = join(CLAUDE_DIR, 'settings.json');
58
+ let settings = {};
59
+
60
+ if (existsSync(settingsPath)) {
61
+ settings = JSON.parse(readFileSync(settingsPath, 'utf-8'));
62
+ }
63
+
64
+ // Read our hooks config
65
+ const hooks = JSON.parse(readFileSync(join(PROJECT_ROOT, 'hooks', 'hooks.json'), 'utf-8'));
66
+
67
+ // Update loader path to absolute (forward slashes for cross-platform)
68
+ const loaderPath = join(PROJECT_ROOT, 'src', 'loader.js').replace(/\\/g, '/');
69
+ hooks.SessionStart[0].hooks[0].command = `bun "${loaderPath}"`;
70
+
71
+ // Merge hooks (preserve existing hooks, add ours)
72
+ settings.hooks = settings.hooks || {};
73
+ settings.hooks.SessionStart = hooks.SessionStart;
74
+ settings.hooks.PreCompact = hooks.PreCompact;
75
+
76
+ writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
77
+ console.log(`\nUpdated: ${settingsPath}`);
78
+
79
+ console.log(`
80
+ cc-brain installed!
81
+
82
+ Brain location: ${BRAIN_DIR}
83
+
84
+ Memory tiers:
85
+ T1 (always): user.md, preferences.md
86
+ T2 (project): projects/{name}/context.md
87
+ T3 (archive): projects/{name}/archive/
88
+
89
+ Hooks installed:
90
+ SessionStart → loads T1 + T2 into context
91
+ PreCompact → saves important bits before compaction
92
+
93
+ Edit your brain:
94
+ ${BRAIN_DIR}/user.md
95
+ ${BRAIN_DIR}/preferences.md
96
+ `);
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Uninstall cc-brain
5
+ * Removes hooks from settings.json
6
+ * Use --purge to also delete brain data
7
+ */
8
+
9
+ import { existsSync, readFileSync, writeFileSync, rmSync } from 'fs';
10
+ import { join } from 'path';
11
+ import { homedir } from 'os';
12
+
13
+ const HOME = homedir();
14
+ const CLAUDE_DIR = join(HOME, '.claude');
15
+ const BRAIN_DIR = join(CLAUDE_DIR, 'brain');
16
+ const SETTINGS_PATH = join(CLAUDE_DIR, 'settings.json');
17
+
18
+ const purge = process.argv.includes('--purge');
19
+
20
+ console.log('Uninstalling cc-brain...\n');
21
+
22
+ // Remove hooks from settings.json
23
+ if (existsSync(SETTINGS_PATH)) {
24
+ const settings = JSON.parse(readFileSync(SETTINGS_PATH, 'utf-8'));
25
+
26
+ if (settings.hooks) {
27
+ delete settings.hooks.SessionStart;
28
+ delete settings.hooks.PreCompact;
29
+
30
+ // Clean up empty hooks object
31
+ if (Object.keys(settings.hooks).length === 0) {
32
+ delete settings.hooks;
33
+ }
34
+
35
+ writeFileSync(SETTINGS_PATH, JSON.stringify(settings, null, 2));
36
+ console.log(`Removed hooks from: ${SETTINGS_PATH}`);
37
+ } else {
38
+ console.log('No hooks found in settings.json');
39
+ }
40
+ } else {
41
+ console.log('No settings.json found');
42
+ }
43
+
44
+ // Optionally remove brain data
45
+ if (purge) {
46
+ if (existsSync(BRAIN_DIR)) {
47
+ rmSync(BRAIN_DIR, { recursive: true, force: true });
48
+ console.log(`Deleted: ${BRAIN_DIR}`);
49
+ } else {
50
+ console.log('No brain directory found');
51
+ }
52
+ console.log('\ncc-brain completely removed (hooks + data).');
53
+ } else {
54
+ console.log(`
55
+ cc-brain hooks removed.
56
+
57
+ Brain data preserved at: ${BRAIN_DIR}
58
+
59
+ To also delete brain data, run:
60
+ bun scripts/uninstall.js --purge
61
+ `);
62
+ }
@@ -0,0 +1,55 @@
1
+ ---
2
+ name: brain
3
+ description: View current brain state (what Claude remembers about you)
4
+ user_invocable: true
5
+ ---
6
+
7
+ # View Brain State
8
+
9
+ Show the user what's currently in persistent memory.
10
+
11
+ ## Instructions
12
+
13
+ 1. **Show Tier 1** (always loaded):
14
+ ```bash
15
+ cat ~/.claude/brain/user.md
16
+ cat ~/.claude/brain/preferences.md
17
+ ```
18
+
19
+ 2. **Show Tier 2** (current project):
20
+ ```bash
21
+ bun src/project-id.js --path
22
+ # Then read context.md from that path
23
+ ```
24
+
25
+ 3. **Show Tier 3 stats**:
26
+ ```bash
27
+ bun src/archive.js stats
28
+ ```
29
+
30
+ 4. **Format output** showing:
31
+ - T1: User profile and preferences
32
+ - T2: Current project context
33
+ - T3: Archive statistics (count, date range, size)
34
+
35
+ 5. **Note any empty sections** or missing files
36
+
37
+ 6. **Remind user** of available commands:
38
+ - `/save` - Update brain from session
39
+ - `/recall <query>` - Search archive
40
+ - `bun src/archive.js list` - List all archive entries
41
+ - `bun src/archive.js prune --keep 20` - Prune old entries
42
+ - Direct file edits for precision
43
+
44
+ ## Project Identity
45
+
46
+ Show the project ID being used:
47
+ ```bash
48
+ bun src/project-id.js
49
+ ```
50
+
51
+ If using directory name fallback, suggest:
52
+ ```bash
53
+ bun src/project-id.js --init
54
+ ```
55
+ to create a stable `.brain-id` file.
@@ -0,0 +1,44 @@
1
+ ---
2
+ name: recall
3
+ description: Search brain archive for past context and decisions
4
+ args: query
5
+ user_invocable: true
6
+ ---
7
+
8
+ # Recall from Brain Archive
9
+
10
+ Search Tier 3 archive for historical context.
11
+
12
+ ## Instructions
13
+
14
+ The user wants to recall: `$ARGUMENTS`
15
+
16
+ 1. **Run the search**:
17
+ ```bash
18
+ bun src/recall.js "$ARGUMENTS"
19
+ ```
20
+
21
+ 2. **For regex patterns or context**:
22
+ ```bash
23
+ bun src/recall.js "$ARGUMENTS" --context
24
+ ```
25
+
26
+ 3. **Present the results** to the user:
27
+ - What was found
28
+ - When it was recorded (from dates)
29
+ - Key relevant details
30
+
31
+ 4. **If nothing found**, let the user know and suggest:
32
+ - Different search terms
33
+ - Checking T2 context.md for recent info
34
+
35
+ ## Examples
36
+
37
+ User: `/recall authentication`
38
+ → Searches archive for anything about auth decisions, implementations, issues
39
+
40
+ User: `/recall why did we choose bun`
41
+ → Look for decision rationale in archive
42
+
43
+ User: `/recall API.*endpoint`
44
+ → Regex search for API endpoint mentions
package/skills/save.md ADDED
@@ -0,0 +1,73 @@
1
+ ---
2
+ name: save
3
+ description: Save important context to brain memory
4
+ user_invocable: true
5
+ ---
6
+
7
+ # Save to Brain
8
+
9
+ Save important information from this session to persistent memory.
10
+
11
+ ## Instructions
12
+
13
+ 1. **Analyze this session** and identify what's worth saving:
14
+ - New insights about the user (T1 - rare)
15
+ - New code/tool preferences (T1 - rare)
16
+ - Project decisions + rationale (T2 - common)
17
+ - Current focus/state (T2 - common)
18
+ - Session summary (T3 - if significant work done)
19
+
20
+ 2. **Build the save payload** as JSON:
21
+
22
+ ```json
23
+ {
24
+ "t1_user": {
25
+ "Communication Style": ["new insight 1", "new insight 2"],
26
+ "Pet Peeves": ["discovered pet peeve"]
27
+ },
28
+ "t1_prefs": {
29
+ "Code Style": ["preference learned"],
30
+ "Tools": ["tool preference"]
31
+ },
32
+ "t2": {
33
+ "what": "One-line project description",
34
+ "focus": ["current task 1", "current task 2"],
35
+ "decisions": {
36
+ "Decision made": "rationale for why"
37
+ },
38
+ "files": {
39
+ "path/to/file.js": "what it does"
40
+ },
41
+ "blockers": ["any blockers"]
42
+ },
43
+ "t3": "Summary of significant work done this session."
44
+ }
45
+ ```
46
+
47
+ 3. **Preview changes** with dry-run:
48
+ ```bash
49
+ bun src/saver.js --dry-run --json '<payload>'
50
+ ```
51
+
52
+ 4. **Apply changes** if preview looks good:
53
+ ```bash
54
+ bun src/saver.js --json '<payload>'
55
+ ```
56
+
57
+ 5. **Report** what was saved.
58
+
59
+ ## Rules
60
+
61
+ - Only include tiers that have new information
62
+ - T1 updates are rare - only genuine new user insights
63
+ - T2 updates are common - project state changes frequently
64
+ - T3 is optional - only for significant sessions
65
+ - REPLACE outdated info, don't append endlessly
66
+ - Decisions need rationale (the "why")
67
+
68
+ ## Size Limits
69
+
70
+ - T1 user.md: 40 lines max
71
+ - T1 preferences.md: 40 lines max
72
+ - T2 context.md: 120 lines max
73
+ - T3 archive: unlimited (but keep summaries concise)