fix(agent): strip Claude Code nesting env + plan mode + validate worktree branch - #6
Open
apex-skyner wants to merge 4 commits into
Open
fix(agent): strip Claude Code nesting env + plan mode + validate worktree branch#6apex-skyner wants to merge 4 commits into
apex-skyner wants to merge 4 commits into
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes three bugs that blocked autonomous Claude Code dispatch from the OpenClaw
openclaw-code-agentplugin, making the claw a fully functional autonomous dev agent.1. CLAUDECODE nesting guard — silent agent exit (closes #3)
session-manager.tsinheritedCLAUDECODE=1,CLAUDE_CODE_SESSION, andCLAUDE_CODE_ENTRYPOINTfrom the parent OpenClaw process. Claude Code checks these as a nesting guard and silently exits with code 0 — giving 0% success rate on allagent_launchcalls. 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)
"plan"toPermissionModeEnum; thedev-agent-routingskill documentspermission_mode: "plan"for gated autonomous dispatch but the plugin rejected it at the schema level."delegate"as alias for"auto"inWorktreeStrategyEnum; the skill usesworktree_strategy: "delegate"but only"auto"was accepted.worktree_pr_target_repooptional parameter (referenced in skill for fork workflows).auto/delegatestrategy is used without abranchparameter instead of silently running in the main workdir.3. Session memory prune + broken test + lint script (closes #4, closes #5)
SessionManagernow runs a background prune interval (1 h) to discard completed sessions older than 24 h — prevents unbounded memory growth in long-running gateway processes.index.test.tswhich was asserting["echo"]instead of the actual 7-tool list — it was always failing.lintandtypechecknpm scripts so the pre-commit policy gate works.Test plan
npm run lint— typecheck + vitest pass (2/2 green)npm run build— clean TypeScript compileagent_launchfrom within a Claude Code session and confirm Claude Code child process starts (not silently exits)worktree_strategy: "delegate"accepted and creates worktreepermission_mode: "plan"passes--permission-mode planto claude CLI🤖 Generated with Claude Code