Feature request: Allow nested/recursive CLI calls for testing LLM applications
Use Case
When developing LLM-powered applications inside Claude Code, those applications often need to call Claude themselves (via CLI or API). Currently, if the application uses claude --print as its LLM provider, nested calls hang/return empty.
Example scenario:
- User is working in Claude Code on a research project
- The project has a
ClaudeCodeProviderclass that usesclaude --printto make LLM calls - User wants to test the project by running experiments
- Experiments fail because nested
claudeCLI calls don't work
Current Behavior
When running inside Claude Code (CLAUDECODE=1), calls to claude --print hang indefinitely and return empty. This happens even with:
--session-id <new-uuid>(fresh session)--no-session-persistence- Clearing all
CLAUDE*environment variables - Combinations of the above
Proposed Solution
Add an option to explicitly allow nested calls, such as:
claude --print --allow-nested "prompt here"
Or alternatively, make --no-session-persistence + --session-id work for isolated one-shot calls that don't interfere with the parent session.
Workaround
We implemented a fallback to use the direct Anthropic API when CLAUDECODE=1 is detected and ANTHROPIC_API_KEY is available. This works but:
- Requires an API key (defeats purpose of CLI-based workflow)
- Adds complexity to handle both paths
- Different behavior between development and production
Environment
- Claude Code version: 2.1.11 (VSCode extension)
- macOS Darwin 24.6.0
- Tested from both terminal and VSCode integrated terminal
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗