[FEATURE] Support nested claude -p calls from custom slash commands without nested session error
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
What problem does this solve:
When a custom slash command (e.g. /review) triggers a shell script that calls claude -p internally, Claude Code blocks it with: "Claude Code cannot be launched inside another Claude Code session." This makes it impossible to use headless Claude pipelines as slash commands.
What I expected:
/review would run my review_and_commit.sh pipeline which uses claude -p for automated code review and bug fixing.
What happened:
The nested session check blocked the inner claude -p calls, causing the pipeline to abort.
Proposed Solution
Suggested solution:
Either automatically unset the CLAUDECODE environment variable when running slash command shell scripts, add a --allow-nested flag for headless calls, or add clear documentation showing the recommended pattern for slash commands that use claude -p.
Environment:
Claude Code v2.1.70
macOS
Claude Pro subscription
Alternative Solutions
_No response_
Priority
Low - Nice to have
Feature Category
CLI commands and flags
Use Case Example
_No response_
Additional Context
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗