Skip to content

feat(agent): add Windows service management via PM2#38

Open
mikekidder wants to merge 2 commits intoearlyaidopters:mainfrom
mikekidder:feat/windows-pm2-support
Open

feat(agent): add Windows service management via PM2#38
mikekidder wants to merge 2 commits intoearlyaidopters:mainfrom
mikekidder:feat/windows-pm2-support

Conversation

@mikekidder
Copy link
Copy Markdown

@mikekidder mikekidder commented Apr 10, 2026

Summary

  • Adds Windows (win32) support to the agent service lifecycle using PM2 as the process manager, completing cross-platform coverage alongside macOS (launchd) and Linux (systemd)
  • New functions in agent-create.ts: generatePm2Config() creates an ecosystem.config.cjs, activatePm2() starts the agent via PM2, and the deactivate path stops/deletes the PM2 process
  • Adds a win32 branch in security.ts's emergency kill switch that runs pm2 kill to halt all ClaudeClaw services
  • activatePm2() now calls pm2-startup install to register a Windows boot hook so processes survive reboots. Logs a warning if the package is not installed

Prerequisites (Windows)

PM2 alone does not persist processes across reboots on Windows. Users need:

npm install -g pm2-windows-startup

The activation flow calls pm2-startup install automatically after pm2 save. If the package is missing, activation still succeeds but a warning is logged that reboot persistence is unavailable.

Test plan

  • On Windows, run npm run build to verify TypeScript compiles without errors
  • Create a new agent and confirm ecosystem.config.cjs is generated in PROJECT_ROOT with correct app name, script path, args, and log file paths
  • Activate the agent and verify pm2 list shows the process running with the expected claudeclaw-<agentId> name
  • Deactivate the agent and confirm it is stopped and removed from pm2 list, and that pm2 save persists the change
  • Verify pm2-startup install is called during activation and registers the Windows boot hook
  • Verify existing macOS (launchd) and Linux (systemd) paths are unaffected by the changes

🤖 Generated with Claude Code

mikekidder and others added 2 commits April 10, 2026 10:44
Adds win32 support to agent service lifecycle (create, activate,
deactivate) using PM2 as the process manager. Previously, only macOS
(launchd) and Linux (systemd) were supported, with Windows returning
an 'Unsupported platform' error.

Changes:
- agent-create.ts: generatePm2Config(), activatePm2(), deactivatePm2()
- security.ts: win32 branch in killSwitch() using pm2 kill

PM2 is commonly available on Windows via npm and provides reliable
process management with auto-restart, log rotation, and monitoring.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Calls pm2-startup install after pm2 save during Windows agent activation
so processes survive reboots. Logs a warning if pm2-windows-startup is
not installed globally.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant