feat: add RespawnController for automatic Claude Code session respawning

Implements an autonomous respawn loop that keeps Claude Code productive:
- Detects idle state by monitoring PTY for prompt character + timeout
- Sends configurable update prompt when idle (default: "update all the docs and CLAUDE.md")
- Executes /clear and /init to reset session
- Cycles automatically

New features:
- RespawnController class with state machine (watching → update → clear → init)
- REST API endpoints for respawn control (/api/sessions/:id/respawn/*)
- Web UI controls: toggle, prompt config, idle timeout settings
- SSE events for real-time respawn status updates
- Full CLAUDE.md template with Ralph Loop instructions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-18 07:31:19 +01:00
co-authored by Claude Opus 4.5
parent 46f97becc9
commit 675893111b
8 changed files with 2234 additions and 152 deletions
+18
View File
@@ -61,11 +61,23 @@ export interface AppState {
config: AppConfig;
}
export interface RespawnConfig {
/** How long to wait after seeing prompt before considering truly idle (ms) */
idleTimeoutMs: number;
/** The prompt to send for updating docs */
updatePrompt: string;
/** Delay between sending steps (ms) */
interStepDelayMs: number;
/** Whether to enable respawn loop */
enabled: boolean;
}
export interface AppConfig {
pollIntervalMs: number;
defaultTimeoutMs: number;
maxConcurrentSessions: number;
stateFilePath: string;
respawn: RespawnConfig;
}
export interface SessionOutput {
@@ -85,6 +97,12 @@ export const DEFAULT_CONFIG: AppConfig = {
defaultTimeoutMs: 300000, // 5 minutes
maxConcurrentSessions: 5,
stateFilePath: '',
respawn: {
idleTimeoutMs: 5000, // 5 seconds of no activity after prompt
updatePrompt: 'update all the docs and CLAUDE.md',
interStepDelayMs: 1000, // 1 second between steps
enabled: true,
},
};
export function createInitialState(): AppState {