Skip to content

fix: allow claude CLI provider to run inside Claude Code sessions#135

Closed
Leeaandrob wants to merge 3 commits intosipeed:mainfrom
Leeaandrob:fix/claude-cli-nesting
Closed

fix: allow claude CLI provider to run inside Claude Code sessions#135
Leeaandrob wants to merge 3 commits intosipeed:mainfrom
Leeaandrob:fix/claude-cli-nesting

Conversation

@Leeaandrob
Copy link
Collaborator

Summary

  • Remove CLAUDECODE env var from subprocess environment so Claude Code can be invoked as a subprocess from PicoClaw (or from within another Claude Code session)
  • Parse stdout before checking exit code to handle stderr diagnostic noise without losing valid JSON output (same resilience pattern applied to codex CLI provider in feat: add Codex CLI provider for subprocess integration #80)

Problem

When PicoClaw's claude-cli provider is used inside a Claude Code session (or any environment where CLAUDECODE is set), the subprocess fails with:

Error: Claude Code cannot be launched inside another Claude Code session.

Additionally, if Claude Code writes diagnostic messages to stderr, the non-zero exit code would cause the provider to return an error even when valid JSON output exists on stdout.

Changes

  • pkg/providers/claude_cli_provider.go: Filter out CLAUDECODE env var + stdout-first parsing

Test plan

  • All existing unit tests pass (go test ./pkg/providers/... -run Claude)
  • gofmt and go vet clean
  • Manually tested: PicoClaw → claude-cli → Claude Code → Context7 MCP → valid response

Remove CLAUDECODE env var from subprocess environment to allow nesting.
Also parse stdout before checking exit code to handle stderr diagnostic
noise without losing valid JSON output (same pattern as codex provider).
Remove trailing whitespace and extra newlines flagged by CI fmt-check.
Upstream refactored NewWebSearchTool to accept WebSearchToolOptions
struct instead of positional args. Update config_test.go and
web_test.go to match the new API.
@Leeaandrob
Copy link
Collaborator Author

Closing this PR — the fixes here (CLAUDECODE env var removal + stderr resilience) will be included in an upcoming larger PR that refactors the CLI provider architecture entirely.

The new PR will:

  • Replace claude_cli_provider.go with a unified cli_runner.go that handles both Claude CLI and Codex CLI
  • Add proper --session-id + --resume support
  • Add execution serialization queue
  • Add clearEnv support (which covers the CLAUDECODE fix from this PR)
  • Add image pipeline for CLI providers

All changes from this PR are preserved in the new implementation.

@Leeaandrob Leeaandrob closed this Feb 13, 2026
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