Last active
January 16, 2026 04:50
-
-
Save dai/4dbb3298b44b4e319137af236f9592d5 to your computer and use it in GitHub Desktop.
Resume Codex on Windows pwsh (PowerShell 7) Admin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Codex auto-resume (latest session) | |
| function Get-LatestCodexSessionId { | |
| $sessionsRoot = Join-Path $env:USERPROFILE ".codex\sessions" | |
| if (-not (Test-Path $sessionsRoot)) { | |
| return $null | |
| } | |
| $latest = Get-ChildItem -Path $sessionsRoot -Recurse -Filter "*.jsonl" | | |
| Sort-Object LastWriteTime -Descending | | |
| Select-Object -First 1 | |
| if (-not $latest) { | |
| return $null | |
| } | |
| if ($latest.Name -match '([0-9a-fA-F-]{36})\.jsonl$') { | |
| return $Matches[1] | |
| } | |
| return $null | |
| } | |
| if (-not $env:CODEX_AUTO_RESUME -or $env:CODEX_AUTO_RESUME -ne "0") { | |
| if (Get-Command codex -ErrorAction SilentlyContinue) { | |
| $latestSessionId = Get-LatestCodexSessionId | |
| if ($latestSessionId) { | |
| codex resume $latestSessionId | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment