mcfly init powershell hangs in non-interactive sessions due to Install-Module PSReadLine
Problem
mcfly init powershell generates a script (mcfly.ps1) that unconditionally calls Install-Module PSReadLine when PSReadLine is not already loaded:
https://github.com/cantino/mcfly/blob/master/mcfly.ps1#L13-L16
if ($null -eq (Get-Module -Name PSReadLine)) {
Write-Host "Installing PSReadLine as McFly dependency"
Install-Module PSReadLine
}Because Install-Module is called without -Force or -Confirm:$false, it prompts for user confirmation. In non-interactive sessions (CI pipelines, VS Code tasks, AI coding agents, headless terminals), there is no user to confirm, so the shell hangs indefinitely at Installing PSReadLine as McFly dependency.
This blocks the entire PowerShell profile from loading.
Environment
- OS: Windows 11
- PowerShell: 7.x (pwsh)
- McFly: latest
Suggested fix
Guard the install with an interactivity check, and add -Force so it doesn't prompt:
if ($null -eq (Get-Module -Name PSReadLine)) {
if ([Environment]::UserInteractive) {
Write-Host "Installing PSReadLine as McFly dependency"
Install-Module PSReadLine -Force -Scope CurrentUser
} else {
Write-Warning "McFly requires PSReadLine but cannot install it in a non-interactive session. Run 'Install-Module PSReadLine' manually."
return
}
}Current workaround
Wrap the mcfly init in the user's PowerShell profile with a try/catch that checks for a console window:
try {
if ($host.Name -eq 'ConsoleHost' -and [Console]::WindowHeight -gt 0) {
Invoke-Expression -Command $(mcfly init powershell | out-string)
}
} catch {}Source: cantino/mcfly