-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
158 lines (134 loc) · 5.57 KB
/
Copy pathinstall.ps1
File metadata and controls
158 lines (134 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# install.ps1 — Claude Workflow setup installer for Windows
# Usage: powershell -ExecutionPolicy Bypass -File install.ps1 [-Project]
#
# -Project Also install CLAUDE.md + scripts\worktree-setup.sh
# into the current directory (run from your project root)
#Requires -Version 5.1
param(
[switch]$Project
)
$ErrorActionPreference = 'Stop'
$ScriptDir = $PSScriptRoot
$FilesDir = Join-Path $ScriptDir "files"
$ClaudeDir = "$env:USERPROFILE\.claude"
$Utf8NoBom = New-Object System.Text.UTF8Encoding $false
function Write-LF {
param([string]$Dest, [string]$Src)
$content = Get-Content $Src -Raw
$content = $content -replace "`r`n", "`n" -replace "`r", "`n"
[System.IO.File]::WriteAllText($Dest, $content, $Utf8NoBom)
}
# --- Prerequisites ---
Write-Host "Checking prerequisites..."
$python = $null
foreach ($cmd in @('python3','python')) {
if (Get-Command $cmd -ErrorAction SilentlyContinue) { $python = $cmd; break }
}
if (-not $python) {
Write-Host "ERROR: python3 not found. Install from https://python.org" -ForegroundColor Red
exit 1
}
Write-Host " python: $((& $python --version 2>&1))"
# --- Create ~/.claude directories ---
foreach ($d in @(
"$ClaudeDir\rules",
"$ClaudeDir\skills\dream",
"$ClaudeDir\skills\review",
"$ClaudeDir\commands",
"$ClaudeDir\handoff"
)) { New-Item -ItemType Directory -Force -Path $d | Out-Null }
# --- Install rules ---
Write-Host "Installing rules → $ClaudeDir\rules\"
Write-LF "$ClaudeDir\rules\code-style.md" "$FilesDir\rules\code-style.md"
Write-LF "$ClaudeDir\rules\testing.md" "$FilesDir\rules\testing.md"
Write-LF "$ClaudeDir\rules\git.md" "$FilesDir\rules\git.md"
Write-Host " code-style.md, testing.md, git.md"
# --- Install skills ---
Write-Host "Installing skills → $ClaudeDir\skills\"
Write-LF "$ClaudeDir\skills\dream\SKILL.md" "$FilesDir\skills\dream\SKILL.md"
Write-LF "$ClaudeDir\skills\review\SKILL.md" "$FilesDir\skills\review\SKILL.md"
Write-Host " dream/SKILL.md, review/SKILL.md"
# --- Install commands ---
Write-Host "Installing commands → $ClaudeDir\commands\"
Write-LF "$ClaudeDir\commands\doc-and-clear.md" "$FilesDir\commands\doc-and-clear.md"
Write-LF "$ClaudeDir\commands\fix-issue.md" "$FilesDir\commands\fix-issue.md"
Write-Host " doc-and-clear.md, fix-issue.md"
# --- Handoff placeholder ---
$gitkeep = "$ClaudeDir\handoff\.gitkeep"
if (-not (Test-Path $gitkeep)) { New-Item -ItemType File -Path $gitkeep | Out-Null }
# --- Merge hooks into ~/.claude/settings.json ---
Write-Host "Configuring hooks in $ClaudeDir\settings.json ..."
$SettingsPath = "$ClaudeDir\settings.json"
if (-not (Test-Path $SettingsPath)) {
[System.IO.File]::WriteAllText($SettingsPath, "{}`n", $Utf8NoBom)
}
$cfg = Get-Content $SettingsPath -Raw -Encoding UTF8 | ConvertFrom-Json
$preHook = [PSCustomObject]@{
matcher = "Edit|Write"
hooks = @(
[PSCustomObject]@{
type = "command"
command = "python3 -c `"import json, sys; data=json.load(sys.stdin); path=data.get('tool_input',{}).get('file_path',''); sys.exit(2 if any(p in path for p in ['.env', '.git/', 'package-lock.json', 'yarn.lock']) else 0)`""
}
)
}
$postHook = [PSCustomObject]@{
matcher = "Edit|Write"
hooks = @(
[PSCustomObject]@{
type = "command"
command = "if echo `"`$CLAUDE_FILE_PATH`" | grep -qE '\.(ts|tsx|js|jsx)$'; then npx prettier --write `"`$CLAUDE_FILE_PATH`" 2>/dev/null; fi"
}
)
}
$hooksObj = [PSCustomObject]@{
PreToolUse = @($preHook)
PostToolUse = @($postHook)
}
if ($cfg.PSObject.Properties['hooks']) {
$cfg.hooks = $hooksObj
} else {
$cfg | Add-Member -NotePropertyName hooks -NotePropertyValue $hooksObj
}
$json = $cfg | ConvertTo-Json -Depth 10
$json = $json -replace "`r`n", "`n"
[System.IO.File]::WriteAllText($SettingsPath, $json + "`n", $Utf8NoBom)
Write-Host " Hooks written."
# --- Project-level files (-Project flag) ---
if ($Project) {
Write-Host ""
Write-Host "Installing project files in $(Get-Location) ..."
if (Test-Path "CLAUDE.md") {
Write-Host " CLAUDE.md already exists — skipping (delete it first to overwrite)"
} else {
Write-LF "CLAUDE.md" "$FilesDir\CLAUDE.md"
Write-Host " CLAUDE.md"
}
New-Item -ItemType Directory -Force -Path ".claude\handoff" | Out-Null
New-Item -ItemType Directory -Force -Path "scripts" | Out-Null
$gk = ".claude\handoff\.gitkeep"
if (-not (Test-Path $gk)) { New-Item -ItemType File -Path $gk | Out-Null }
Write-LF "scripts\worktree-setup.sh" "$FilesDir\scripts\worktree-setup.sh"
Write-Host " scripts\worktree-setup.sh"
Write-Host " (make it executable in Git Bash: chmod +x scripts/worktree-setup.sh)"
}
# --- Done ---
Write-Host ""
Write-Host "Global install complete:" -ForegroundColor Green
Write-Host " ~/.claude/rules/ code-style, testing, git"
Write-Host " ~/.claude/skills/ dream, review"
Write-Host " ~/.claude/commands/ doc-and-clear, fix-issue"
Write-Host " ~/.claude/settings.json hooks configured"
Write-Host ""
if (-not $Project) {
Write-Host "To also set up a project, run from your project root:"
Write-Host " powershell -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`" -Project"
Write-Host ""
}
Write-Host "Restart Claude Code to activate all changes."
Write-Host ""
Write-Host "Quick reference:"
Write-Host " /dream Consolidate memory"
Write-Host " /review Review code before committing"
Write-Host " /fix-issue N Fix GitHub issue #N"
Write-Host " /doc-and-clear Save progress and clear context"