Skip to content

Add fork-session lane, /kill command, and auto-routing#20

Open
1872-svg wants to merge 3 commits intomoazbuilds:masterfrom
1872-svg:feature/fork-agent
Open

Add fork-session lane, /kill command, and auto-routing#20
1872-svg wants to merge 3 commits intomoazbuilds:masterfrom
1872-svg:feature/fork-agent

Conversation

@1872-svg
Copy link
Copy Markdown

Summary

  • Fork agent lane: /fork <prompt> spawns a parallel Claude session that doesn't touch the main session or queue. Useful for checking progress or asking quick questions while the main agent is running a long task.
  • /kill command: Terminates the currently running Claude subprocess immediately.
  • Auto-routing: When the main agent is busy, incoming messages are automatically routed to the fork lane instead of queuing behind the current task.
  • Fork agent uses Haiku model with a speed-focused system prompt — denies long tasks (compiling, downloads, fuzzing) and answers in 1-3 sentences.

How it works

runner.ts exports killActive(), isMainBusy(), and runFork(). The fork agent runs with --output-format json in a separate subprocess, bypassing the serial queue used by the main session.

In telegram.ts, handleMessage checks isMainBusy() before dispatching — busy → fork, idle → main session.

Test plan

  • Send a long-running prompt, then /fork what are you doing? — should get a fast response without interrupting the main task
  • Send a long-running prompt, then send another message mid-run — should be auto-routed to fork
  • /kill while a task is running — should terminate and confirm
  • /kill with nothing running — should report "No active agent running"

- /fork <prompt>: spawns a parallel lightweight watcher agent outside
  the main serial queue. Uses a dedicated system prompt that hard-denies
  long-running tasks (compilation, downloads, fuzzing) to keep it
  responsive for monitoring the main agent.
- /kill: sends SIGTERM to the active claude subprocess immediately.
- activeProc tracking in runClaudeOnce() enables kill to work from
  any handler without exposing the proc externally.
- Fork agent is given the session JSONL path so it can peek at main
  agent progress mid-task.
When the main serial queue is processing a task, new incoming messages
are automatically handled by the fork agent instead of queuing behind it.
This makes fork behavior transparent — users just chat normally without
needing to type /fork manually.

- Add mainRunning flag + isMainBusy() export in runner.ts
- telegram.ts checks isMainBusy() before dispatching and routes
  to runFork() if main is occupied
Hardcode FORK_MODEL to claude-haiku-4-5-20251001 — forks are meant
to be fast watchers, not reasoning agents. Add explicit speed
instructions to the system prompt: 1-3 sentences, no preamble,
no over-analysis.
@1872-svg 1872-svg force-pushed the feature/fork-agent branch from 8bb7ab8 to 0f1f920 Compare March 11, 2026 03:37
Fenrur added a commit to Fenrur/claudeclaw that referenced this pull request Mar 13, 2026
… and /kill command

From upstream PR moazbuilds#21 by 1872-svg (streaming + verbose) and PR moazbuilds#20 (fork agent).
- Streaming output via editMessageText for real-time response display
- /verbose command to show tool calls in Telegram
- /fork command for parallel lightweight agent using Haiku
- /kill command to terminate active agent
- Auto-routing to fork when main agent is busy
- Merged with additionalDirs (moazbuilds#13) and session corruption fix (moazbuilds#26)

Co-Authored-By: 1872-svg <1872-svg@users.noreply.github.com>
justmaker added a commit to justmaker/claudeclaw that referenced this pull request Mar 31, 2026
- 新增 tests/runner.test.ts(buildChildEnv、rate limit、security args、queue、timeout)
- 新增 tests/config.test.ts(resolvePrompt、parseSettings、Discord snowflake、exclude windows)
- 新增 tests/sessions.test.ts(session CRUD、turnCount、compactWarned、backup)
- package.json 新增 test script
- README 新增 Testing section(測試覆蓋範圍表格)
- 全部 178 tests 通過
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