@@ -129,23 +129,36 @@ foreach ($dir in $skillDirs) {
129129
130130Write-Step " Installing host-protection hook..."
131131
132- $hookUrl = " https://raw.githubusercontent.com/$Repo /main/hooks/devcontainer-guard.sh"
132+ $hookUrl = " https://raw.githubusercontent.com/$Repo /main/.github/hooks/devcontainer-guard.sh"
133+ $loaderUrl = " https://raw.githubusercontent.com/$Repo /main/.github/hooks/devcontainer-skill-loader.sh"
133134$WslHookDir = " ~/.local/share/devcontainer-mcp/hooks"
134135$WslHookPath = " $WslHookDir /devcontainer-guard.sh"
136+ $WslLoaderPath = " $WslHookDir /devcontainer-skill-loader.sh"
135137
136138$hookResult = wsl - d $WslDistro bash - c " mkdir -p '$WslHookDir ' && curl -fsSL -o '$WslHookPath ' '$hookUrl ' && chmod +x '$WslHookPath ' && echo OK" 2>&1
137139if ($hookResult -match " OK" ) {
138- Write-Ok " Hook script installed in WSL at $WslHookPath "
140+ Write-Ok " Guard hook installed in WSL at $WslHookPath "
139141} else {
140- Write-Warn " Could not install hook script in WSL"
142+ Write-Warn " Could not install guard hook in WSL"
141143}
142144
143- # Configure Claude Code PreToolUse hook (Windows-side)
144- Write-Step " Configuring agent host-protection hooks..."
145+ $loaderResult = wsl - d $WslDistro bash - c " curl -fsSL -o '$WslLoaderPath ' '$loaderUrl ' && chmod +x '$WslLoaderPath ' && echo OK" 2>&1
146+ if ($loaderResult -match " OK" ) {
147+ Write-Ok " Skill-loader hook installed in WSL at $WslLoaderPath "
148+ } else {
149+ Write-Warn " Could not install skill-loader hook in WSL"
150+ }
151+
152+ # Install SKILL.md alongside hooks for the loader to find
153+ $WslSkillDataPath = " ~/.local/share/devcontainer-mcp/SKILL.md"
154+ wsl - d $WslDistro bash - c " curl -fsSL -o '$WslSkillDataPath ' '$skillUrl '" 2>&1 | Out-Null
155+
156+ # Configure Claude Code PreToolUse + SessionStart hooks (Windows-side)
157+ Write-Step " Configuring agent hooks..."
145158
146159$claudeSettings = " $env: USERPROFILE \.claude\settings.json"
147160try {
148- $hookEntry = @ {
161+ $guardEntry = @ {
149162 matcher = " Bash"
150163 hooks = @ (
151164 @ {
@@ -155,35 +168,64 @@ try {
155168 }
156169 )
157170 }
171+ $loaderEntry = @ {
172+ hooks = @ (
173+ @ {
174+ type = " command"
175+ command = " wsl $WslLoaderPath "
176+ timeout = 5
177+ }
178+ )
179+ }
158180
159181 if (Test-Path $claudeSettings ) {
160182 $content = Get-Content - Raw $claudeSettings | ConvertFrom-Json
161183 if (-not $content.hooks ) {
162184 $content | Add-Member - NotePropertyName " hooks" - NotePropertyValue ([PSCustomObject ]@ {})
163185 }
186+
187+ # PreToolUse: devcontainer-guard
164188 if (-not $content.hooks.PreToolUse ) {
165189 $content.hooks | Add-Member - NotePropertyName " PreToolUse" - NotePropertyValue @ ()
166190 }
167- # Check if already configured
168- $already = $false
191+ $alreadyGuard = $false
169192 foreach ($group in $content.hooks.PreToolUse ) {
170193 foreach ($h in $group.hooks ) {
171- if ($h.command -match " devcontainer-guard" ) { $already = $true ; break }
194+ if ($h.command -match " devcontainer-guard" ) { $alreadyGuard = $true ; break }
172195 }
173196 }
174- if (-not $already ) {
175- $content.hooks.PreToolUse += [PSCustomObject ]$hookEntry
176- $content | ConvertTo-Json - Depth 10 | Set-Content $claudeSettings - Encoding UTF8
177- Write-Ok " Claude Code — added hook to $claudeSettings "
197+ if (-not $alreadyGuard ) {
198+ $content.hooks.PreToolUse += [PSCustomObject ]$guardEntry
199+ Write-Ok " Claude Code — added PreToolUse hook"
178200 } else {
179- Write-Ok " Claude Code — hook already configured"
201+ Write-Ok " Claude Code — PreToolUse hook already configured"
180202 }
203+
204+ # SessionStart: skill-loader
205+ if (-not $content.hooks.SessionStart ) {
206+ $content.hooks | Add-Member - NotePropertyName " SessionStart" - NotePropertyValue @ ()
207+ }
208+ $alreadyLoader = $false
209+ foreach ($group in $content.hooks.SessionStart ) {
210+ foreach ($h in $group.hooks ) {
211+ if ($h.command -match " skill-loader" ) { $alreadyLoader = $true ; break }
212+ }
213+ }
214+ if (-not $alreadyLoader ) {
215+ $content.hooks.SessionStart += [PSCustomObject ]$loaderEntry
216+ Write-Ok " Claude Code — added SessionStart hook"
217+ } else {
218+ Write-Ok " Claude Code — SessionStart hook already configured"
219+ }
220+
221+ $content | ConvertTo-Json - Depth 10 | Set-Content $claudeSettings - Encoding UTF8
181222 } else {
182223 $dir = Split-Path $claudeSettings - Parent
183224 if ($dir ) { New-Item - ItemType Directory - Path $dir - Force | Out-Null }
184225 $config = [PSCustomObject ]@ {
185226 hooks = [PSCustomObject ]@ {
186- PreToolUse = @ ([PSCustomObject ]$hookEntry )
227+ PreToolUse = @ ([PSCustomObject ]$guardEntry )
228+ SessionStart = @ ([PSCustomObject ]$loaderEntry )
187229 }
188230 }
189231 $config | ConvertTo-Json - Depth 10 | Set-Content $claudeSettings - Encoding UTF8
@@ -193,11 +235,12 @@ try {
193235 Write-Warn " Claude Code — could not configure hooks"
194236}
195237
196- # Configure Copilot CLI preToolUse hook (Windows-side)
238+ # Configure Copilot CLI preToolUse + sessionStart hooks (Windows-side)
197239$copilotHooksDir = " $env: USERPROFILE \.copilot\hooks"
198240try {
199241 New-Item - ItemType Directory - Path $copilotHooksDir - Force | Out-Null
200- $copilotHook = [PSCustomObject ]@ {
242+
243+ $copilotGuard = [PSCustomObject ]@ {
201244 version = 1
202245 hooks = [PSCustomObject ]@ {
203246 preToolUse = @ (
@@ -209,8 +252,23 @@ try {
209252 )
210253 }
211254 }
212- $copilotHook | ConvertTo-Json - Depth 10 | Set-Content " $copilotHooksDir \devcontainer-guard.json" - Encoding UTF8
255+ $copilotGuard | ConvertTo-Json - Depth 10 | Set-Content " $copilotHooksDir \devcontainer-guard.json" - Encoding UTF8
213256 Write-Ok " Copilot CLI — created $copilotHooksDir \devcontainer-guard.json"
257+
258+ $copilotLoader = [PSCustomObject ]@ {
259+ version = 1
260+ hooks = [PSCustomObject ]@ {
261+ sessionStart = @ (
262+ [PSCustomObject ]@ {
263+ type = " command"
264+ bash = " wsl $WslLoaderPath "
265+ timeoutSec = 5
266+ }
267+ )
268+ }
269+ }
270+ $copilotLoader | ConvertTo-Json - Depth 10 | Set-Content " $copilotHooksDir \devcontainer-skill-loader.json" - Encoding UTF8
271+ Write-Ok " Copilot CLI — created $copilotHooksDir \devcontainer-skill-loader.json"
214272} catch {
215273 Write-Warn " Copilot CLI — could not configure hooks"
216274}
0 commit comments