Repository navigation
Closed
Labels
bugSomething isn't working
Description
Summary
When running sequant run <issue>, the exec phase fails with "Claude Code process exited with code 1" after only 2-3 seconds, but invoking the same skill directly via claude -p "Run /exec <issue>" works perfectly.
Observed Behavior
npx sequant run 26starts successfully- Spec phase completes (1-2 minutes)
- Exec phase starts in worktree
- After ~2-3 seconds:
✗ exec: Claude Code process exited with code 1 - No additional error context provided
Expected Behavior
- Exec phase should complete successfully (like spec phase does)
- OR provide actionable error message explaining why it failed
Reproduction Steps
# 1. Run sequant for any issue
npx sequant run <issue-number>
# 2. Observe exec phase fails quickly with exit code 1
# 3. Try direct invocation in the same worktree
cd ../worktrees/feature/<branch>/
claude -p "Run /exec <issue>" --dangerously-skip-permissions
# 4. Direct invocation succeedsInvestigation Findings
What Works
claude -p "Run /exec 26" --dangerously-skip-permissionsin worktree ✅- Spec phase via SDK (runs in main repo) ✅
- Skills exist and are properly formatted in worktree ✅
What Fails
- Exec phase via SDK
query()call in worktree ❌
SDK Call Configuration (from run.ts)
const queryInstance = query({
prompt,
options: {
abortController,
cwd: worktreePath, // Exec runs in worktree
settingSources: ["project"],
systemPrompt: { type: "preset", preset: "claude_code" },
tools: { type: "preset", preset: "claude_code" },
permissionMode: "bypassPermissions",
allowDangerouslySkipPermissions: true,
env: {
SEQUANT_WORKTREE: worktreePath,
SEQUANT_ISSUE: String(issueNumber),
},
},
});Error Source
The error comes from @anthropic-ai/claude-agent-sdk/sdk.mjs:7850:
return new Error(`Claude Code process exited with code ${code}`);Root Cause Hypothesis
- SDK process spawning issue - Something about the worktree context causes the spawned process to fail
- Permission/settings issue - The SDK may not be loading settings correctly from worktree
- Environment variable issue - Custom env vars may conflict with SDK internals
- Skill loading issue - SDK may fail to load skill differently than direct CLI
Proposed Fix
- Add stderr/stdout capture before process exit for diagnostics
- Add pre-flight validation that SDK can initialize in the target cwd
- Consider falling back to direct
claudeCLI invocation if SDK fails
Workaround
Use direct CLI invocation instead of SDK:
cd <worktree-path>
claude -p "Run /exec <issue>" --dangerously-skip-permissionsImpact
- Severity: Medium (workaround exists)
- Frequency: 100% reproducible
- Affected:
sequant runwith worktree isolation (exec, test, qa phases)
Related
- Discovered during issue exec skill: Verify PR creation and report failures #26 implementation
- Spec phase (runs in main repo) works fine
- May be related to worktree-specific behavior
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
admarble commentedon Jan 9, 2026
Implementation Plan
Acceptance Criteria
Verification Methods
Implementation Steps
Phase 1: stderr capture (primary fix)
stderrcallback to SDKquery()options inexecutePhase()Phase 2: Pre-flight validation
4. Add
validateWorktreeReady()function to check:.claude/settings.local.jsonexists.claude/skills/directory has skill filesnode_modulesexistsPhase 3: CLI fallback (deferred)
6. Add optional
--fallback-to-cliflag for retry with directclaudecommandKey Decisions
--debug-sdkflagConsolidated Assumptions
options.stderrcallback receives stderr data before process exitsensureWorktree) copies all required filesRecommended Workflow
Phases:
exec → qaQuality Loop: disabled
Reasoning: Bug fix with clear root cause analysis. Implementation is straightforward SDK option changes.