Skip to content

Instantly share code, notes, and snippets.

@dai
Last active January 16, 2026 04:50
Show Gist options
  • Select an option

  • Save dai/4dbb3298b44b4e319137af236f9592d5 to your computer and use it in GitHub Desktop.

Select an option

Save dai/4dbb3298b44b4e319137af236f9592d5 to your computer and use it in GitHub Desktop.
Resume Codex on Windows pwsh (PowerShell 7) Admin.
# 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