claude-code-autoconfig 1.0.1 → 1.0.3

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.
@@ -171,6 +171,10 @@ This ensures double-clicking CLAUDE.md in the guide shows the real generated con
171
171
 
172
172
  ## After Completion
173
173
 
174
- Once autoconfig is complete, prompt the user:
174
+ Once autoconfig is complete, open the interactive guide in the user's browser:
175
175
 
176
- **Run `/show-guide` for an interactive walkthrough of your new Claude Code project setup.**
176
+ - macOS: `open .claude/guide/autoconfig.guide.html`
177
+ - Linux: `xdg-open .claude/guide/autoconfig.guide.html`
178
+ - Windows: `start .claude/guide/autoconfig.guide.html`
179
+
180
+ This shows the user what got installed and how to use it.
package/bin/cli.js CHANGED
@@ -2,19 +2,53 @@
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
- const { exec } = require('child_process');
5
+ const { execSync, spawn } = require('child_process');
6
6
 
7
7
  const cwd = process.cwd();
8
8
  const packageDir = path.dirname(__dirname);
9
9
 
10
- console.log('\x1b[36m%s\x1b[0m', '🚀 Installing Claude Code Autoconfig...');
10
+ console.log('\x1b[36m%s\x1b[0m', '🚀 Claude Code Autoconfig');
11
11
  console.log();
12
12
 
13
- // Files/dirs to skip during copy (project-specific, not for distribution)
14
- const SKIP_FILES = ['settings.local.json', 'retro'];
13
+ // Step 1: Check if Claude Code is installed
14
+ function isClaudeInstalled() {
15
+ try {
16
+ execSync('claude --version', { stdio: 'ignore' });
17
+ return true;
18
+ } catch {
19
+ return false;
20
+ }
21
+ }
15
22
 
16
- // Helper to copy directory recursively
17
- function copyDir(src, dest) {
23
+ function installClaude() {
24
+ console.log('\x1b[33m%s\x1b[0m', '⚠️ Claude Code not found. Installing...');
25
+ console.log();
26
+ try {
27
+ execSync('npm install -g @anthropic-ai/claude-code', { stdio: 'inherit' });
28
+ console.log();
29
+ console.log('\x1b[32m%s\x1b[0m', '✅ Claude Code installed');
30
+ return true;
31
+ } catch (err) {
32
+ console.log('\x1b[31m%s\x1b[0m', '❌ Failed to install Claude Code');
33
+ console.log(' Install manually: npm install -g @anthropic-ai/claude-code');
34
+ return false;
35
+ }
36
+ }
37
+
38
+ if (!isClaudeInstalled()) {
39
+ if (!installClaude()) {
40
+ process.exit(1);
41
+ }
42
+ }
43
+
44
+ console.log('\x1b[32m%s\x1b[0m', '✅ Claude Code detected');
45
+
46
+ // Step 2: Backup existing .claude/ if present
47
+ const claudeDest = path.join(cwd, '.claude');
48
+ const SKIP_FILES = ['settings.local.json', 'retro', 'migration'];
49
+ let migrationPath = null;
50
+
51
+ function copyDirForBackup(src, dest) {
18
52
  fs.mkdirSync(dest, { recursive: true });
19
53
  const entries = fs.readdirSync(src, { withFileTypes: true });
20
54
 
@@ -25,20 +59,92 @@ function copyDir(src, dest) {
25
59
  const destPath = path.join(dest, entry.name);
26
60
 
27
61
  if (entry.isDirectory()) {
28
- copyDir(srcPath, destPath);
62
+ copyDirForBackup(srcPath, destPath);
63
+ } else {
64
+ fs.copyFileSync(srcPath, destPath);
65
+ }
66
+ }
67
+ }
68
+
69
+ if (fs.existsSync(claudeDest)) {
70
+ // Create timestamped backup
71
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
72
+ const migrationDir = path.join(claudeDest, 'migration');
73
+ migrationPath = path.join(migrationDir, timestamp);
74
+
75
+ fs.mkdirSync(migrationPath, { recursive: true });
76
+
77
+ // Copy existing files to backup (excluding migration folder itself)
78
+ const entries = fs.readdirSync(claudeDest, { withFileTypes: true });
79
+ for (const entry of entries) {
80
+ if (entry.name === 'migration') continue;
81
+
82
+ const srcPath = path.join(claudeDest, entry.name);
83
+ const destPath = path.join(migrationPath, entry.name);
84
+
85
+ if (entry.isDirectory()) {
86
+ copyDirForBackup(srcPath, destPath);
29
87
  } else {
30
88
  fs.copyFileSync(srcPath, destPath);
31
89
  }
32
90
  }
91
+
92
+ // Create/update migration README
93
+ const readmePath = path.join(migrationDir, 'README.md');
94
+ const readmeContent = `# Migration Backups
95
+
96
+ This folder contains backups of previous .claude/ configurations created during autoconfig upgrades.
97
+
98
+ Each timestamped folder contains the files that existed before that migration.
99
+
100
+ ## Backups
101
+
102
+ - \`${timestamp}/\` - Backup created during autoconfig install
103
+
104
+ ## Restoring
105
+
106
+ To restore a previous configuration, copy files from the backup folder back to \`.claude/\`.
107
+ `;
108
+
109
+ // Append to existing README or create new
110
+ if (fs.existsSync(readmePath)) {
111
+ const existing = fs.readFileSync(readmePath, 'utf8');
112
+ const newEntry = `- \`${timestamp}/\` - Backup created during autoconfig install\n`;
113
+ if (!existing.includes(timestamp)) {
114
+ const updated = existing.replace('## Backups\n\n', `## Backups\n\n${newEntry}`);
115
+ fs.writeFileSync(readmePath, updated);
116
+ }
117
+ } else {
118
+ fs.writeFileSync(readmePath, readmeContent);
119
+ }
120
+
121
+ console.log('\x1b[33m%s\x1b[0m', `⚠️ Existing .claude/ backed up to migration/${timestamp}/`);
33
122
  }
34
123
 
35
- // Copy .claude directory
124
+ // Step 3: Copy new files
36
125
  const claudeSrc = path.join(packageDir, '.claude');
37
- const claudeDest = path.join(cwd, '.claude');
126
+
127
+ function copyDir(src, dest) {
128
+ fs.mkdirSync(dest, { recursive: true });
129
+ const entries = fs.readdirSync(src, { withFileTypes: true });
130
+
131
+ for (const entry of entries) {
132
+ if (SKIP_FILES.includes(entry.name)) continue;
133
+
134
+ const srcPath = path.join(src, entry.name);
135
+ const destPath = path.join(dest, entry.name);
136
+
137
+ if (entry.isDirectory()) {
138
+ copyDir(srcPath, destPath);
139
+ } else {
140
+ fs.copyFileSync(srcPath, destPath);
141
+ }
142
+ }
143
+ }
38
144
 
39
145
  if (fs.existsSync(claudeSrc)) {
40
146
  copyDir(claudeSrc, claudeDest);
41
- console.log('\x1b[32m%s\x1b[0m', '✅ Created .claude/ directory structure');
147
+ console.log('\x1b[32m%s\x1b[0m', '✅ Created .claude/ directory');
42
148
  } else {
43
149
  console.log('\x1b[31m%s\x1b[0m', '❌ Error: .claude directory not found in package');
44
150
  process.exit(1);
@@ -49,29 +155,31 @@ const claudeMdSrc = path.join(packageDir, 'CLAUDE.md');
49
155
  const claudeMdDest = path.join(cwd, 'CLAUDE.md');
50
156
 
51
157
  if (fs.existsSync(claudeMdDest)) {
52
- console.log('\x1b[33m%s\x1b[0m', '⚠️ CLAUDE.md already exists, saving template as CLAUDE.md.template');
158
+ // Backup existing CLAUDE.md to migration folder if we have one
159
+ if (migrationPath) {
160
+ fs.copyFileSync(claudeMdDest, path.join(migrationPath, 'CLAUDE.md'));
161
+ }
162
+ console.log('\x1b[33m%s\x1b[0m', '⚠️ CLAUDE.md exists, saved template as CLAUDE.md.template');
53
163
  fs.copyFileSync(claudeMdSrc, path.join(cwd, 'CLAUDE.md.template'));
54
164
  } else if (fs.existsSync(claudeMdSrc)) {
55
165
  fs.copyFileSync(claudeMdSrc, claudeMdDest);
56
166
  console.log('\x1b[32m%s\x1b[0m', '✅ Created CLAUDE.md');
57
167
  }
58
168
 
169
+ // Step 4: Launch Claude Code
59
170
  console.log();
60
- console.log('\x1b[36m%s\x1b[0m', ' Claude Code Autoconfig installed!');
61
- console.log();
62
- console.log('Once Claude Code is open:');
63
- console.log(' Run \x1b[33m/autoconfig\x1b[0m to configure for your project');
171
+ console.log('\x1b[36m%s\x1b[0m', '🚀 Launching Claude Code...');
172
+ console.log('\x1b[33m%s\x1b[0m', ' Run /autoconfig to complete setup');
64
173
  console.log();
65
174
 
66
- // Auto-open the guide in browser
67
- const guidePath = path.join(cwd, '.claude', 'guide', 'autoconfig.guide.html');
68
- if (fs.existsSync(guidePath)) {
69
- console.log('\x1b[36m%s\x1b[0m', '📖 Opening interactive guide...');
70
- const openCmd = process.platform === 'win32' ? 'start ""' :
71
- process.platform === 'darwin' ? 'open' : 'xdg-open';
72
- exec(`${openCmd} "${guidePath}"`, (err) => {
73
- if (err) {
74
- console.log('\x1b[33m%s\x1b[0m', ` Run /show-guide in Claude Code to view the guide`);
75
- }
76
- });
77
- }
175
+ // Spawn claude in the current directory, inheriting stdio for interactive use
176
+ const claude = spawn('claude', [], {
177
+ cwd: cwd,
178
+ stdio: 'inherit',
179
+ shell: true
180
+ });
181
+
182
+ claude.on('error', (err) => {
183
+ console.log('\x1b[31m%s\x1b[0m', '❌ Failed to launch Claude Code');
184
+ console.log(' Run "claude" manually, then run /autoconfig');
185
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-autoconfig",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Intelligent, self-configuring setup for Claude Code. One command analyzes your project, configures Claude, and shows you what it did.",
5
5
  "author": "ADAC 1001 <info@adac1001.com>",
6
6
  "license": "MIT",