claude-mem 3.3.10 → 3.3.12

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.
Files changed (104) hide show
  1. package/README.md +8 -1
  2. package/bin/claude-mem-linux +0 -0
  3. package/bin/claude-mem-linux-arm64 +0 -0
  4. package/bin/claude-mem-macos-arm64 +0 -0
  5. package/bin/claude-mem-macos-x64 +0 -0
  6. package/bin/claude-mem.exe +0 -0
  7. package/claude-mem +60 -0
  8. package/hooks/pre-compact.js +4 -0
  9. package/hooks/session-end.js +4 -0
  10. package/hooks/session-start.js +4 -0
  11. package/package.json +7 -56
  12. package/dist/bin/cli.d.ts +0 -2
  13. package/dist/bin/cli.js +0 -179
  14. package/dist/commands/compress.d.ts +0 -2
  15. package/dist/commands/compress.js +0 -27
  16. package/dist/commands/hooks.d.ts +0 -19
  17. package/dist/commands/hooks.js +0 -131
  18. package/dist/commands/install.d.ts +0 -2
  19. package/dist/commands/install.js +0 -836
  20. package/dist/commands/load-context.d.ts +0 -2
  21. package/dist/commands/load-context.js +0 -151
  22. package/dist/commands/logs.d.ts +0 -2
  23. package/dist/commands/logs.js +0 -76
  24. package/dist/commands/migrate-to-jsonl.d.ts +0 -5
  25. package/dist/commands/migrate-to-jsonl.js +0 -99
  26. package/dist/commands/restore.d.ts +0 -1
  27. package/dist/commands/restore.js +0 -20
  28. package/dist/commands/status.d.ts +0 -1
  29. package/dist/commands/status.js +0 -136
  30. package/dist/commands/trash-empty.d.ts +0 -3
  31. package/dist/commands/trash-empty.js +0 -56
  32. package/dist/commands/trash-view.d.ts +0 -1
  33. package/dist/commands/trash-view.js +0 -101
  34. package/dist/commands/trash.d.ts +0 -6
  35. package/dist/commands/trash.js +0 -49
  36. package/dist/commands/uninstall.d.ts +0 -2
  37. package/dist/commands/uninstall.js +0 -107
  38. package/dist/constants.d.ts +0 -241
  39. package/dist/constants.js +0 -179
  40. package/dist/core/compression/TranscriptCompressor.d.ts +0 -79
  41. package/dist/core/compression/TranscriptCompressor.js +0 -585
  42. package/dist/core/orchestration/PromptOrchestrator.d.ts +0 -165
  43. package/dist/core/orchestration/PromptOrchestrator.js +0 -182
  44. package/dist/lib/time-utils.d.ts +0 -5
  45. package/dist/lib/time-utils.js +0 -70
  46. package/dist/prompts/constants.d.ts +0 -126
  47. package/dist/prompts/constants.js +0 -161
  48. package/dist/prompts/index.d.ts +0 -10
  49. package/dist/prompts/index.js +0 -11
  50. package/dist/prompts/templates/analysis/AnalysisTemplates.d.ts +0 -13
  51. package/dist/prompts/templates/analysis/AnalysisTemplates.js +0 -94
  52. package/dist/prompts/templates/context/ContextTemplates.d.ts +0 -119
  53. package/dist/prompts/templates/context/ContextTemplates.js +0 -399
  54. package/dist/prompts/templates/hooks/HookTemplates.d.ts +0 -175
  55. package/dist/prompts/templates/hooks/HookTemplates.js +0 -394
  56. package/dist/prompts/templates/hooks/HookTemplates.test.d.ts +0 -7
  57. package/dist/prompts/templates/hooks/HookTemplates.test.js +0 -127
  58. package/dist/shared/config.d.ts +0 -4
  59. package/dist/shared/config.js +0 -42
  60. package/dist/shared/error-handler.d.ts +0 -22
  61. package/dist/shared/error-handler.js +0 -142
  62. package/dist/shared/logger.d.ts +0 -19
  63. package/dist/shared/logger.js +0 -51
  64. package/dist/shared/paths.d.ts +0 -28
  65. package/dist/shared/paths.js +0 -100
  66. package/dist/shared/settings.d.ts +0 -41
  67. package/dist/shared/settings.js +0 -81
  68. package/dist/shared/types.d.ts +0 -145
  69. package/dist/shared/types.js +0 -78
  70. package/docs/STATUS.md +0 -155
  71. package/docs/chroma-backend-migration.md +0 -161
  72. package/docs/landing-page-outline.md +0 -287
  73. package/docs/multi-platform-builds.md +0 -96
  74. package/docs/plans/cloud-service-plan.md +0 -274
  75. package/docs/plans/fix-response-format-issue.md +0 -61
  76. package/docs/plans/restructure-session-hook-output.md +0 -102
  77. package/docs/plans/session-start-hook-investigation.md +0 -45
  78. package/docs/plans/src-reorganization-plan.md +0 -181
  79. package/docs/plans/terminal-effects-decision.md +0 -22
  80. package/docs/plans/terminal-effects-integration.md +0 -82
  81. package/docs/plans/trash-bin-feature-plan.md +0 -240
  82. package/docs/plans/trash-bin-minimal-plan.md +0 -102
  83. package/docs/reference/bun-single-executable.md +0 -584
  84. package/docs/reference/cc-output-styles.md +0 -99
  85. package/docs/reference/chroma-mcp-project-memory-example.md +0 -80
  86. package/docs/reference/chroma-mcp-team-example.md +0 -92
  87. package/docs/reference/claude-code/cc-hooks.md +0 -787
  88. package/docs/reference/claude-code/cc-status-line.md +0 -202
  89. package/docs/reference/claude-code/hook-configuration.md +0 -173
  90. package/docs/reference/claude-code/hook-responses.md +0 -127
  91. package/docs/reference/claude-code/hooks.md +0 -175
  92. package/docs/reference/claude-code/mcp-configuration.md +0 -133
  93. package/docs/reference/claude-code/session-start-hook.md +0 -82
  94. package/docs/reference/load-context-format-example.md +0 -33
  95. package/docs/reference/mcp-sdk/mcp-typescript-sdk-readme.md +0 -1323
  96. package/docs/reference/mcp-sdk/server-implementation.md +0 -286
  97. package/docs/reference/mcp-sdk/stdio-transport.md +0 -345
  98. package/docs/todos/fix-response-format-tasks.md +0 -43
  99. package/docs/todos/implementation-todos.md +0 -280
  100. package/docs/todos/restructure-hook-output-tasks.md +0 -103
  101. package/docs/todos/session-start-hook-fix.md +0 -26
  102. package/docs/todos/terminal-effects-tasks.md +0 -42
  103. package/docs/todos/trash-bin-implementation-todos.md +0 -348
  104. package/docs/todos/trash-bin-minimal-todos.md +0 -27
package/README.md CHANGED
@@ -50,12 +50,17 @@ Transform your Claude Code experience from forgetful to persistent, from isolate
50
50
 
51
51
  ## 🛠 Installation & Setup
52
52
 
53
+ ### Prerequisites
54
+ - Node.js 18+
55
+ - Claude Code CLI installed
56
+ - uv (Python package manager) - automatically installed if missing
57
+
53
58
  ### Quick Install
54
59
  ```bash
55
60
  # Install globally
56
61
  npm install -g claude-mem
57
62
 
58
- # Set up Claude Code integration
63
+ # Set up Claude Code integration (installs uv if needed)
59
64
  claude-mem install
60
65
 
61
66
  # Restart Claude Code to activate
@@ -67,6 +72,8 @@ claude-mem install
67
72
  npx claude-mem install
68
73
  ```
69
74
 
75
+ The `claude-mem install` command will automatically install [uv](https://docs.astral.sh/uv/) if it's not already present on your system. uv is required for the Chroma MCP server that powers the memory system.
76
+
70
77
  ### Verification
71
78
  ```bash
72
79
  # Check installation status
Binary file
Binary file
Binary file
Binary file
Binary file
package/claude-mem ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync } = require('child_process');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+
7
+ // Detect platform and architecture
8
+ const platform = process.platform;
9
+ const arch = process.arch;
10
+
11
+ // Map platform/arch to binary filename
12
+ let binaryName;
13
+
14
+ if (platform === 'win32') {
15
+ binaryName = 'claude-mem.exe';
16
+ } else if (platform === 'linux') {
17
+ if (arch === 'arm64' || arch === 'aarch64') {
18
+ binaryName = 'claude-mem-linux-arm64';
19
+ } else {
20
+ binaryName = 'claude-mem-linux';
21
+ }
22
+ } else if (platform === 'darwin') {
23
+ if (arch === 'arm64') {
24
+ binaryName = 'claude-mem-macos-arm64';
25
+ } else {
26
+ binaryName = 'claude-mem-macos-x64';
27
+ }
28
+ } else {
29
+ console.error(`❌ Unsupported platform: ${platform}-${arch}`);
30
+ console.error('Supported platforms:');
31
+ console.error(' - Windows x64');
32
+ console.error(' - Linux x64');
33
+ console.error(' - Linux ARM64');
34
+ console.error(' - macOS x64');
35
+ console.error(' - macOS ARM64');
36
+ process.exit(1);
37
+ }
38
+
39
+ // Find the binary path
40
+ const binDir = path.join(__dirname, 'bin');
41
+ const binaryPath = path.join(binDir, binaryName);
42
+
43
+ // Check if binary exists
44
+ if (!fs.existsSync(binaryPath)) {
45
+ console.error(`❌ Binary not found: ${binaryPath}`);
46
+ console.error(`Expected binary: ${binaryName}`);
47
+ console.error(`Platform: ${platform}-${arch}`);
48
+ process.exit(1);
49
+ }
50
+
51
+ // Execute the binary with all arguments
52
+ try {
53
+ const args = process.argv.slice(2);
54
+ execSync(`"${binaryPath}" ${args.join(' ')}`, {
55
+ stdio: 'inherit',
56
+ cwd: process.cwd()
57
+ });
58
+ } catch (error) {
59
+ process.exit(error.status || 1);
60
+ }
@@ -18,6 +18,10 @@ import {
18
18
 
19
19
  const cliCommand = loadCliCommand();
20
20
 
21
+ // Set up stdin immediately before any async operations
22
+ process.stdin.setEncoding('utf8');
23
+ process.stdin.resume(); // Explicitly enter flowing mode to prevent data loss
24
+
21
25
  // Read input from stdin
22
26
  let input = '';
23
27
  process.stdin.on('data', chunk => {
@@ -26,6 +26,10 @@ function isSaveOnClearEnabled() {
26
26
  return false;
27
27
  }
28
28
 
29
+ // Set up stdin immediately before any async operations
30
+ process.stdin.setEncoding('utf8');
31
+ process.stdin.resume(); // Explicitly enter flowing mode to prevent data loss
32
+
29
33
  // Read input
30
34
  let input = '';
31
35
  process.stdin.on('data', chunk => {
@@ -21,6 +21,10 @@ import {
21
21
 
22
22
  const cliCommand = loadCliCommand();
23
23
 
24
+ // Set up stdin immediately before any async operations
25
+ process.stdin.setEncoding('utf8');
26
+ process.stdin.resume(); // Explicitly enter flowing mode to prevent data loss
27
+
24
28
  // Read input from stdin
25
29
  let input = '';
26
30
  process.stdin.on('data', chunk => {
package/package.json CHANGED
@@ -1,25 +1,7 @@
1
1
  {
2
2
  "name": "claude-mem",
3
- "version": "3.3.10",
3
+ "version": "3.3.12",
4
4
  "description": "Memory compression system for Claude Code - persist context across sessions",
5
- "type": "module",
6
- "main": "claude-mem",
7
- "scripts": {
8
- "dev": "tsx src/bin/cli.ts",
9
- "dev:install": "node dist/cli.js install --force",
10
- "dev:status": "node dist/cli.js status",
11
- "dev:compress": "node dist/cli.js compress",
12
- "dev:load": "node dist/cli.js load-context",
13
- "dev:uninstall": "node dist/cli.js uninstall",
14
- "build": "tsc",
15
- "test:watch": "npm test -- --watch",
16
- "lint": "eslint 'src/**/*.ts' 'hooks/**/*.ts' 'test/**/*.ts'",
17
- "lint:fix": "npm run lint -- --fix",
18
- "format": "prettier --write 'src/**/*.ts' 'hooks/**/*.ts' 'test/**/*.ts'",
19
- "build:multiplatform": "./scripts/build-multiplatform.sh",
20
- "publish": "./scripts/npm-publish.sh && cd releases/npm-package && npm publish",
21
- "publish:latest": "npm version patch && ./scripts/npm-publish.sh && cd releases/npm-package && npm publish"
22
- },
23
5
  "keywords": [
24
6
  "claude",
25
7
  "claude-code",
@@ -28,9 +10,7 @@
28
10
  "compression",
29
11
  "knowledge-graph",
30
12
  "transcript",
31
- "cli",
32
- "typescript",
33
- "bun"
13
+ "cli"
34
14
  ],
35
15
  "author": "Alex Newman",
36
16
  "license": "SEE LICENSE IN LICENSE",
@@ -46,43 +26,14 @@
46
26
  "access": "public",
47
27
  "registry": "https://registry.npmjs.org/"
48
28
  },
49
- "dependencies": {
50
- "@anthropic-ai/claude-code": "^1.0.88",
51
- "@clack/prompts": "^0.11.0",
52
- "@modelcontextprotocol/sdk": "^0.5.0",
53
- "boxen": "^8.0.1",
54
- "chalk": "^5.6.0",
55
- "commander": "^14.0.0",
56
- "figlet": "^1.8.2",
57
- "glob": "^11.0.3",
58
- "gradient-string": "^3.0.0",
59
- "handlebars": "^4.7.8",
60
- "oh-my-logo": "^0.3.2"
61
- },
62
- "devDependencies": {
63
- "@types/chai": "^4.3.0",
64
- "@types/figlet": "^1.7.0",
65
- "@types/handlebars": "^4.0.40",
66
- "@types/node": "^20.0.0",
67
- "@typescript-eslint/eslint-plugin": "^6.0.0",
68
- "@typescript-eslint/parser": "^6.0.0",
69
- "chai": "^4.3.0",
70
- "eslint": "^8.0.0",
71
- "prettier": "^3.0.0",
72
- "ts-node": "^10.0.0",
73
- "tsx": "^4.20.5",
74
- "typescript": "^5.0.0"
75
- },
76
- "engines": {
77
- "node": ">=18.0.0",
78
- "bun": ">=1.0.0"
79
- },
80
29
  "bin": {
81
- "claude-mem": "dist/bin/cli.js"
30
+ "claude-mem": "./claude-mem"
82
31
  },
83
32
  "files": [
84
- "dist",
33
+ "claude-mem",
34
+ "bin/**",
85
35
  "hooks",
86
- "docs"
36
+ "dist",
37
+ ".mcp.json"
87
38
  ]
88
39
  }
package/dist/bin/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/bin/cli.js DELETED
@@ -1,179 +0,0 @@
1
- #!/usr/bin/env node
2
- // <Block> 1.1 ====================================
3
- // CLI Dependencies and Imports Setup
4
- // Natural pattern: Import what you need before using it
5
- import { Command } from 'commander';
6
- import { PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_DESCRIPTION } from '../shared/config.js';
7
- // Import command handlers
8
- import { compress } from '../commands/compress.js';
9
- import { install } from '../commands/install.js';
10
- import { uninstall } from '../commands/uninstall.js';
11
- import { status } from '../commands/status.js';
12
- import { logs } from '../commands/logs.js';
13
- import { loadContext } from '../commands/load-context.js';
14
- import { trash } from '../commands/trash.js';
15
- import { restore } from '../commands/restore.js';
16
- const program = new Command();
17
- // </Block> =======================================
18
- // <Block> 1.2 ====================================
19
- // Program Configuration
20
- // Natural pattern: Configure program metadata first
21
- program
22
- .name(PACKAGE_NAME)
23
- .description(PACKAGE_DESCRIPTION)
24
- .version(PACKAGE_VERSION);
25
- // </Block> =======================================
26
- // <Block> 1.3 ====================================
27
- // Compress Command Definition
28
- // Natural pattern: Define command with its options and handler
29
- // Compress command
30
- program
31
- .command('compress [transcript]')
32
- .description('Compress a Claude Code transcript into memory')
33
- .option('--output <path>', 'Output directory for compressed files')
34
- .option('--dry-run', 'Show what would be compressed without doing it')
35
- .option('-v, --verbose', 'Show detailed output')
36
- .action(compress);
37
- // </Block> =======================================
38
- // <Block> 1.4 ====================================
39
- // Install Command Definition
40
- // Natural pattern: Define command with its options and handler
41
- // Install command
42
- program
43
- .command('install')
44
- .description('Install Claude Code hooks for automatic compression')
45
- .option('--user', 'Install for current user (default)')
46
- .option('--project', 'Install for current project only')
47
- .option('--local', 'Install to custom local directory')
48
- .option('--path <path>', 'Custom installation path (with --local)')
49
- .option('--timeout <ms>', 'Hook execution timeout in milliseconds', '180000')
50
- .option('--skip-mcp', 'Skip Chroma MCP server installation')
51
- .option('--force', 'Force installation even if already installed')
52
- .action(install);
53
- // </Block> =======================================
54
- // <Block> 1.5 ====================================
55
- // Uninstall Command Definition
56
- // Natural pattern: Define command with its options and handler
57
- // Uninstall command
58
- program
59
- .command('uninstall')
60
- .description('Remove Claude Code hooks')
61
- .option('--user', 'Remove from user settings (default)')
62
- .option('--project', 'Remove from project settings')
63
- .option('--all', 'Remove from both user and project settings')
64
- .action(uninstall);
65
- // </Block> =======================================
66
- // <Block> 1.6 ====================================
67
- // Status Command Definition
68
- // Natural pattern: Define command with its handler
69
- // Status command
70
- program
71
- .command('status')
72
- .description('Check installation status of Claude Memory System')
73
- .action(status);
74
- // </Block> =======================================
75
- // <Block> 1.7 ====================================
76
- // Logs Command Definition
77
- // Natural pattern: Define command with its options and handler
78
- // Logs command
79
- program
80
- .command('logs')
81
- .description('View claude-mem operation logs')
82
- .option('--debug', 'Show debug logs only')
83
- .option('--error', 'Show error logs only')
84
- .option('--tail [n]', 'Show last n lines', '50')
85
- .option('--follow', 'Follow log output')
86
- .action(logs);
87
- // </Block> =======================================
88
- // <Block> 1.8 ====================================
89
- // Load-Context Command Definition
90
- // Natural pattern: Define command with its options and handler
91
- // Load-context command
92
- program
93
- .command('load-context')
94
- .description('Load compressed memories for current session')
95
- .option('--project <name>', 'Filter by project name')
96
- .option('--count <n>', 'Number of memories to load', '10')
97
- .option('--raw', 'Output raw JSON instead of formatted text')
98
- .option('--format <type>', 'Output format: json, session-start, or default')
99
- .action(loadContext);
100
- // </Block> =======================================
101
- // <Block> 1.9 ====================================
102
- // Trash and Restore Commands Definition
103
- // Natural pattern: Define commands for safe file operations
104
- // Trash command with subcommands
105
- const trashCmd = program
106
- .command('trash')
107
- .description('Manage trash bin for safe file deletion')
108
- .argument('[files...]', 'Files to move to trash')
109
- .option('-r, --recursive', 'Remove directories recursively')
110
- .option('-R', 'Remove directories recursively (same as -r)')
111
- .option('-f, --force', 'Suppress errors for nonexistent files')
112
- .action(async (files, options) => {
113
- // If no files provided, show help
114
- if (!files || files.length === 0) {
115
- trashCmd.outputHelp();
116
- return;
117
- }
118
- // Map -R to recursive
119
- if (options.R)
120
- options.recursive = true;
121
- await trash(files, {
122
- force: options.force,
123
- recursive: options.recursive
124
- });
125
- });
126
- // Trash view subcommand
127
- trashCmd
128
- .command('view')
129
- .description('View contents of trash bin')
130
- .action(async () => {
131
- const { viewTrash } = await import('../commands/trash-view.js');
132
- await viewTrash();
133
- });
134
- // Trash empty subcommand
135
- trashCmd
136
- .command('empty')
137
- .description('Permanently delete all files in trash')
138
- .option('-f, --force', 'Skip confirmation prompt')
139
- .action(async (options) => {
140
- const { emptyTrash } = await import('../commands/trash-empty.js');
141
- await emptyTrash(options);
142
- });
143
- // Restore command
144
- program
145
- .command('restore')
146
- .description('Restore files from trash interactively')
147
- .action(restore);
148
- // </Block> =======================================
149
- // <Block> 1.10 ===================================
150
- // Hook Commands for Binary Distribution
151
- // Internal commands called by hook wrappers
152
- program
153
- .command('hook:pre-compact', { hidden: true })
154
- .description('Internal pre-compact hook handler')
155
- .action(async () => {
156
- const { preCompactHook } = await import('../commands/hooks.js');
157
- await preCompactHook();
158
- });
159
- program
160
- .command('hook:session-start', { hidden: true })
161
- .description('Internal session-start hook handler')
162
- .action(async () => {
163
- const { sessionStartHook } = await import('../commands/hooks.js');
164
- await sessionStartHook();
165
- });
166
- program
167
- .command('hook:session-end', { hidden: true })
168
- .description('Internal session-end hook handler')
169
- .action(async () => {
170
- const { sessionEndHook } = await import('../commands/hooks.js');
171
- await sessionEndHook();
172
- });
173
- // </Block> =======================================
174
- // <Block> 1.11 ===================================
175
- // CLI Execution
176
- // Natural pattern: After defining all commands, parse and execute
177
- // Parse arguments and execute
178
- program.parse();
179
- // </Block> =======================================
@@ -1,2 +0,0 @@
1
- import { OptionValues } from 'commander';
2
- export declare function compress(transcript?: string, options?: OptionValues): Promise<void>;
@@ -1,27 +0,0 @@
1
- import { basename } from 'path';
2
- import { createLoadingMessage, createCompletionMessage, createOperationSummary, createUserFriendlyError } from '../prompts/templates/context/ContextTemplates.js';
3
- export async function compress(transcript, options = {}) {
4
- console.log(createLoadingMessage('compressing'));
5
- if (!transcript) {
6
- console.log(createUserFriendlyError('Compression', 'No transcript file provided', 'Please provide a path to a transcript file'));
7
- return;
8
- }
9
- try {
10
- const startTime = Date.now();
11
- // Import and run compression
12
- const { TranscriptCompressor } = await import('../core/compression/TranscriptCompressor.js');
13
- const compressor = new TranscriptCompressor({
14
- verbose: options.verbose || false
15
- });
16
- const sessionId = options.sessionId || basename(transcript, '.jsonl');
17
- const archivePath = await compressor.compress(transcript, sessionId);
18
- const duration = Date.now() - startTime;
19
- console.log(createCompletionMessage('Compression', undefined, `Session archived as ${basename(archivePath)}`));
20
- console.log(createOperationSummary('compress', { count: 1, duration, details: `Session: ${sessionId}` }));
21
- }
22
- catch (error) {
23
- const errorMessage = error instanceof Error ? error.message : String(error);
24
- console.log(createUserFriendlyError('Compression', errorMessage, 'Check that the transcript file exists and you have write permissions'));
25
- throw error; // Re-throw to maintain existing error handling behavior
26
- }
27
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * Hook command handlers for binary distribution
3
- * These execute the actual hook logic embedded in the binary
4
- */
5
- /**
6
- * Pre-compact hook handler
7
- * Runs compression on the Claude Code transcript
8
- */
9
- export declare function preCompactHook(): Promise<void>;
10
- /**
11
- * Session-start hook handler
12
- * Loads context for the new session
13
- */
14
- export declare function sessionStartHook(): Promise<void>;
15
- /**
16
- * Session-end hook handler
17
- * Compresses session transcript when ending with /clear
18
- */
19
- export declare function sessionEndHook(): Promise<void>;
@@ -1,131 +0,0 @@
1
- /**
2
- * Hook command handlers for binary distribution
3
- * These execute the actual hook logic embedded in the binary
4
- */
5
- import { compress } from './compress.js';
6
- import { loadContext } from './load-context.js';
7
- /**
8
- * Pre-compact hook handler
9
- * Runs compression on the Claude Code transcript
10
- */
11
- export async function preCompactHook() {
12
- try {
13
- // Read hook data from stdin (Claude Code sends JSON)
14
- let inputData = '';
15
- // Set up stdin to read data
16
- process.stdin.setEncoding('utf8');
17
- // Collect all input data
18
- for await (const chunk of process.stdin) {
19
- inputData += chunk;
20
- }
21
- // Parse the JSON input
22
- let transcriptPath;
23
- if (inputData) {
24
- try {
25
- const hookData = JSON.parse(inputData);
26
- transcriptPath = hookData.transcript_path;
27
- }
28
- catch (parseError) {
29
- // If JSON parsing fails, treat the input as a direct path
30
- transcriptPath = inputData.trim();
31
- }
32
- }
33
- // Fallback to environment variable or command line argument
34
- if (!transcriptPath) {
35
- transcriptPath = process.env.TRANSCRIPT_PATH || process.argv[2];
36
- }
37
- if (!transcriptPath) {
38
- console.log('🗜️ Compressing session transcript...');
39
- console.log('❌ No transcript path provided to pre-compact hook');
40
- console.log('Hook data received:', inputData || 'none');
41
- console.log('Environment TRANSCRIPT_PATH:', process.env.TRANSCRIPT_PATH || 'not set');
42
- console.log('Command line args:', process.argv.slice(2));
43
- return;
44
- }
45
- // Run compression with the transcript path
46
- await compress(transcriptPath, { dryRun: false });
47
- }
48
- catch (error) {
49
- console.error('Pre-compact hook failed:', error.message);
50
- process.exit(1);
51
- }
52
- }
53
- /**
54
- * Session-start hook handler
55
- * Loads context for the new session
56
- */
57
- export async function sessionStartHook() {
58
- try {
59
- // Read hook data from stdin (Claude Code sends JSON)
60
- let inputData = '';
61
- // Set up stdin to read data
62
- process.stdin.setEncoding('utf8');
63
- // Collect all input data
64
- for await (const chunk of process.stdin) {
65
- inputData += chunk;
66
- }
67
- // Parse the JSON input to get the current working directory
68
- let project;
69
- if (inputData) {
70
- try {
71
- const hookData = JSON.parse(inputData);
72
- // Extract project name from cwd if provided
73
- if (hookData.cwd) {
74
- const pathParts = hookData.cwd.split('/');
75
- project = pathParts[pathParts.length - 1];
76
- }
77
- }
78
- catch (parseError) {
79
- // If JSON parsing fails, continue without project filtering
80
- console.error('Failed to parse session-start hook data:', parseError);
81
- }
82
- }
83
- // If no project from hook data, try to get from current working directory
84
- if (!project) {
85
- const pathParts = process.cwd().split('/');
86
- project = pathParts[pathParts.length - 1];
87
- }
88
- // Load context with session-start format and project filtering
89
- await loadContext({ format: 'session-start', count: '10', project });
90
- }
91
- catch (error) {
92
- console.error('Session-start hook failed:', error.message);
93
- process.exit(1);
94
- }
95
- }
96
- /**
97
- * Session-end hook handler
98
- * Compresses session transcript when ending with /clear
99
- */
100
- export async function sessionEndHook() {
101
- try {
102
- // Read hook data from stdin (Claude Code sends JSON)
103
- let inputData = '';
104
- // Set up stdin to read data
105
- process.stdin.setEncoding('utf8');
106
- // Collect all input data
107
- for await (const chunk of process.stdin) {
108
- inputData += chunk;
109
- }
110
- // Parse the JSON input to check the reason for session end
111
- if (inputData) {
112
- try {
113
- const hookData = JSON.parse(inputData);
114
- // If reason is "clear", compress the session transcript before it's deleted
115
- if (hookData.reason === 'clear' && hookData.transcript_path) {
116
- console.log('🗜️ Compressing current session before /clear...');
117
- await compress(hookData.transcript_path, { dryRun: false });
118
- }
119
- }
120
- catch (parseError) {
121
- // If JSON parsing fails, log but don't fail the hook
122
- console.error('Failed to parse hook data:', parseError);
123
- }
124
- }
125
- console.log('Session ended successfully');
126
- }
127
- catch (error) {
128
- console.error('Session-end hook failed:', error.message);
129
- process.exit(1);
130
- }
131
- }
@@ -1,2 +0,0 @@
1
- import { OptionValues } from 'commander';
2
- export declare function install(options?: OptionValues): Promise<void>;