Skip to content

Windows: agent detection fails (ps/lsof/pwdx/stat are Unix-only) #113

@hanker0x

Description

@hanker0x

Summary

On Windows, ai-devkit agent list always reports "No running agents detected" and prints 'ps' is not recognized as an internal or external command. Process/session detection in @ai-devkit/agent-manager is hard-coded to Unix tools that don't exist on Windows.

Environment

  • Windows 11 Pro (10.0.26200)
  • ai-devkit 0.42.0, @ai-devkit/agent-manager 0.20.0
  • Node v24.13.0
  • Claude Code 2.1.144 (native Windows binary -> runs as claude.exe)

Repro

  1. Run a Claude Code session on Windows (so there's a live claude.exe).
  2. ai-devkit agent list

Actual

'ps' is not recognized as an internal or external command,
operable program or batch file.
i No running agents detected.

(From Git Bash the MSYS ps is found but rejects the flags: ps: unknown option -- x.)

Expected

Running agents are listed, as on macOS/Linux.

Root cause

@ai-devkit/agent-manager/dist/utils/process.js:

  • listAgentProcesses() -> ps -axo pid=,ppid=,tty=,command=
  • batchGetProcessCwds() -> lsof -a -d cwd -Fn -p ..., fallback pwdx
  • batchGetProcessStartTimes() -> ps -o pid=,lstart= -p ...
  • getProcessTty() -> ps -p <pid> -o tty=

@ai-devkit/agent-manager/dist/utils/session.js:

  • batchGetSessionFileBirthtimes() -> stat -f / stat --format

None of these exist on Windows.

Suggested fix (verified working locally)

A process.platform === 'win32' branch in process.js is sufficient, because the authoritative PID-file path (~/.claude/sessions/<pid>.json) already supplies cwd, sessionId, and startedAt, so lsof/cwd isn't needed on Windows:

  • listAgentProcesses: enumerate via Get-CimInstance Win32_Process (ProcessId, ParentProcessId, ExecutablePath, CommandLine). Claude Code is claude.exe on Windows, so the existing exact-basename filter (=== 'claude.exe') matches unchanged. CommandLine preserves --resume <uuid>.
  • batchGetProcessStartTimes: ([DateTimeOffset]$_.CreationDate).ToUnixTimeMilliseconds().
  • batchGetProcessCwds: return empty on Windows (CIM doesn't expose process cwd). PID-file matching covers all interactive sessions; only the legacy CWD+birthtime fallback is unavailable.
  • getProcessTty: return '?' (no tty concept on Windows).
  • session.js batchGetSessionFileBirthtimes: replace stat with Node fs.statSync().birthtimeMs (cross-platform; removes the dependency entirely).

With this branch, agent list on Windows correctly lists agents, statuses, and "working on" summaries (matched via the PID files). Happy to open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions