claude-code-scanner 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.
Files changed (65) hide show
  1. package/DOCUMENTATION.md +1210 -0
  2. package/LICENSE +21 -0
  3. package/README.md +306 -0
  4. package/bin/cli.js +305 -0
  5. package/package.json +43 -0
  6. package/template/.claude/agents/api-builder.md +64 -0
  7. package/template/.claude/agents/architect.md +92 -0
  8. package/template/.claude/agents/debugger.md +69 -0
  9. package/template/.claude/agents/explorer.md +71 -0
  10. package/template/.claude/agents/frontend.md +61 -0
  11. package/template/.claude/agents/infra.md +66 -0
  12. package/template/.claude/agents/product-owner.md +73 -0
  13. package/template/.claude/agents/qa-lead.md +102 -0
  14. package/template/.claude/agents/reviewer.md +77 -0
  15. package/template/.claude/agents/security.md +81 -0
  16. package/template/.claude/agents/team-lead.md +128 -0
  17. package/template/.claude/agents/tester.md +72 -0
  18. package/template/.claude/docs/agent-error-protocol.md +89 -0
  19. package/template/.claude/docs/best-practices.md +93 -0
  20. package/template/.claude/docs/commands-template.md +73 -0
  21. package/template/.claude/docs/conflict-resolution-protocol.md +82 -0
  22. package/template/.claude/docs/context-budget.md +54 -0
  23. package/template/.claude/docs/execution-metrics-protocol.md +105 -0
  24. package/template/.claude/docs/flow-engine.md +475 -0
  25. package/template/.claude/docs/smithery-setup.md +51 -0
  26. package/template/.claude/docs/task-record-schema.md +196 -0
  27. package/template/.claude/hooks/drift-detector.js +143 -0
  28. package/template/.claude/hooks/execution-report.js +114 -0
  29. package/template/.claude/hooks/notify-approval.js +30 -0
  30. package/template/.claude/hooks/post-compact-recovery.js +68 -0
  31. package/template/.claude/hooks/post-edit-format.js +43 -0
  32. package/template/.claude/hooks/pre-compact-save.js +94 -0
  33. package/template/.claude/hooks/protect-files.js +39 -0
  34. package/template/.claude/hooks/session-start.js +76 -0
  35. package/template/.claude/hooks/stop-failure-handler.js +77 -0
  36. package/template/.claude/hooks/tool-failure-tracker.js +54 -0
  37. package/template/.claude/hooks/track-file-changes.js +34 -0
  38. package/template/.claude/hooks/validate-bash.js +34 -0
  39. package/template/.claude/manifest.json +22 -0
  40. package/template/.claude/profiles/backend.md +34 -0
  41. package/template/.claude/profiles/devops.md +36 -0
  42. package/template/.claude/profiles/frontend.md +34 -0
  43. package/template/.claude/rules/context-budget.md +34 -0
  44. package/template/.claude/scripts/verify-setup.js +210 -0
  45. package/template/.claude/settings.json +154 -0
  46. package/template/.claude/skills/context-check/SKILL.md +112 -0
  47. package/template/.claude/skills/execution-report/SKILL.md +229 -0
  48. package/template/.claude/skills/generate-environment/SKILL.md +128 -0
  49. package/template/.claude/skills/generate-environment/additional-skills.md +276 -0
  50. package/template/.claude/skills/generate-environment/artifact-templates.md +386 -0
  51. package/template/.claude/skills/generate-environment/domain-agents.md +202 -0
  52. package/template/.claude/skills/impact-analysis/SKILL.md +17 -0
  53. package/template/.claude/skills/metrics/SKILL.md +19 -0
  54. package/template/.claude/skills/progress-report/SKILL.md +27 -0
  55. package/template/.claude/skills/rollback/SKILL.md +75 -0
  56. package/template/.claude/skills/scan-codebase/SKILL.md +59 -0
  57. package/template/.claude/skills/scan-codebase/deep-scan-instructions.md +101 -0
  58. package/template/.claude/skills/scan-codebase/tech-markers.md +87 -0
  59. package/template/.claude/skills/setup-smithery/SKILL.md +38 -0
  60. package/template/.claude/skills/sync/SKILL.md +239 -0
  61. package/template/.claude/skills/task-tracker/SKILL.md +40 -0
  62. package/template/.claude/skills/validate-setup/SKILL.md +30 -0
  63. package/template/.claude/skills/workflow/SKILL.md +333 -0
  64. package/template/.claude/templates/README.md +42 -0
  65. package/template/CLAUDE.md +67 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 adnan-prompts
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,306 @@
1
+ # Claude Code Scanner
2
+
3
+ > Scan any codebase and generate a complete Claude Code environment — 12 role-based agents, 13 skills, 12 hooks, rules, templates, full SDLC workflow with execution analytics.
4
+
5
+ ## Prerequisites
6
+
7
+ This tool requires **Node.js >= 18**. `npx` is included with Node.js/npm.
8
+
9
+ ### Check if Node.js is installed:
10
+ ```bash
11
+ node --version # Should be >= 18.x.x
12
+ npm --version # Should be >= 8.x.x
13
+ ```
14
+
15
+ ### Install Node.js if needed:
16
+
17
+ **macOS (using Homebrew):**
18
+ ```bash
19
+ brew install node
20
+ ```
21
+
22
+ **Ubuntu/Debian:**
23
+ ```bash
24
+ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
25
+ sudo apt-get install -y nodejs
26
+ ```
27
+
28
+ **Windows (using Chocolatey):**
29
+ ```bash
30
+ choco install nodejs
31
+ ```
32
+
33
+ **Or download from [nodejs.org](https://nodejs.org/)**
34
+
35
+ ## Installation
36
+
37
+ ### Method 1: npx (Recommended)
38
+ ```bash
39
+ cd /path/to/your-project
40
+ npx claude-code-scanner init
41
+ ```
42
+
43
+ ### Method 2: One-line install (macOS/Linux)
44
+ ```bash
45
+ cd /path/to/your-project
46
+ curl -fsSL https://raw.githubusercontent.com/adnan-prompts/claude-code-scanner/main/install.sh | bash
47
+ ```
48
+
49
+ ### Method 2b: One-line install (Windows PowerShell)
50
+ ```powershell
51
+ cd C:\path\to\your-project
52
+ irm https://raw.githubusercontent.com/adnan-prompts/claude-code-scanner/main/install.ps1 | iex
53
+ ```
54
+
55
+ ### Method 3: Git clone
56
+ ```bash
57
+ git clone https://github.com/adnan-prompts/claude-code-scanner.git /tmp/scanner
58
+ cp /tmp/scanner/template/CLAUDE.md ./CLAUDE.md
59
+ cp -r /tmp/scanner/template/.claude ./.claude
60
+ rm -rf /tmp/scanner
61
+ ```
62
+
63
+ ### Method 4: Global install
64
+ ```bash
65
+ npm install -g claude-code-scanner
66
+ cd /path/to/your-project
67
+ claude-code-scanner init
68
+ ```
69
+
70
+ ### Cross-Platform Support
71
+
72
+ Works on **Windows**, **macOS**, and **Linux**. All hooks and scripts use Node.js (no bash/jq dependency). The only requirement is Node.js >= 18.
73
+
74
+ ## Usage
75
+
76
+ After installing, 3 commands set up everything:
77
+
78
+ ```bash
79
+ claude # Start Claude Code session
80
+ /scan-codebase # Scan your tech stack (2-5 min)
81
+ /generate-environment # Generate all Claude Code files
82
+ ```
83
+
84
+ That's it. Your project now has a complete AI-powered development environment.
85
+
86
+ ## What It Creates
87
+
88
+ ```
89
+ your-project/
90
+ ├── CLAUDE.md <- Project instructions (auto-loaded)
91
+ ├── .claude/
92
+ │ ├── settings.json <- Permissions + 10 hook events
93
+ │ ├── settings.local.json <- Your env vars (gitignored)
94
+ │ ├── rules/ <- Path-specific coding rules
95
+ │ ├── agents/ <- 12 role-based AI agents
96
+ │ │ ├── team-lead.md <- Orchestrator, assigns work, tech sign-off
97
+ │ │ ├── architect.md <- Architecture design & review
98
+ │ │ ├── product-owner.md <- Acceptance criteria, business sign-off
99
+ │ │ ├── qa-lead.md <- QA planning, QA sign-off
100
+ │ │ ├── explorer.md <- Codebase navigation & impact analysis
101
+ │ │ ├── reviewer.md <- Code review & conventions
102
+ │ │ ├── security.md <- Security & vulnerability review
103
+ │ │ ├── debugger.md <- Root cause analysis & bug fixing
104
+ │ │ ├── tester.md <- Test writing & coverage
105
+ │ │ ├── frontend.md <- UI component development
106
+ │ │ ├── api-builder.md <- API endpoint development
107
+ │ │ └── infra.md <- Docker, CI/CD, deployment
108
+ │ ├── skills/ <- 13 slash commands
109
+ │ │ ├── workflow/ <- /workflow — Full 13-phase SDLC
110
+ │ │ ├── scan-codebase/ <- /scan-codebase
111
+ │ │ ├── generate-environment/ <- /generate-environment
112
+ │ │ ├── task-tracker/ <- /task-tracker
113
+ │ │ ├── progress-report/ <- /progress-report
114
+ │ │ ├── metrics/ <- /metrics
115
+ │ │ ├── impact-analysis/ <- /impact-analysis
116
+ │ │ ├── execution-report/ <- /execution-report — Post-execution analytics
117
+ │ │ ├── context-check/ <- /context-check — Context budget enforcement
118
+ │ │ ├── rollback/ <- /rollback — Deploy/code/phase rollback
119
+ │ │ ├── sync/ <- /sync — Drift detection & repair
120
+ │ │ ├── setup-smithery/ <- /setup-smithery
121
+ │ │ └── validate-setup/ <- /validate-setup
122
+ │ ├── hooks/ <- 12 automation scripts (10 events)
123
+ │ ├── profiles/ <- Developer role profiles
124
+ │ ├── templates/ <- Code scaffolding (extracted from real code)
125
+ │ ├── docs/ <- 9 reference documents
126
+ │ ├── scripts/ <- Verification scripts
127
+ │ ├── tasks/ <- Task tracking (gitignored)
128
+ │ └── reports/ <- Progress & execution reports (gitignored)
129
+ ```
130
+
131
+ ## Agent Team (Role-Based)
132
+
133
+ ### SDLC Role Agents
134
+ | Agent | Role | Access | Model |
135
+ |-------|------|--------|-------|
136
+ | `@team-lead` | Orchestrator — assigns work, resolves blockers, tech sign-off | Read/Write | opus |
137
+ | `@architect` | Architecture design & review | Read-only | opus |
138
+ | `@product-owner` | Acceptance criteria, business sign-off | Read-only | opus |
139
+ | `@qa-lead` | QA planning, QA sign-off, bug triage | Read-only | sonnet |
140
+
141
+ ### Core Agents
142
+ | Agent | Role | Access | Model |
143
+ |-------|------|--------|-------|
144
+ | `@explorer` | Codebase investigation & impact mapping | Read-only | sonnet |
145
+ | `@reviewer` | Code quality & convention review | Read-only | sonnet |
146
+ | `@security` | Vulnerability & OWASP review | Read-only | opus |
147
+ | `@debugger` | Root cause analysis & bug fixes | Read/Write | opus |
148
+ | `@tester` | Automated test writing & coverage | Read/Write | sonnet |
149
+
150
+ ### Dev Agents
151
+ | Agent | Role | Access | Model |
152
+ |-------|------|--------|-------|
153
+ | `@api-builder` | Backend endpoints & services | Read/Write + worktree | sonnet |
154
+ | `@frontend` | UI components & pages | Read/Write + worktree | sonnet |
155
+ | `@infra` | Docker, CI/CD, deployment | Read/Write | sonnet |
156
+
157
+ All agents include: structured handoff protocol with execution metrics, explicit limitations, cross-session memory, and self-check for hallucinations and regressions.
158
+
159
+ ## Commands After Setup
160
+
161
+ ### Built-in Skills
162
+ ```bash
163
+ /scan-codebase # Scan your tech stack
164
+ /generate-environment # Generate all Claude Code files
165
+ /validate-setup # Verify everything works
166
+ /workflow new "add user notifications" # Full 13-phase SDLC lifecycle
167
+ /workflow new --hotfix "fix login crash" # Fast-track hotfix
168
+ /workflow new --spike "evaluate Redis" # Research only
169
+ /workflow status # Dashboard
170
+ /task-tracker status # Task dashboard
171
+ /progress-report dev TASK-001 # Developer report
172
+ /progress-report business # Business stakeholder report
173
+ /metrics all # Velocity, quality, cycle-time
174
+ /impact-analysis "replace auth" # Blast radius check
175
+ /execution-report TASK-001 # Post-execution analytics
176
+ /context-check # Verify context under 60% budget
177
+ /rollback deploy TASK-001 # Rollback failed deployment
178
+ /sync --check # Detect environment drift
179
+ /sync --fix # Auto-repair stale files
180
+ /setup-smithery # Install community skills
181
+ ```
182
+
183
+ ### Generated Skills (created by /generate-environment based on your stack)
184
+ ```bash
185
+ /add-feature "password reset" # Scaffold feature
186
+ /add-endpoint "POST /api/orders" # Create API endpoint
187
+ /add-component "UserAvatar" # Create UI component
188
+ /fix-bug "cart total wrong" # Systematic debugging
189
+ /migrate "add user roles" # Database migration
190
+ /review-pr 123 # Code review
191
+ /qa-plan # Generate QA test plan
192
+ /signoff qa TASK-001 # Request sign-off
193
+ /deploy staging 456 # Deploy to staging
194
+ ```
195
+
196
+ ## Workflow (13 Phases)
197
+
198
+ ```
199
+ Phase 1: Task Intake — classify, branch, create task record
200
+ Phase 2: Impact Analysis — @explorer + @security parallel scan
201
+ Phase 3: Architecture Review — @architect designs (skip if small + LOW risk)
202
+ Phase 4: Business Analysis — @product-owner writes acceptance criteria
203
+ Phase 5: Development — @api-builder / @frontend / @infra (parallel worktrees)
204
+ Phase 6: Dev Self-Testing — @tester + @debugger loop (max 5 iterations)
205
+ Phase 7: Code Review — @reviewer + @security loop (max 3 iterations)
206
+ Phase 8: PR + CI — create PR, fix CI failures
207
+ Phase 9: QA Testing — @qa-lead plans, @tester executes, bug loop
208
+ Phase 10: Sign-offs — QA -> Business -> Tech (with rejection routing)
209
+ Phase 11: Deployment — @infra deploys, health check, rollback on failure
210
+ Phase 12: Post-Deploy — monitor, close issues, notify stakeholders
211
+ Phase 13: Execution Report — success score, hallucination check, regression audit
212
+ ```
213
+
214
+ Mandatory `/context-check` between every phase transition to enforce 60% context budget.
215
+
216
+ ## Hook Events (10 registered)
217
+
218
+ | Event | Hook | Purpose |
219
+ |-------|------|---------|
220
+ | SessionStart | session-start.js | Re-inject active task context |
221
+ | PreToolUse | protect-files.js, validate-bash.js | Block dangerous operations |
222
+ | PostToolUse | post-edit-format.js, track-file-changes.js | Auto-format, log changes |
223
+ | PostToolUseFailure | tool-failure-tracker.js | Track tool errors for debugging |
224
+ | PreCompact | pre-compact-save.js | Save loop state before compaction |
225
+ | PostCompact | post-compact-recovery.js | Restore workflow state after compaction |
226
+ | Notification | notify-approval.js | OS notification on permission prompt |
227
+ | SubagentStop | track-file-changes.js | Record subagent file changes |
228
+ | Stop | execution-report.js + prompt | Mandatory execution report |
229
+ | StopFailure | stop-failure-handler.js | Preserve state on failures |
230
+
231
+ ## Execution Reports
232
+
233
+ Every phase generates a scored report:
234
+ - **Success Score (0-100)** — completeness + quality + efficiency
235
+ - **Hallucination Check (0-3)** — verifies file refs, function names, conventions
236
+ - **Regression Impact (0-3)** — test suite, coverage delta, lint/type/build
237
+ - **Agent Communication** — handoff count, loop iterations, parallel executions
238
+ - **Token/Context Usage** — estimated consumption, peak context %
239
+
240
+ ## Context Budget
241
+
242
+ Everything is designed to keep working context under 60%:
243
+
244
+ | What | Context Cost | When Loaded |
245
+ |------|-------------|-------------|
246
+ | CLAUDE.md + rules | ~332 tokens | Always (startup) |
247
+ | Agent descriptions | ~371 tokens | Always (metadata only) |
248
+ | Skill descriptions | ~250 tokens | Always (metadata only) |
249
+ | Agent full bodies | 0 on parent | Subagent context (isolated) |
250
+ | Forked skills (11/13) | 0 on parent | Fork context (isolated) |
251
+ | Templates/profiles/docs | 0 | Never auto-loaded |
252
+ | **Total startup** | **~1,500 tokens** | **~1.2% of 128K** |
253
+
254
+ Runtime enforcement: `/context-check` between phases, PreCompact hook saves state, PostCompact hook restores it.
255
+
256
+ ## Keeping In Sync
257
+
258
+ The environment tracks its own state via `.claude/manifest.json`. When the codebase changes (new dependencies, new directories, team role changes), drift is detected automatically:
259
+
260
+ - **On session start:** `drift-detector.js` hook checks for stale agents, modified dependencies, orphan hooks
261
+ - **On workflow start:** Phase 1 runs `/sync --check` before intake
262
+ - **Manually:** `/sync --check` (report) or `/sync --fix` (auto-repair)
263
+ - **Full reset:** `/sync --full-rescan` re-scans and regenerates everything
264
+
265
+ ## CLI Commands
266
+
267
+ ```bash
268
+ npx claude-code-scanner init # Initialize in current directory
269
+ npx claude-code-scanner status # Check setup status
270
+ npx claude-code-scanner verify # Run verification checks (170+ checks)
271
+ npx claude-code-scanner update # Update to latest version
272
+ npx claude-code-scanner help # Show help
273
+
274
+ # Flags
275
+ npx claude-code-scanner init --force # Overwrite existing files
276
+ npx claude-code-scanner init --no-smithery # Skip Smithery instructions
277
+ ```
278
+
279
+ ## How It Works
280
+
281
+ 1. **`/scan-codebase`** spawns 6 parallel agents that read your actual code:
282
+ - Technology fingerprinter (100+ framework markers)
283
+ - Directory structure mapper
284
+ - Backend deep scanner (API routes, DB, auth, logging)
285
+ - Frontend deep scanner (components, state, styling, routing)
286
+ - Architecture mapper (data flow, dependencies, security)
287
+ - Domain & convention extractor (naming, patterns, gotchas)
288
+
289
+ 2. **`/generate-environment`** uses scan results to create project-specific:
290
+ - CLAUDE.md with your exact commands, paths, and conventions
291
+ - Rules that enforce YOUR codebase patterns
292
+ - 12 agents configured for YOUR tech stack
293
+ - Skills with YOUR project's commands and file paths
294
+ - Templates extracted from YOUR existing code
295
+ - Profiles for backend, frontend, and devops roles
296
+
297
+ 3. **`/workflow`** orchestrates the full 13-phase SDLC with your agent team:
298
+ - Structured handoff protocol between every agent transition
299
+ - Loop limits with circuit breakers (dev-test 5x, review 3x, QA 3x)
300
+ - Rejection routing from sign-off gates back to correct phase
301
+ - Mandatory execution report with scoring after every phase
302
+ - Context budget enforcement between every phase transition
303
+
304
+ ## License
305
+
306
+ MIT
package/bin/cli.js ADDED
@@ -0,0 +1,305 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ // Check prerequisites
7
+ function checkPrerequisites() {
8
+ const { execSync } = require('child_process');
9
+
10
+ try {
11
+ // Check Node.js version
12
+ const nodeVersion = execSync('node --version', { encoding: 'utf-8' }).trim();
13
+ const nodeMajor = parseInt(nodeVersion.replace('v', '').split('.')[0]);
14
+ if (nodeMajor < 18) {
15
+ error(`Node.js ${nodeVersion} detected. This tool requires Node.js >= 18.`);
16
+ error('Please upgrade Node.js: https://nodejs.org/');
17
+ process.exit(1);
18
+ }
19
+ } catch (e) {
20
+ error('Node.js not found. Please install Node.js >= 18: https://nodejs.org/');
21
+ process.exit(1);
22
+ }
23
+
24
+ try {
25
+ // Check npm version (which includes npx)
26
+ const npmVersion = execSync('npm --version', { encoding: 'utf-8' }).trim();
27
+ const npmMajor = parseInt(npmVersion.split('.')[0]);
28
+ if (npmMajor < 8) {
29
+ error(`npm ${npmVersion} detected. This tool requires npm >= 8.`);
30
+ error('Please upgrade npm: npm install -g npm');
31
+ process.exit(1);
32
+ }
33
+ } catch (e) {
34
+ error('npm not found. Please install npm (comes with Node.js): https://nodejs.org/');
35
+ process.exit(1);
36
+ }
37
+ }
38
+
39
+ // Run prerequisite check
40
+ checkPrerequisites();
41
+
42
+ const COMMANDS = {
43
+ init: 'Initialize Claude Code environment in current directory',
44
+ status: 'Check if Claude Code environment is set up',
45
+ verify: 'Run verification checks on existing setup',
46
+ update: 'Update scanner skills/agents to latest version',
47
+ help: 'Show this help message',
48
+ };
49
+
50
+ const args = process.argv.slice(2);
51
+ const command = args[0] || 'help';
52
+ const flags = args.slice(1);
53
+
54
+ const CYAN = '\x1b[36m';
55
+ const GREEN = '\x1b[32m';
56
+ const YELLOW = '\x1b[33m';
57
+ const RED = '\x1b[31m';
58
+ const BOLD = '\x1b[1m';
59
+ const RESET = '\x1b[0m';
60
+
61
+ function log(msg) { console.log(msg); }
62
+ function success(msg) { log(`${GREEN}✓${RESET} ${msg}`); }
63
+ function warn(msg) { log(`${YELLOW}!${RESET} ${msg}`); }
64
+ function error(msg) { log(`${RED}✗${RESET} ${msg}`); }
65
+ function header(msg) { log(`\n${BOLD}${CYAN}${msg}${RESET}`); }
66
+
67
+ function copyDir(src, dest, overwrite = false) {
68
+ if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
69
+
70
+ const entries = fs.readdirSync(src, { withFileTypes: true });
71
+ let copied = 0;
72
+ let skipped = 0;
73
+
74
+ for (const entry of entries) {
75
+ const srcPath = path.join(src, entry.name);
76
+ const destPath = path.join(dest, entry.name);
77
+
78
+ if (entry.isDirectory()) {
79
+ const result = copyDir(srcPath, destPath, overwrite);
80
+ copied += result.copied;
81
+ skipped += result.skipped;
82
+ } else {
83
+ if (fs.existsSync(destPath) && !overwrite) {
84
+ skipped++;
85
+ } else {
86
+ fs.copyFileSync(srcPath, destPath);
87
+ copied++;
88
+ }
89
+ }
90
+ }
91
+ return { copied, skipped };
92
+ }
93
+
94
+ function init() {
95
+ const cwd = process.cwd();
96
+ const templateDir = path.join(__dirname, '..', 'template');
97
+ const force = flags.includes('--force') || flags.includes('-f');
98
+ const skipSmithery = flags.includes('--no-smithery');
99
+
100
+ header('Claude Code Scanner — Environment Setup');
101
+ log(`Target: ${cwd}\n`);
102
+
103
+ // Check if already initialized
104
+ if (fs.existsSync(path.join(cwd, 'CLAUDE.md')) && !force) {
105
+ warn('CLAUDE.md already exists. Use --force to overwrite.');
106
+ log(' Or run: npx claude-code-scanner update');
107
+ process.exit(1);
108
+ }
109
+
110
+ // Copy CLAUDE.md to root
111
+ log('Installing files...\n');
112
+
113
+ const claudeMdSrc = path.join(templateDir, 'CLAUDE.md');
114
+ const claudeMdDest = path.join(cwd, 'CLAUDE.md');
115
+ fs.copyFileSync(claudeMdSrc, claudeMdDest);
116
+ success('CLAUDE.md');
117
+
118
+ // Copy .claude/ directory structure
119
+ const dirs = ['rules', 'agents', 'skills', 'hooks', 'scripts', 'docs', 'templates', 'profiles'];
120
+ for (const dir of dirs) {
121
+ const src = path.join(templateDir, '.claude', dir);
122
+ const dest = path.join(cwd, '.claude', dir);
123
+ if (fs.existsSync(src)) {
124
+ const result = copyDir(src, dest, force);
125
+ success(`.claude/${dir}/ (${result.copied} files${result.skipped ? `, ${result.skipped} skipped` : ''})`);
126
+ }
127
+ }
128
+
129
+ // Copy settings files
130
+ const settingsSrc = path.join(templateDir, '.claude', 'settings.json');
131
+ const settingsDest = path.join(cwd, '.claude', 'settings.json');
132
+ if (fs.existsSync(settingsSrc) && (!fs.existsSync(settingsDest) || force)) {
133
+ fs.copyFileSync(settingsSrc, settingsDest);
134
+ success('.claude/settings.json');
135
+ }
136
+
137
+ const localSettingsDest = path.join(cwd, '.claude', 'settings.local.json');
138
+ if (!fs.existsSync(localSettingsDest)) {
139
+ fs.writeFileSync(localSettingsDest, JSON.stringify({ env: {} }, null, 2));
140
+ success('.claude/settings.local.json (template)');
141
+ }
142
+
143
+ // Copy manifest.json for drift detection
144
+ const manifestSrc = path.join(templateDir, '.claude', 'manifest.json');
145
+ const manifestDest = path.join(cwd, '.claude', 'manifest.json');
146
+ if (fs.existsSync(manifestSrc) && (!fs.existsSync(manifestDest) || force)) {
147
+ fs.copyFileSync(manifestSrc, manifestDest);
148
+ success('.claude/manifest.json (drift tracking)');
149
+ }
150
+
151
+ // Create task/report/execution directories
152
+ fs.mkdirSync(path.join(cwd, '.claude', 'tasks'), { recursive: true });
153
+ fs.mkdirSync(path.join(cwd, '.claude', 'reports', 'daily'), { recursive: true });
154
+ fs.mkdirSync(path.join(cwd, '.claude', 'reports', 'executions'), { recursive: true });
155
+ // Ensure empty template dirs exist even if copyDir skips them
156
+ fs.mkdirSync(path.join(cwd, '.claude', 'profiles'), { recursive: true });
157
+ fs.mkdirSync(path.join(cwd, '.claude', 'templates'), { recursive: true });
158
+ success('.claude/tasks/, .claude/reports/, .claude/profiles/, .claude/templates/');
159
+
160
+ // Make hook scripts executable (handle both .js and legacy .sh)
161
+ const hooksDir = path.join(cwd, '.claude', 'hooks');
162
+ if (fs.existsSync(hooksDir)) {
163
+ for (const file of fs.readdirSync(hooksDir)) {
164
+ if (file.endsWith('.sh') || file.endsWith('.js')) {
165
+ const hookPath = path.join(hooksDir, file);
166
+ try { fs.chmodSync(hookPath, 0o755); } catch (e) { /* Windows — not needed for .js */ }
167
+ }
168
+ }
169
+ success('Hook scripts ready');
170
+ }
171
+
172
+ // Update .gitignore
173
+ const gitignorePath = path.join(cwd, '.gitignore');
174
+ const gitignoreEntries = [
175
+ '.claude/settings.local.json',
176
+ '.claude/agent-memory-local/',
177
+ '.claude/tasks/',
178
+ '.claude/reports/',
179
+ ];
180
+
181
+ let gitignoreContent = fs.existsSync(gitignorePath)
182
+ ? fs.readFileSync(gitignorePath, 'utf-8')
183
+ : '';
184
+
185
+ const newEntries = gitignoreEntries.filter(e => !gitignoreContent.includes(e));
186
+ if (newEntries.length > 0) {
187
+ gitignoreContent += '\n# Claude Code local files\n' + newEntries.join('\n') + '\n';
188
+ fs.writeFileSync(gitignorePath, gitignoreContent);
189
+ success(`.gitignore updated (${newEntries.length} entries)`);
190
+ }
191
+
192
+ // Summary
193
+ header('Setup Complete!\n');
194
+ log('Next steps:\n');
195
+ log(` ${BOLD}1.${RESET} cd ${cwd}`);
196
+ log(` ${BOLD}2.${RESET} claude`);
197
+ log(` ${BOLD}3.${RESET} /scan-codebase ${CYAN}# Scan your tech stack${RESET}`);
198
+ log(` ${BOLD}4.${RESET} /generate-environment ${CYAN}# Generate customized environment${RESET}`);
199
+ log(` ${BOLD}5.${RESET} /validate-setup ${CYAN}# Verify everything works${RESET}`);
200
+ if (!skipSmithery) {
201
+ log(` ${BOLD}6.${RESET} /setup-smithery ${CYAN}# Install community skills (optional)${RESET}`);
202
+ }
203
+ log('');
204
+ log(`Then start working:`);
205
+ log(` /workflow new "your first task"`);
206
+ log('');
207
+ }
208
+
209
+ function status() {
210
+ const cwd = process.cwd();
211
+ header('Claude Code Environment Status\n');
212
+
213
+ const checks = [
214
+ ['CLAUDE.md', path.join(cwd, 'CLAUDE.md')],
215
+ ['.claude/rules/', path.join(cwd, '.claude', 'rules')],
216
+ ['.claude/agents/', path.join(cwd, '.claude', 'agents')],
217
+ ['.claude/skills/', path.join(cwd, '.claude', 'skills')],
218
+ ['.claude/settings.json', path.join(cwd, '.claude', 'settings.json')],
219
+ ['.claude/hooks/', path.join(cwd, '.claude', 'hooks')],
220
+ ['.claude/scripts/', path.join(cwd, '.claude', 'scripts')],
221
+ ['.claude/docs/', path.join(cwd, '.claude', 'docs')],
222
+ ];
223
+
224
+ let found = 0;
225
+ for (const [name, p] of checks) {
226
+ if (fs.existsSync(p)) { success(name); found++; }
227
+ else { error(`${name} — missing`); }
228
+ }
229
+
230
+ log('');
231
+ if (found === checks.length) {
232
+ log(`${GREEN}${BOLD}Environment is fully set up.${RESET}`);
233
+ log('Run: claude → /scan-codebase → /generate-environment');
234
+ } else if (found > 0) {
235
+ log(`${YELLOW}${BOLD}Partially set up (${found}/${checks.length}).${RESET}`);
236
+ log('Run: npx claude-code-scanner init --force');
237
+ } else {
238
+ log(`${RED}${BOLD}Not initialized.${RESET}`);
239
+ log('Run: npx claude-code-scanner init');
240
+ }
241
+ }
242
+
243
+ function verify() {
244
+ const cwd = process.cwd();
245
+ // Prefer cross-platform .js, fall back to legacy .sh
246
+ const jsPath = path.join(cwd, '.claude', 'scripts', 'verify-setup.js');
247
+ const shPath = path.join(cwd, '.claude', 'scripts', 'verify-setup.sh');
248
+ const scriptPath = fs.existsSync(jsPath) ? jsPath : shPath;
249
+ if (!fs.existsSync(scriptPath)) {
250
+ error('Verification script not found. Run: npx claude-code-scanner init');
251
+ process.exit(1);
252
+ }
253
+ const { execSync } = require('child_process');
254
+ try {
255
+ if (scriptPath.endsWith('.js')) {
256
+ execSync(`node "${scriptPath}"`, { stdio: 'inherit', cwd });
257
+ } else {
258
+ execSync(`bash "${scriptPath}"`, { stdio: 'inherit', cwd });
259
+ }
260
+ } catch (e) {
261
+ process.exit(1);
262
+ }
263
+ }
264
+
265
+ function update() {
266
+ flags.push('--force');
267
+ init();
268
+ }
269
+
270
+ function help() {
271
+ header('Claude Code Scanner\n');
272
+ log('Scan any codebase and generate a complete Claude Code environment.\n');
273
+ log(`${BOLD}Usage:${RESET}`);
274
+ log(' npx claude-code-scanner <command> [options]\n');
275
+ log(`${BOLD}Commands:${RESET}`);
276
+ for (const [cmd, desc] of Object.entries(COMMANDS)) {
277
+ log(` ${CYAN}${cmd.padEnd(12)}${RESET} ${desc}`);
278
+ }
279
+ log(`\n${BOLD}Options:${RESET}`);
280
+ log(` ${CYAN}--force, -f${RESET} Overwrite existing files`);
281
+ log(` ${CYAN}--no-smithery${RESET} Skip Smithery setup step in instructions`);
282
+ log(`\n${BOLD}Quick Start:${RESET}`);
283
+ log(' cd /path/to/your-project');
284
+ log(' npx claude-code-scanner init');
285
+ log(' claude');
286
+ log(' /scan-codebase');
287
+ log(' /generate-environment');
288
+ log('');
289
+ }
290
+
291
+ // Route command
292
+ switch (command) {
293
+ case 'init': init(); break;
294
+ case 'status': status(); break;
295
+ case 'verify': verify(); break;
296
+ case 'update': update(); break;
297
+ case 'help': case '--help': case '-h': help(); break;
298
+ case '--version': case '-v': case '-V': case 'version':
299
+ log(require('../package.json').version);
300
+ break;
301
+ default:
302
+ error(`Unknown command: ${command}`);
303
+ help();
304
+ process.exit(1);
305
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "claude-code-scanner",
3
+ "version": "1.0.0",
4
+ "description": "Scan any codebase and generate a complete Claude Code environment — agents, skills, hooks, rules, templates, and SDLC workflow",
5
+ "author": "adnan-prompts",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/adnan-prompts/claude-code-scanner#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/adnan-prompts/claude-code-scanner.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/adnan-prompts/claude-code-scanner/issues"
14
+ },
15
+ "bin": {
16
+ "claude-code-scanner": "./bin/cli.js"
17
+ },
18
+ "scripts": {
19
+ "postinstall": "echo '✓ Run: npx claude-code-scanner init'"
20
+ },
21
+ "keywords": [
22
+ "claude",
23
+ "claude-code",
24
+ "ai",
25
+ "agents",
26
+ "skills",
27
+ "claude-code-scanner",
28
+ "sdlc",
29
+ "cli",
30
+ "generator",
31
+ "developer-tools"
32
+ ],
33
+ "files": [
34
+ "bin/",
35
+ "template/",
36
+ "README.md",
37
+ "DOCUMENTATION.md",
38
+ "LICENSE"
39
+ ],
40
+ "engines": {
41
+ "node": ">=18"
42
+ }
43
+ }