claude-context-saver 1.2.0 → 1.2.2
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 +26 -6
- package/backup-core.mjs +1 -1
- package/conv-backup.mjs +3 -3
- package/package.json +1 -1
- package/setup.mjs +12 -12
package/README.md
CHANGED
|
@@ -43,6 +43,15 @@ node setup.mjs -g # global
|
|
|
43
43
|
|
|
44
44
|
Restart Claude Code after installing.
|
|
45
45
|
|
|
46
|
+
## Update
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx claude-context-saver@latest # local
|
|
50
|
+
npx claude-context-saver@latest -g # global
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Re-running the installer overwrites hooks with the latest version.
|
|
54
|
+
|
|
46
55
|
## Uninstall
|
|
47
56
|
|
|
48
57
|
```bash
|
|
@@ -149,7 +158,7 @@ Read .claude/backups/LATEST.md to recover context.
|
|
|
149
158
|
```
|
|
150
159
|
your-project/
|
|
151
160
|
└── .claude/
|
|
152
|
-
├── hooks/
|
|
161
|
+
├── hooks/context-saver/
|
|
153
162
|
│ ├── backup-core.mjs
|
|
154
163
|
│ ├── statusline-monitor.mjs
|
|
155
164
|
│ └── conv-backup.mjs
|
|
@@ -164,7 +173,7 @@ your-project/
|
|
|
164
173
|
|
|
165
174
|
```
|
|
166
175
|
~/.claude/
|
|
167
|
-
├── hooks/
|
|
176
|
+
├── hooks/context-saver/
|
|
168
177
|
│ ├── backup-core.mjs
|
|
169
178
|
│ ├── statusline-monitor.mjs
|
|
170
179
|
│ └── conv-backup.mjs
|
|
@@ -181,13 +190,13 @@ The installer merges these entries into your settings (all existing settings pre
|
|
|
181
190
|
{
|
|
182
191
|
"statusLine": {
|
|
183
192
|
"type": "command",
|
|
184
|
-
"command": "node \".claude/hooks/
|
|
193
|
+
"command": "node \".claude/hooks/context-saver/statusline-monitor.mjs\""
|
|
185
194
|
},
|
|
186
195
|
"hooks": {
|
|
187
196
|
"PreCompact": [{
|
|
188
197
|
"hooks": [{
|
|
189
198
|
"type": "command",
|
|
190
|
-
"command": "node \".claude/hooks/
|
|
199
|
+
"command": "node \".claude/hooks/context-saver/conv-backup.mjs\"",
|
|
191
200
|
"async": true
|
|
192
201
|
}]
|
|
193
202
|
}]
|
|
@@ -200,13 +209,13 @@ The installer merges these entries into your settings (all existing settings pre
|
|
|
200
209
|
{
|
|
201
210
|
"statusLine": {
|
|
202
211
|
"type": "command",
|
|
203
|
-
"command": "node \"$HOME/.claude/hooks/
|
|
212
|
+
"command": "node \"$HOME/.claude/hooks/context-saver/statusline-monitor.mjs\""
|
|
204
213
|
},
|
|
205
214
|
"hooks": {
|
|
206
215
|
"PreCompact": [{
|
|
207
216
|
"hooks": [{
|
|
208
217
|
"type": "command",
|
|
209
|
-
"command": "node \"$HOME/.claude/hooks/
|
|
218
|
+
"command": "node \"$HOME/.claude/hooks/context-saver/conv-backup.mjs\"",
|
|
210
219
|
"async": true
|
|
211
220
|
}]
|
|
212
221
|
}]
|
|
@@ -214,6 +223,17 @@ The installer merges these entries into your settings (all existing settings pre
|
|
|
214
223
|
}
|
|
215
224
|
```
|
|
216
225
|
|
|
226
|
+
## Context Window & Compaction
|
|
227
|
+
|
|
228
|
+
Claude Code auto-compacts at ~83.5% context usage. This is built into Claude Code and **cannot be changed**. The 33K token buffer is reserved for compaction's own summary.
|
|
229
|
+
|
|
230
|
+
On a 200K context window:
|
|
231
|
+
- ~167K tokens are usable before compaction fires
|
|
232
|
+
- The remaining 33K is untouchable buffer
|
|
233
|
+
- After compaction, context resets to a lossy summary + system prompt + CLAUDE.md
|
|
234
|
+
|
|
235
|
+
This tool doesn't prevent compaction — it makes sure you have detailed backups before it happens, and recovers them automatically after.
|
|
236
|
+
|
|
217
237
|
## Requirements
|
|
218
238
|
|
|
219
239
|
- Node.js >= 18
|
package/backup-core.mjs
CHANGED
|
@@ -304,7 +304,7 @@ export async function createBackup({ transcriptPath, sessionId, projectDir, trig
|
|
|
304
304
|
return { path: backupPath, num };
|
|
305
305
|
} catch (err) {
|
|
306
306
|
// Backup should never crash the host process
|
|
307
|
-
process.stderr.write(`[context-
|
|
307
|
+
process.stderr.write(`[context-saver] Backup failed: ${err.message}\n`);
|
|
308
308
|
return null;
|
|
309
309
|
}
|
|
310
310
|
}
|
package/conv-backup.mjs
CHANGED
|
@@ -15,7 +15,7 @@ async function main() {
|
|
|
15
15
|
try {
|
|
16
16
|
data = JSON.parse(input);
|
|
17
17
|
} catch {
|
|
18
|
-
process.stderr.write('[context-
|
|
18
|
+
process.stderr.write('[context-saver] PreCompact: invalid stdin\n');
|
|
19
19
|
process.exit(0);
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -38,10 +38,10 @@ async function main() {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
if (result) {
|
|
41
|
-
process.stderr.write(`[context-
|
|
41
|
+
process.stderr.write(`[context-saver] PreCompact backup saved: ${result.path}\n`);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
main().catch(err => {
|
|
46
|
-
process.stderr.write(`[context-
|
|
46
|
+
process.stderr.write(`[context-saver] PreCompact error: ${err.message}\n`);
|
|
47
47
|
});
|
package/package.json
CHANGED
package/setup.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// setup.mjs — One-command installer for
|
|
2
|
+
// setup.mjs — One-command installer for claude-context-saver
|
|
3
3
|
// Usage: node setup.mjs [-g] [--uninstall]
|
|
4
4
|
// Default: local install to project .claude/
|
|
5
5
|
// -g: install globally to ~/.claude/ (all projects)
|
|
@@ -22,15 +22,15 @@ const isHelp = args.includes('--help') || args.includes('-h');
|
|
|
22
22
|
const CLAUDE_DIR = isLocal
|
|
23
23
|
? join(process.cwd(), '.claude')
|
|
24
24
|
: join(homedir(), '.claude');
|
|
25
|
-
const HOOKS_DIR = join(CLAUDE_DIR, 'hooks', '
|
|
25
|
+
const HOOKS_DIR = join(CLAUDE_DIR, 'hooks', 'context-saver');
|
|
26
26
|
const SETTINGS_PATH = join(CLAUDE_DIR, 'settings.json');
|
|
27
27
|
|
|
28
28
|
// Command paths used inside settings.json
|
|
29
29
|
// Global: use $HOME so it works across shells (Git Bash, etc.)
|
|
30
30
|
// Local: use .claude/ relative path (Claude Code runs from project root)
|
|
31
31
|
const HOOK_CMD_PREFIX = isLocal
|
|
32
|
-
? '.claude/hooks/
|
|
33
|
-
: '$HOME/.claude/hooks/
|
|
32
|
+
? '.claude/hooks/context-saver'
|
|
33
|
+
: '$HOME/.claude/hooks/context-saver';
|
|
34
34
|
|
|
35
35
|
const SCRIPTS = ['backup-core.mjs', 'statusline-monitor.mjs', 'conv-backup.mjs'];
|
|
36
36
|
|
|
@@ -116,7 +116,7 @@ function removeClaudeMdRecovery(projectDir) {
|
|
|
116
116
|
|
|
117
117
|
function install() {
|
|
118
118
|
const mode = isLocal ? 'local (this project only)' : 'global (all projects)';
|
|
119
|
-
console.log(`
|
|
119
|
+
console.log(`claude-context-saver — Installing ${mode}...\n`);
|
|
120
120
|
|
|
121
121
|
// 1. Copy scripts to hooks dir
|
|
122
122
|
mkdirSync(HOOKS_DIR, { recursive: true });
|
|
@@ -133,7 +133,7 @@ function install() {
|
|
|
133
133
|
const configs = makeConfigs();
|
|
134
134
|
|
|
135
135
|
// Check for existing statusLine
|
|
136
|
-
if (settings.statusLine && settings.statusLine.command && !settings.statusLine.command.includes('
|
|
136
|
+
if (settings.statusLine && settings.statusLine.command && !settings.statusLine.command.includes('context-saver')) {
|
|
137
137
|
console.log(` WARNING: Existing statusLine config will be overwritten:`);
|
|
138
138
|
console.log(` Old: ${JSON.stringify(settings.statusLine)}`);
|
|
139
139
|
console.log(` New: ${JSON.stringify(configs.statusLine)}`);
|
|
@@ -147,7 +147,7 @@ function install() {
|
|
|
147
147
|
|
|
148
148
|
const existingPreCompact = settings.hooks.PreCompact || [];
|
|
149
149
|
const alreadyInstalled = existingPreCompact.some(entry =>
|
|
150
|
-
entry.hooks?.some(h => h.command?.includes('
|
|
150
|
+
entry.hooks?.some(h => h.command?.includes('context-saver'))
|
|
151
151
|
);
|
|
152
152
|
|
|
153
153
|
if (alreadyInstalled) {
|
|
@@ -163,11 +163,11 @@ function install() {
|
|
|
163
163
|
console.log('Installation complete!\n');
|
|
164
164
|
if (isLocal) {
|
|
165
165
|
console.log('Mode: local (this project only)');
|
|
166
|
-
console.log(`Hooks installed to: .claude/hooks/
|
|
166
|
+
console.log(`Hooks installed to: .claude/hooks/context-saver/`);
|
|
167
167
|
console.log(`Settings updated: .claude/settings.json`);
|
|
168
168
|
} else {
|
|
169
169
|
console.log('Mode: global (all projects)');
|
|
170
|
-
console.log('Hooks installed to: ~/.claude/hooks/
|
|
170
|
+
console.log('Hooks installed to: ~/.claude/hooks/context-saver/');
|
|
171
171
|
console.log('Settings updated: ~/.claude/settings.json');
|
|
172
172
|
}
|
|
173
173
|
console.log('Backups will appear: {project}/.claude/backups/');
|
|
@@ -182,7 +182,7 @@ function install() {
|
|
|
182
182
|
|
|
183
183
|
function uninstall() {
|
|
184
184
|
const mode = isLocal ? 'local' : 'global';
|
|
185
|
-
console.log(`
|
|
185
|
+
console.log(`claude-context-saver — Uninstalling ${mode}...\n`);
|
|
186
186
|
|
|
187
187
|
// 1. Remove hooks directory
|
|
188
188
|
if (existsSync(HOOKS_DIR)) {
|
|
@@ -198,7 +198,7 @@ function uninstall() {
|
|
|
198
198
|
let changed = false;
|
|
199
199
|
|
|
200
200
|
// Remove statusLine if it's ours
|
|
201
|
-
if (settings.statusLine?.command?.includes('
|
|
201
|
+
if (settings.statusLine?.command?.includes('context-saver')) {
|
|
202
202
|
delete settings.statusLine;
|
|
203
203
|
console.log(' Removed statusLine config.');
|
|
204
204
|
changed = true;
|
|
@@ -207,7 +207,7 @@ function uninstall() {
|
|
|
207
207
|
// Remove our PreCompact hook entry
|
|
208
208
|
if (settings.hooks?.PreCompact) {
|
|
209
209
|
const filtered = settings.hooks.PreCompact.filter(entry =>
|
|
210
|
-
!entry.hooks?.some(h => h.command?.includes('
|
|
210
|
+
!entry.hooks?.some(h => h.command?.includes('context-saver'))
|
|
211
211
|
);
|
|
212
212
|
if (filtered.length !== settings.hooks.PreCompact.length) {
|
|
213
213
|
settings.hooks.PreCompact = filtered.length > 0 ? filtered : undefined;
|