claude-instance-manager 0.0.0-stage → 1.0.1

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 CHANGED
@@ -1,3 +1,128 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # Claude Instance Manager
2
+
3
+ A Windows launcher for opening Claude Desktop with separate data directories.
4
+ Use the desktop interface or the `cim` command.
5
+
6
+ ## Requirements
7
+
8
+ - Windows
9
+ - [Node.js 22.12 or newer and npm](https://nodejs.org/)
10
+ - Claude Desktop installed on the computer
11
+
12
+ ## Installation
13
+
14
+ Once published to npm, install globally with:
15
+
16
+ ```powershell
17
+ npm install -g claude-instance-manager
18
+ ```
19
+
20
+ To install from a project checkout instead, open a terminal in the project
21
+ directory and run:
22
+
23
+ ```powershell
24
+ npm install
25
+ npm link
26
+ ```
27
+
28
+ `npm link` makes `cim` available globally for the active Node.js
29
+ installation. Keep the project directory in place: the command links to it.
30
+ If the command is not found, make sure npm's global binary directory is on
31
+ your `PATH`, or run the commands below with `node .\cli.js` instead.
32
+
33
+ ## Usage
34
+
35
+ Open the desktop launcher:
36
+
37
+ ```powershell
38
+ cim
39
+ ```
40
+
41
+ You can also start it from the project directory with `npm start`.
42
+
43
+ To create a desktop shortcut to the launcher, run:
44
+
45
+ ```powershell
46
+ cim create-shortcut
47
+ ```
48
+
49
+ The shortcut points to this project and its installed Electron dependency, so
50
+ keep the project directory in place. If a different shortcut with the same
51
+ name already exists, rename or remove it before running the command.
52
+ An existing shortcut from an earlier version is renamed when it belongs to
53
+ this launcher; unrelated shortcuts are left untouched.
54
+
55
+ To remove the shortcut without deleting the app or instances:
56
+
57
+ ```powershell
58
+ cim remove-shortcut
59
+ ```
60
+
61
+ Only the shortcut pointing to this project is removed. If you have moved the
62
+ project since creating it, remove the old shortcut from the desktop manually.
63
+
64
+ The **Default** instance opens Claude Desktop normally, using its existing data.
65
+ Select **New Instance** (or press **Ctrl+N**), enter an instance name, and confirm. Then select
66
+ the instance in the sidebar and choose **Open Claude** to open it.
67
+ The launcher also discovers instance directories created by the CLI. Hiding an
68
+ instance only removes it from the launcher's list; it does not delete its data.
69
+ It does not stop Claude either. Add its name again to show it.
70
+ To permanently remove a separate instance and its data, close Claude for that
71
+ instance, then select **Delete** and confirm. The default instance cannot be
72
+ deleted from the launcher.
73
+
74
+ The launcher checks local Claude process information to show whether instances
75
+ are running. After the initial check, status updates quietly in the background;
76
+ the last known status remains visible while checking. Status is unavailable if
77
+ Windows or PowerShell prevents access to process details. It does not read or
78
+ display account identity.
79
+
80
+ The detail panel shows progress bars for the most recently recorded usage when Claude
81
+ has saved `plan-usage-history.json` locally. This is historical data, not a live
82
+ check, and may refer to a previously signed-in account. When available, reset
83
+ times come from locally cached Claude usage responses matched to the recorded
84
+ account, percentages, and a sample within ten minutes. They may be stale, and
85
+ the cache format may change.
86
+ Some model-specific limits are not stored in the history file. Claude may not
87
+ create the files for every instance; the launcher never reads login credentials
88
+ or requests usage from the internet.
89
+
90
+ Command-line options:
91
+
92
+ ```powershell
93
+ cim open Work
94
+ cim open "My Account"
95
+ cim list
96
+ cim delete Work
97
+ cim wipe-instances
98
+ cim --help
99
+ ```
100
+
101
+ `open` creates the instance directory if necessary. `list` shows existing
102
+ instance directories. **`delete` permanently removes the named instance
103
+ directory and its data.**
104
+
105
+ **`wipe-instances` permanently deletes all stopped managed instance directories**,
106
+ including hidden ones, after you type `DELETE` in an interactive terminal. It
107
+ skips running instances and protects the Default instance, including Default
108
+ data linked into a managed folder. It stops if running status cannot be checked;
109
+ some folders may already have been deleted if an error occurs. Close instances
110
+ before wiping to avoid a concurrent launch. Launcher-saved names may remain
111
+ visible after their data is deleted.
112
+
113
+ ## Instance storage
114
+
115
+ Instance data is stored locally under `%APPDATA%\Claude-Profile-<name>`.
116
+ The directory prefix remains unchanged to preserve existing data.
117
+ Spaces in names are replaced with underscores in directory names.
118
+ Each instance uses its own Claude Desktop data directory; sign in separately
119
+ for each instance as needed.
120
+
121
+ The desktop launcher's saved and hidden names are stored in its local storage.
122
+ New installations start with `Personal` and `Work` suggestions, which do not
123
+ become CLI instances until opened. The launcher also shows existing instance
124
+ directories unless they have been hidden.
125
+
126
+ The launcher looks for Claude Desktop in the legacy installer location and
127
+ Windows package locations. If it cannot find the executable, check that
128
+ Claude Desktop is installed for the current Windows user.
package/cli.js ADDED
@@ -0,0 +1,286 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn, execSync, execFileSync } = require('child_process');
4
+ const electron = require('electron');
5
+ const path = require('path');
6
+ const fs = require('fs');
7
+ const yargs = require('yargs/yargs');
8
+ const { hideBin } = require('yargs/helpers');
9
+ const readline = require('readline/promises');
10
+ const { getAllRunningManagedInstances } = require('./instances');
11
+ const { wipeInstances } = require('./wipe');
12
+
13
+ const appData = process.env.APPDATA;
14
+
15
+ function getClaudePath() {
16
+ const localAppData = process.env.LOCALAPPDATA || '';
17
+ const appData = process.env.APPDATA || '';
18
+
19
+ // 1. Check legacy installer path
20
+ const legacyPath = path.join(localAppData, 'AnthropicClaude', 'claude.exe');
21
+ if (fs.existsSync(legacyPath)) return legacyPath;
22
+
23
+ // 2. Check standard Windows AppX / MSIX package installation paths
24
+ const packagesDir = path.join(localAppData, 'Packages');
25
+ if (fs.existsSync(packagesDir)) {
26
+ try {
27
+ const packageFolders = fs.readdirSync(packagesDir);
28
+ const claudePkg = packageFolders.find(f => f.startsWith('Claude_') || f.includes('Anthropic'));
29
+ if (claudePkg) {
30
+ // Search inside the package directory for the executable
31
+ const pkgAppPath = path.join(packagesDir, claudePkg, 'app', 'claude.exe');
32
+ if (fs.existsSync(pkgAppPath)) return pkgAppPath;
33
+ }
34
+ } catch (e) {
35
+ // Ignore directory read errors
36
+ }
37
+ }
38
+
39
+ // 3. Fallback: Query Windows Registry / PowerShell for installed AppX package location
40
+ try {
41
+ const psCommand = 'powershell -Command "(Get-AppxPackage *Claude*).InstallLocation"';
42
+ const installLoc = execSync(psCommand, { encoding: 'utf8' }).trim();
43
+ if (installLoc) {
44
+ const exeInPkg = path.join(installLoc, 'Claude.exe');
45
+ if (fs.existsSync(exeInPkg)) return exeInPkg;
46
+
47
+ const exeInAppFolder = path.join(installLoc, 'app', 'claude.exe');
48
+ if (fs.existsSync(exeInAppFolder)) return exeInAppFolder;
49
+ }
50
+ } catch (e) {
51
+ // Powershell lookup failed
52
+ }
53
+
54
+ // Fallback default
55
+ return legacyPath;
56
+ }
57
+
58
+ // Helper to get stored instance folder paths
59
+ function getInstances() {
60
+ if (!fs.existsSync(appData)) return [];
61
+ const files = fs.readdirSync(appData);
62
+ return files
63
+ .filter(file => file.startsWith('Claude-Profile-'))
64
+ .map(file => file.replace('Claude-Profile-', '').replace(/_/g, ' '));
65
+ }
66
+
67
+ yargs(hideBin(process.argv))
68
+ .scriptName('cim')
69
+ .usage('$0 [command] [options]')
70
+
71
+ // Command: List all accounts
72
+ .command('list', 'List all existing Claude instances', {}, () => {
73
+ const instances = getInstances();
74
+ if (instances.length === 0) {
75
+ console.log('No instances found.');
76
+ } else {
77
+ console.log('\nExisting Claude Instances:');
78
+ instances.forEach(instance => console.log(` • ${instance}`));
79
+ console.log('');
80
+ }
81
+ })
82
+
83
+ // Command: Open an instance directly
84
+ .command('open <name>', 'Launch a specific Claude instance', (yargs) => {
85
+ yargs.positional('name', { describe: 'Instance name to launch', type: 'string' });
86
+ }, (argv) => {
87
+ launchInstance(argv.name);
88
+ })
89
+
90
+ // Command: Delete an account's data folder
91
+ .command('delete <name>', 'Delete data folder for an instance', (yargs) => {
92
+ yargs.positional('name', { describe: 'Instance name to delete', type: 'string' });
93
+ }, (argv) => {
94
+ const safeName = argv.name.replace(/\s+/g, '_');
95
+ const instanceDir = path.join(appData, `Claude-Profile-${safeName}`);
96
+ if (fs.existsSync(instanceDir)) {
97
+ fs.rmSync(instanceDir, { recursive: true, force: true });
98
+ console.log(`Instance "${argv.name}" successfully deleted.`);
99
+ } else {
100
+ console.log(`Instance "${argv.name}" not found.`);
101
+ }
102
+ })
103
+
104
+ .command('wipe-instances', 'Permanently delete stopped managed instance data', {}, () => {
105
+ return runWipe().catch(error => {
106
+ console.error(`Error: Could not wipe instances: ${error.message}`);
107
+ process.exitCode = 1;
108
+ });
109
+ })
110
+
111
+ .command('create-shortcut', 'Create a desktop shortcut for the manager', {}, () => {
112
+ manageShortcut('create');
113
+ })
114
+
115
+ .command('remove-shortcut', 'Remove the manager desktop shortcut', {}, () => {
116
+ manageShortcut('remove');
117
+ })
118
+
119
+ // Default behavior (No subcommands passed) -> Open GUI
120
+ .command('$0', 'Open Claude Instance Manager', {}, (argv) => {
121
+ // Prevent opening GUI if --help or --version flags were passed
122
+ if (argv.help || argv.version) return;
123
+
124
+ const child = spawn(electron, [path.join(__dirname, 'main.js')], {
125
+ detached: true,
126
+ stdio: 'ignore'
127
+ });
128
+ child.on('error', (error) => {
129
+ console.error(`Error: Could not start the manager: ${error.message}`);
130
+ process.exitCode = 1;
131
+ });
132
+ child.on('spawn', () => child.unref());
133
+ })
134
+
135
+ .help('h')
136
+ .alias('h', 'help')
137
+ .parse();
138
+
139
+ async function runWipe() {
140
+ if (process.platform !== 'win32') throw new Error('Wiping instances is only supported on Windows.');
141
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
142
+ throw new Error('An interactive terminal is required to confirm the wipe.');
143
+ }
144
+ if (!process.env.LOCALAPPDATA || !path.isAbsolute(process.env.LOCALAPPDATA)) {
145
+ throw new Error('The Windows local application data directory is unavailable.');
146
+ }
147
+ await wipeInstances(appData, {
148
+ localAppData: process.env.LOCALAPPDATA,
149
+ checkRunning: () => getAllRunningManagedInstances(appData),
150
+ log: message => console.log(message),
151
+ confirm: async instances => {
152
+ console.log(`These instance directories will be permanently deleted: ${instances.join(', ')}`);
153
+ console.log('The Default instance will not be touched. Running instances are skipped.');
154
+ const prompt = readline.createInterface({ input: process.stdin, output: process.stdout });
155
+ try {
156
+ return (await prompt.question('Type DELETE to confirm: ')) === 'DELETE';
157
+ } finally {
158
+ prompt.close();
159
+ }
160
+ }
161
+ });
162
+ }
163
+
164
+ function manageShortcut(action) {
165
+ if (process.platform !== 'win32') {
166
+ console.error('Error: Desktop shortcuts are only supported on Windows.');
167
+ process.exitCode = 1;
168
+ return;
169
+ }
170
+ if (action === 'create' && !fs.existsSync(electron)) {
171
+ console.error(`Error: Electron executable not found at: ${electron}`);
172
+ process.exitCode = 1;
173
+ return;
174
+ }
175
+
176
+ const command = `
177
+ $ErrorActionPreference = 'Stop'
178
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
179
+ $desktop = [Environment]::GetFolderPath('Desktop')
180
+ if (-not $desktop -or -not (Test-Path -LiteralPath $desktop -PathType Container)) {
181
+ throw 'Could not find the current user''s Desktop folder.'
182
+ }
183
+ $shortcutPath = Join-Path $desktop 'Claude Instance Manager.lnk'
184
+ $legacyPath = Join-Path $desktop 'Claude Desktop Manager.lnk'
185
+ $arguments = '"' + $env:CLAUDE_INSTANCE_MANAGER_MAIN + '"'
186
+ $shell = New-Object -ComObject WScript.Shell
187
+ function Test-ManagerShortcut($file) {
188
+ $existing = $shell.CreateShortcut($file)
189
+ return ($existing.TargetPath -eq $env:CLAUDE_INSTANCE_MANAGER_ELECTRON -and
190
+ $existing.Arguments -eq $arguments -and
191
+ $existing.WorkingDirectory -eq $env:CLAUDE_INSTANCE_MANAGER_DIRECTORY)
192
+ }
193
+
194
+ if (Test-Path -LiteralPath $shortcutPath) {
195
+ if (-not (Test-ManagerShortcut $shortcutPath)) {
196
+ throw "A different shortcut exists at $shortcutPath. It was not changed."
197
+ }
198
+ }
199
+ $legacyOwned = (Test-Path -LiteralPath $legacyPath) -and (Test-ManagerShortcut $legacyPath)
200
+ if ($env:CLAUDE_INSTANCE_MANAGER_SHORTCUT_ACTION -eq 'remove') {
201
+ $removed = $false
202
+ foreach ($file in @($shortcutPath, $legacyPath)) {
203
+ if ((Test-Path -LiteralPath $file) -and (Test-ManagerShortcut $file)) {
204
+ Remove-Item -LiteralPath $file
205
+ Write-Output "Removed shortcut: $file"
206
+ $removed = $true
207
+ }
208
+ }
209
+ if (-not $removed) { Write-Output "Shortcut not found: $shortcutPath" }
210
+ if ((Test-Path -LiteralPath $legacyPath) -and -not $legacyOwned) {
211
+ Write-Output 'A different legacy shortcut was not changed.'
212
+ }
213
+ exit 0
214
+ }
215
+ if (Test-Path -LiteralPath $shortcutPath) {
216
+ if ($legacyOwned) {
217
+ Remove-Item -LiteralPath $legacyPath
218
+ Write-Output 'Removed the previous launcher shortcut.'
219
+ }
220
+ Write-Output "Shortcut already exists: $shortcutPath"
221
+ exit 0
222
+ }
223
+ if ($legacyOwned) {
224
+ Move-Item -LiteralPath $legacyPath -Destination $shortcutPath
225
+ $shortcut = $shell.CreateShortcut($shortcutPath)
226
+ $shortcut.Description = 'Open Claude Instance Manager'
227
+ $shortcut.Save()
228
+ Write-Output "Updated shortcut: $shortcutPath"
229
+ exit 0
230
+ }
231
+ $shortcut = $shell.CreateShortcut($shortcutPath)
232
+ $shortcut.TargetPath = $env:CLAUDE_INSTANCE_MANAGER_ELECTRON
233
+ $shortcut.Arguments = $arguments
234
+ $shortcut.WorkingDirectory = $env:CLAUDE_INSTANCE_MANAGER_DIRECTORY
235
+ $shortcut.Description = 'Open Claude Instance Manager'
236
+ $shortcut.Save()
237
+ Write-Output "Created shortcut: $shortcutPath"
238
+ `;
239
+
240
+ try {
241
+ const output = execFileSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', command], {
242
+ encoding: 'utf8',
243
+ windowsHide: true,
244
+ env: {
245
+ ...process.env,
246
+ CLAUDE_INSTANCE_MANAGER_ELECTRON: electron,
247
+ CLAUDE_INSTANCE_MANAGER_MAIN: path.join(__dirname, 'main.js'),
248
+ CLAUDE_INSTANCE_MANAGER_DIRECTORY: __dirname,
249
+ CLAUDE_INSTANCE_MANAGER_SHORTCUT_ACTION: action
250
+ }
251
+ });
252
+ console.log(output.trim());
253
+ } catch (error) {
254
+ console.error(`Error: Could not ${action} desktop shortcut: ${error.stderr ? error.stderr.trim() : error.message}`);
255
+ process.exitCode = 1;
256
+ }
257
+ }
258
+
259
+ function launchInstance(accountName) {
260
+ const safeName = accountName.replace(/\s+/g, '_');
261
+ const instanceDir = path.join(appData, `Claude-Profile-${safeName}`);
262
+ const claudePath = getClaudePath();
263
+
264
+ if (!fs.existsSync(claudePath)) {
265
+ console.error(`Error: Could not locate Claude executable at: ${claudePath}`);
266
+ process.exitCode = 1;
267
+ return;
268
+ }
269
+
270
+ if (!fs.existsSync(instanceDir)) {
271
+ fs.mkdirSync(instanceDir, { recursive: true });
272
+ }
273
+
274
+ const child = spawn(claudePath, [`--user-data-dir=${instanceDir}`], {
275
+ detached: true,
276
+ stdio: 'ignore'
277
+ });
278
+ child.on('error', (error) => {
279
+ console.error(`Error: Could not launch Claude: ${error.message}`);
280
+ process.exitCode = 1;
281
+ });
282
+ child.on('spawn', () => {
283
+ child.unref();
284
+ console.log(`Launched Claude Desktop instance for "${accountName}".`);
285
+ });
286
+ }