Set-ClaudeConfig.ps1

function Set-ClaudeConfig {
    [CmdletBinding(SupportsShouldProcess)]
    param(
        [string]$HomeDir = [System.Environment]::GetFolderPath('UserProfile')
    )

    $settingsPath = Join-Path $HomeDir '.claude' 'settings.json'
    Write-Verbose "Checking Claude settings at '$settingsPath'."

    $settings = if (Test-Path $settingsPath) {
        try {
            Get-Content $settingsPath -Raw | ConvertFrom-Json -AsHashtable
        } catch {
            Write-Warning "Could not parse '$settingsPath': $_. Starting with empty settings."
            @{}
        }
    } else {
        @{}
    }

    $changed = $false

    if ($settings['defaultShell'] -ne 'powershell') {
        Write-Verbose "Setting defaultShell to 'powershell'."
        $settings['defaultShell'] = 'powershell'
        $changed = $true
    } else {
        Write-Verbose "defaultShell already 'powershell'; no changes needed."
    }

    if ($changed -and $PSCmdlet.ShouldProcess($settingsPath, 'Write Claude settings')) {
        $dir = Split-Path $settingsPath
        if (-not (Test-Path $dir)) {
            New-Item -ItemType Directory -Path $dir -Force | Out-Null
        }
        $settings | ConvertTo-Json -Depth 10 | Set-Content $settingsPath -Encoding UTF8
        Write-Verbose "Wrote updated settings to '$settingsPath'."
    }
}