# Claude Code Notification 훅 - 권한 요청 및 사용자 입력 대기 알림 # 이 스크립트는 Claude Code가 Notification 이벤트를 발생시킬 때 실행됩니다. # UTF-8 인코딩 강제 설정 [Console]::InputEncoding = [System.Text.Encoding]::UTF8 [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $OutputEncoding = [System.Text.Encoding]::UTF8 # .env 파일에서 Slack 웹훅 URL 로드 $envFile = Join-Path $env:CLAUDE_PROJECT_DIR ".env" if (-Not (Test-Path $envFile)) { Write-Error "오류: .env 파일을 찾을 수 없습니다: $envFile" exit 1 } foreach ($line in Get-Content $envFile -Encoding UTF8) { if ($line -match '^\s*#' -or $line -match '^\s*$') { continue } $parts = $line -split '=', 2 if ($parts.Count -eq 2) { [System.Environment]::SetEnvironmentVariable($parts[0].Trim(), $parts[1].Trim(), 'Process') } } $slackWebhookUrl = $env:SLACK_WEBHOOK_URL if (-Not $slackWebhookUrl) { Write-Error "오류: SLACK_WEBHOOK_URL이 설정되지 않았습니다." exit 1 } # stdin에서 JSON 입력 읽기 $stdinData = $input | Out-String if (-Not $stdinData) { $stdinData = [Console]::In.ReadToEnd() } # JSON 입력에서 메시지 추출 $message = "" try { $json = $stdinData | ConvertFrom-Json $message = $json.message } catch {} # 프로젝트명 및 시간 $projectName = Split-Path $env:CLAUDE_PROJECT_DIR -Leaf $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" # Slack payload 생성 및 전송 $payload = @{ channel = "#claude-code" username = "Claude Code" icon_emoji = ":bell:" text = "🔔 권한 요청 알림`n`n프로젝트: $projectName`n상태: $message`n시간: $timestamp`n`nClaude Code에서 알림이 도착했습니다." } | ConvertTo-Json -Compress try { Invoke-RestMethod -Uri $slackWebhookUrl -Method Post -ContentType "application/json; charset=utf-8" -Body ([System.Text.Encoding]::UTF8.GetBytes($payload)) | Out-Null Write-Host "Slack 알림이 성공적으로 전송되었습니다." -ForegroundColor Green } catch { Write-Error "Slack 알림 전송에 실패했습니다: $_" exit 1 }