claude-instance-manager 0.0.0-stage → 1.0.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 CHANGED
@@ -1,3 +1,119 @@
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 --help
98
+ ```
99
+
100
+ `open` creates the instance directory if necessary. `list` shows existing
101
+ instance directories. **`delete` permanently removes the named instance
102
+ directory and its data.**
103
+
104
+ ## Instance storage
105
+
106
+ Instance data is stored locally under `%APPDATA%\Claude-Profile-<name>`.
107
+ The directory prefix remains unchanged to preserve existing data.
108
+ Spaces in names are replaced with underscores in directory names.
109
+ Each instance uses its own Claude Desktop data directory; sign in separately
110
+ for each instance as needed.
111
+
112
+ The desktop launcher's saved and hidden names are stored in its local storage.
113
+ New installations start with `Personal` and `Work` suggestions, which do not
114
+ become CLI instances until opened. The launcher also shows existing instance
115
+ directories unless they have been hidden.
116
+
117
+ The launcher looks for Claude Desktop in the legacy installer location and
118
+ Windows package locations. If it cannot find the executable, check that
119
+ Claude Desktop is installed for the current Windows user.
package/cli.js ADDED
@@ -0,0 +1,251 @@
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
+
10
+ const appData = process.env.APPDATA;
11
+
12
+ function getClaudePath() {
13
+ const localAppData = process.env.LOCALAPPDATA || '';
14
+ const appData = process.env.APPDATA || '';
15
+
16
+ // 1. Check legacy installer path
17
+ const legacyPath = path.join(localAppData, 'AnthropicClaude', 'claude.exe');
18
+ if (fs.existsSync(legacyPath)) return legacyPath;
19
+
20
+ // 2. Check standard Windows AppX / MSIX package installation paths
21
+ const packagesDir = path.join(localAppData, 'Packages');
22
+ if (fs.existsSync(packagesDir)) {
23
+ try {
24
+ const packageFolders = fs.readdirSync(packagesDir);
25
+ const claudePkg = packageFolders.find(f => f.startsWith('Claude_') || f.includes('Anthropic'));
26
+ if (claudePkg) {
27
+ // Search inside the package directory for the executable
28
+ const pkgAppPath = path.join(packagesDir, claudePkg, 'app', 'claude.exe');
29
+ if (fs.existsSync(pkgAppPath)) return pkgAppPath;
30
+ }
31
+ } catch (e) {
32
+ // Ignore directory read errors
33
+ }
34
+ }
35
+
36
+ // 3. Fallback: Query Windows Registry / PowerShell for installed AppX package location
37
+ try {
38
+ const psCommand = 'powershell -Command "(Get-AppxPackage *Claude*).InstallLocation"';
39
+ const installLoc = execSync(psCommand, { encoding: 'utf8' }).trim();
40
+ if (installLoc) {
41
+ const exeInPkg = path.join(installLoc, 'Claude.exe');
42
+ if (fs.existsSync(exeInPkg)) return exeInPkg;
43
+
44
+ const exeInAppFolder = path.join(installLoc, 'app', 'claude.exe');
45
+ if (fs.existsSync(exeInAppFolder)) return exeInAppFolder;
46
+ }
47
+ } catch (e) {
48
+ // Powershell lookup failed
49
+ }
50
+
51
+ // Fallback default
52
+ return legacyPath;
53
+ }
54
+
55
+ // Helper to get stored instance folder paths
56
+ function getInstances() {
57
+ if (!fs.existsSync(appData)) return [];
58
+ const files = fs.readdirSync(appData);
59
+ return files
60
+ .filter(file => file.startsWith('Claude-Profile-'))
61
+ .map(file => file.replace('Claude-Profile-', '').replace(/_/g, ' '));
62
+ }
63
+
64
+ yargs(hideBin(process.argv))
65
+ .scriptName('cim')
66
+ .usage('$0 [command] [options]')
67
+
68
+ // Command: List all accounts
69
+ .command('list', 'List all existing Claude instances', {}, () => {
70
+ const instances = getInstances();
71
+ if (instances.length === 0) {
72
+ console.log('No instances found.');
73
+ } else {
74
+ console.log('\nExisting Claude Instances:');
75
+ instances.forEach(instance => console.log(` • ${instance}`));
76
+ console.log('');
77
+ }
78
+ })
79
+
80
+ // Command: Open an instance directly
81
+ .command('open <name>', 'Launch a specific Claude instance', (yargs) => {
82
+ yargs.positional('name', { describe: 'Instance name to launch', type: 'string' });
83
+ }, (argv) => {
84
+ launchInstance(argv.name);
85
+ })
86
+
87
+ // Command: Delete an account's data folder
88
+ .command('delete <name>', 'Delete data folder for an instance', (yargs) => {
89
+ yargs.positional('name', { describe: 'Instance name to delete', type: 'string' });
90
+ }, (argv) => {
91
+ const safeName = argv.name.replace(/\s+/g, '_');
92
+ const instanceDir = path.join(appData, `Claude-Profile-${safeName}`);
93
+ if (fs.existsSync(instanceDir)) {
94
+ fs.rmSync(instanceDir, { recursive: true, force: true });
95
+ console.log(`Instance "${argv.name}" successfully deleted.`);
96
+ } else {
97
+ console.log(`Instance "${argv.name}" not found.`);
98
+ }
99
+ })
100
+
101
+ .command('create-shortcut', 'Create a desktop shortcut for the manager', {}, () => {
102
+ manageShortcut('create');
103
+ })
104
+
105
+ .command('remove-shortcut', 'Remove the manager desktop shortcut', {}, () => {
106
+ manageShortcut('remove');
107
+ })
108
+
109
+ // Default behavior (No subcommands passed) -> Open GUI
110
+ .command('$0', 'Open Claude Instance Manager', {}, (argv) => {
111
+ // Prevent opening GUI if --help or --version flags were passed
112
+ if (argv.help || argv.version) return;
113
+
114
+ const child = spawn(electron, [path.join(__dirname, 'main.js')], {
115
+ detached: true,
116
+ stdio: 'ignore'
117
+ });
118
+ child.on('error', (error) => {
119
+ console.error(`Error: Could not start the manager: ${error.message}`);
120
+ process.exitCode = 1;
121
+ });
122
+ child.on('spawn', () => child.unref());
123
+ })
124
+
125
+ .help('h')
126
+ .alias('h', 'help')
127
+ .parse();
128
+
129
+ function manageShortcut(action) {
130
+ if (process.platform !== 'win32') {
131
+ console.error('Error: Desktop shortcuts are only supported on Windows.');
132
+ process.exitCode = 1;
133
+ return;
134
+ }
135
+ if (action === 'create' && !fs.existsSync(electron)) {
136
+ console.error(`Error: Electron executable not found at: ${electron}`);
137
+ process.exitCode = 1;
138
+ return;
139
+ }
140
+
141
+ const command = `
142
+ $ErrorActionPreference = 'Stop'
143
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
144
+ $desktop = [Environment]::GetFolderPath('Desktop')
145
+ if (-not $desktop -or -not (Test-Path -LiteralPath $desktop -PathType Container)) {
146
+ throw 'Could not find the current user''s Desktop folder.'
147
+ }
148
+ $shortcutPath = Join-Path $desktop 'Claude Instance Manager.lnk'
149
+ $legacyPath = Join-Path $desktop 'Claude Desktop Manager.lnk'
150
+ $arguments = '"' + $env:CLAUDE_INSTANCE_MANAGER_MAIN + '"'
151
+ $shell = New-Object -ComObject WScript.Shell
152
+ function Test-ManagerShortcut($file) {
153
+ $existing = $shell.CreateShortcut($file)
154
+ return ($existing.TargetPath -eq $env:CLAUDE_INSTANCE_MANAGER_ELECTRON -and
155
+ $existing.Arguments -eq $arguments -and
156
+ $existing.WorkingDirectory -eq $env:CLAUDE_INSTANCE_MANAGER_DIRECTORY)
157
+ }
158
+
159
+ if (Test-Path -LiteralPath $shortcutPath) {
160
+ if (-not (Test-ManagerShortcut $shortcutPath)) {
161
+ throw "A different shortcut exists at $shortcutPath. It was not changed."
162
+ }
163
+ }
164
+ $legacyOwned = (Test-Path -LiteralPath $legacyPath) -and (Test-ManagerShortcut $legacyPath)
165
+ if ($env:CLAUDE_INSTANCE_MANAGER_SHORTCUT_ACTION -eq 'remove') {
166
+ $removed = $false
167
+ foreach ($file in @($shortcutPath, $legacyPath)) {
168
+ if ((Test-Path -LiteralPath $file) -and (Test-ManagerShortcut $file)) {
169
+ Remove-Item -LiteralPath $file
170
+ Write-Output "Removed shortcut: $file"
171
+ $removed = $true
172
+ }
173
+ }
174
+ if (-not $removed) { Write-Output "Shortcut not found: $shortcutPath" }
175
+ if ((Test-Path -LiteralPath $legacyPath) -and -not $legacyOwned) {
176
+ Write-Output 'A different legacy shortcut was not changed.'
177
+ }
178
+ exit 0
179
+ }
180
+ if (Test-Path -LiteralPath $shortcutPath) {
181
+ if ($legacyOwned) {
182
+ Remove-Item -LiteralPath $legacyPath
183
+ Write-Output 'Removed the previous launcher shortcut.'
184
+ }
185
+ Write-Output "Shortcut already exists: $shortcutPath"
186
+ exit 0
187
+ }
188
+ if ($legacyOwned) {
189
+ Move-Item -LiteralPath $legacyPath -Destination $shortcutPath
190
+ $shortcut = $shell.CreateShortcut($shortcutPath)
191
+ $shortcut.Description = 'Open Claude Instance Manager'
192
+ $shortcut.Save()
193
+ Write-Output "Updated shortcut: $shortcutPath"
194
+ exit 0
195
+ }
196
+ $shortcut = $shell.CreateShortcut($shortcutPath)
197
+ $shortcut.TargetPath = $env:CLAUDE_INSTANCE_MANAGER_ELECTRON
198
+ $shortcut.Arguments = $arguments
199
+ $shortcut.WorkingDirectory = $env:CLAUDE_INSTANCE_MANAGER_DIRECTORY
200
+ $shortcut.Description = 'Open Claude Instance Manager'
201
+ $shortcut.Save()
202
+ Write-Output "Created shortcut: $shortcutPath"
203
+ `;
204
+
205
+ try {
206
+ const output = execFileSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', command], {
207
+ encoding: 'utf8',
208
+ windowsHide: true,
209
+ env: {
210
+ ...process.env,
211
+ CLAUDE_INSTANCE_MANAGER_ELECTRON: electron,
212
+ CLAUDE_INSTANCE_MANAGER_MAIN: path.join(__dirname, 'main.js'),
213
+ CLAUDE_INSTANCE_MANAGER_DIRECTORY: __dirname,
214
+ CLAUDE_INSTANCE_MANAGER_SHORTCUT_ACTION: action
215
+ }
216
+ });
217
+ console.log(output.trim());
218
+ } catch (error) {
219
+ console.error(`Error: Could not ${action} desktop shortcut: ${error.stderr ? error.stderr.trim() : error.message}`);
220
+ process.exitCode = 1;
221
+ }
222
+ }
223
+
224
+ function launchInstance(accountName) {
225
+ const safeName = accountName.replace(/\s+/g, '_');
226
+ const instanceDir = path.join(appData, `Claude-Profile-${safeName}`);
227
+ const claudePath = getClaudePath();
228
+
229
+ if (!fs.existsSync(claudePath)) {
230
+ console.error(`Error: Could not locate Claude executable at: ${claudePath}`);
231
+ process.exitCode = 1;
232
+ return;
233
+ }
234
+
235
+ if (!fs.existsSync(instanceDir)) {
236
+ fs.mkdirSync(instanceDir, { recursive: true });
237
+ }
238
+
239
+ const child = spawn(claudePath, [`--user-data-dir=${instanceDir}`], {
240
+ detached: true,
241
+ stdio: 'ignore'
242
+ });
243
+ child.on('error', (error) => {
244
+ console.error(`Error: Could not launch Claude: ${error.message}`);
245
+ process.exitCode = 1;
246
+ });
247
+ child.on('spawn', () => {
248
+ child.unref();
249
+ console.log(`Launched Claude Desktop instance for "${accountName}".`);
250
+ });
251
+ }