init-session.ps1 lacks the Windows PowerShell 5.1 cwd recovery for project paths containing [ or ]

Author: OthmanAdiCreated Sep 17, 2026Updated Sep 17, 2026
Labelsbughelp wanted

Problem

Windows PowerShell 5.1 started with -File from a directory whose path contains [ or ] moves its working directory to $PSHOME before the script runs. set-active-plan.ps1 carries a recovery block for this case; init-session.ps1 does not. In such a project, root mode reports success without writing into the project, and named mode fails at New-Item .planning.

Scope: Windows PowerShell 5.1 only (pwsh 7 is not affected), and only when the project path contains a wildcard character such as [ or ]. Other project paths work on 5.1.

How to reproduce

powershell
mkdir 'C:\work\proj [v2]'; cd 'C:\work\proj [v2]'
powershell.exe -NoProfile -ExecutionPolicy Bypass -File ..\scripts\init-session.ps1

Observed: Planning files initialized! and exit code 0, but no planning file exists in the project. The writes went to $PSHOME (C:\Windows\System32\WindowsPowerShell\v1.0), where a normal user is denied and the Out-File error is non-terminating (see #255). With a plan name argument the run fails at New-Item for .planning under $PSHOME.

Cause: a known Windows PowerShell 5.1 behaviour: the -File host resolves the inherited cwd through wildcard expansion and falls back to $PSHOME when the literal path does not round-trip. skills/planning-with-files/scripts/set-active-plan.ps1 detects this ($PSVersionTable.PSVersion.Major -eq 5 plus WildcardPattern::ContainsWildcardCharacters([Environment]::CurrentDirectory)) and recovers [Environment]::CurrentDirectory as the project root when the script was invoked directly. init-session.ps1 uses (Get-Location).Path without that recovery.

Suggested fix

Either port the recovery block from set-active-plan.ps1 to init-session.ps1 (same detection, same restriction to a direct -File invocation), or detect the condition and exit 1 with a message that names the limitation and suggests pwsh 7. Porting keeps the two scripts consistent and is the preferred route.

A regression test can create a temporary directory with brackets in its name, run the initializer under powershell.exe when present, and assert the planning files land in that directory.

Origin

Found by the v3.19.0 release review (PRs #247, #248, #249). Pre-existing behaviour. Tracked as item 4 of #250 before that issue was split into one issue per item.

Source: OthmanAdi/planning-with-files