Skip to content

fix(agent): strip Claude Code nesting env + plan mode + validate worktree branch - #6

Open
apex-skyner wants to merge 4 commits into
mainfrom
agent/fix-autonomous-dev
Open

fix(agent): strip Claude Code nesting env + plan mode + validate worktree branch#6
apex-skyner wants to merge 4 commits into
mainfrom
agent/fix-autonomous-dev

Conversation

@apex-skyner

Copy link
Copy Markdown
Contributor

Summary

Fixes three bugs that blocked autonomous Claude Code dispatch from the OpenClaw openclaw-code-agent plugin, making the claw a fully functional autonomous dev agent.

1. CLAUDECODE nesting guard — silent agent exit (closes #3)

session-manager.ts inherited CLAUDECODE=1, CLAUDE_CODE_SESSION, and CLAUDE_CODE_ENTRYPOINT from the parent OpenClaw process. Claude Code checks these as a nesting guard and silently exits with code 0 — giving 0% success rate on all agent_launch calls. Fix: explicitly delete these from the child env before spawning.

Related upstream issue: openclaw/openclaw#57858

2. plan permission mode + delegate worktree alias + missing parameter (closes #4, closes #5)

  • Added "plan" to PermissionModeEnum; the dev-agent-routing skill documents permission_mode: "plan" for gated autonomous dispatch but the plugin rejected it at the schema level.
  • Added "delegate" as alias for "auto" in WorktreeStrategyEnum; the skill uses worktree_strategy: "delegate" but only "auto" was accepted.
  • Added worktree_pr_target_repo optional parameter (referenced in skill for fork workflows).
  • Now returns an explicit error when auto/delegate strategy is used without a branch parameter instead of silently running in the main workdir.

3. Session memory prune + broken test + lint script (closes #4, closes #5)

  • SessionManager now runs a background prune interval (1 h) to discard completed sessions older than 24 h — prevents unbounded memory growth in long-running gateway processes.
  • Fixed index.test.ts which was asserting ["echo"] instead of the actual 7-tool list — it was always failing.
  • Added lint and typecheck npm scripts so the pre-commit policy gate works.

Test plan

  • npm run lint — typecheck + vitest pass (2/2 green)
  • npm run build — clean TypeScript compile
  • Integration: launch agent_launch from within a Claude Code session and confirm Claude Code child process starts (not silently exits)
  • Integration: worktree_strategy: "delegate" accepted and creates worktree
  • Integration: permission_mode: "plan" passes --permission-mode plan to claude CLI

🤖 Generated with Claude Code

apex-skyner and others added 4 commits June 26, 2026 07:27
… worktree branch #3 #4 #5

Fixes three bugs that prevented autonomous Claude Code dispatch:

1. **CLAUDECODE nesting guard (closes #3)** — `session-manager.ts` now strips
   `CLAUDECODE`, `CLAUDE_CODE_SESSION`, `CLAUDE_CODE_ENTRYPOINT`, and
   `CLAUDE_CODE_SKIP_TELEMETRY_CONFIRM` from the child process environment
   before spawning. Without this, Claude Code detects a nested session and
   silently exits, producing 0% agent success rate. Related: openclaw/openclaw#57858.

2. **plan permission mode + worktree_strategy alias (closes #4 + #5)** —
   - Added `"plan"` to `PermissionModeEnum`; passes `--permission-mode plan`
     to Claude Code for gated plan-approval workflows.
   - Added `"delegate"` to `WorktreeStrategyEnum` as alias for `"auto"`.
   - Added `worktree_pr_target_repo` optional parameter to `agent_launch`
     for fork-workflow PR routing.
   - Return error when `worktree_strategy` is `"auto"` or `"delegate"` but
     `branch` is not provided.

3. **Session memory prune + stale test + lint (closes #4)** — Added background
   prune interval (1 h) to remove sessions older than 24 h. Fixed `index.test.ts`
   to assert the correct 7-tool list instead of `["echo"]`. Added `lint` and
   `typecheck` npm scripts so the pre-commit hook can validate staged TS.

Co-authored-by: Yashiel Sookdeo <yashiel@skyner.co.za>
…ION #3

The real nesting marker in current Claude Code is CLAUDE_CODE_SESSION_ID
(with _ID suffix). CLAUDE_CODE_SESSION (without _ID) does not exist in the
process env of a running Claude Code child — the previous list stripped the
wrong variable and left the active nesting guard in place.

Updated CLAUDE_NESTING_VARS to:
- CLAUDECODE (primary nesting guard, still present)
- CLAUDE_CODE_ENTRYPOINT (present in current Claude Code)
- CLAUDE_CODE_SESSION_ID (the real session marker — was missing)
- CLAUDE_CODE_SESSION (kept as harmless no-op for future compat)
- CLAUDE_CODE_EXECPATH (present in current Claude Code)
- CLAUDE_CODE_TMPDIR (present in current Claude Code)

Source: openclaw/openclaw#87702 which verified the live child env keys.

Co-authored-by: Yashiel Sookdeo <yashiel@skyner.co.za>
Adds a minimal CI pipeline (ubuntu-latest, Node 22) that runs:
  npm run typecheck → npm test → npm run build

Validates PRs and pushes to main/agent/** branches.

Co-authored-by: Yashiel Sookdeo <yashiel@skyner.co.za>
…_stats; fix delegate auto-branch #4 #5

Three missing tools added (referenced in dev-agent-routing SKILL.md):

- agent_worktree_status: lists git worktrees with branch/commit/session lifecycle info
- agent_worktree_cleanup: removes ended worktrees; skip=running unless force=true
- agent_stats: per-status/harness session counts + total/avg runtime

delegate strategy auto-branch fix:
- `worktree_strategy: "delegate"` now auto-derives the branch as `agent/<session-name>`
  when no `branch` is provided — matching how the skill invokes agent_launch.
- `worktree_strategy: "auto"` still requires explicit `branch`.

Updated index.test.ts to assert all 10 tools.

Co-authored-by: Yashiel Sookdeo <yashiel@skyner.co.za>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant