[BUG] --agent Flag Not Working for Non Interactive (Affects SDK)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
The --agent flag is silently ignored when Claude Code runs in non-interactive mode (using -p/--print flag or when stdin is not a TTY). The agent configuration (system prompt, tools restrictions, MCP servers) is not loaded into the context, even though the flag is accepted without error.
What Should Happen?
When using --agent <name> with -p or --print, Claude should load the agent's configuration from .claude/agents/<name>/<name>.md including:
- Agent system prompt
- Tool restrictions
- Model preferences
- MCP server configurations
The behavior should be consistent between interactive and non-interactive modes.
Error Messages/Logs
No error is shown - the flag is silently ignored.
Interactive mode (works - shows agent header):
claude --output-format stream-json --agent orchestrator --resume <session_id>
# Header shows: "orchestrator · /workspace"
Non-interactive mode (broken - agent not loaded):
claude --output-format=json --agent orchestrator --resume <session_id> -p "who are you?"
# Agent context NOT loaded, Claude reports:
# "No orchestrator-specific directions or workflow state loaded
claude --output-format=json --dangerously-skip-permissions --agent orchestrator --resume 4c344f22-3b5d-4cbe-b69f-3f05fbe7c892 -p "who are you again? Any changes?"
{"type":"result","subtype":"success","is_error":false,"duration_ms":11356,"duration_api_ms":13750,"num_turns":1,"result":"No changes. I'm still:\n\n- **Claude** (Opus 4.5) running as **Claude Code**\n- **Main agent** (not a subagent)\n- **Session ID**: `4c344f22-3b5d-4cbe-b69f-3f05fbe7c892`\n- **Context**: Standard Claude Code system prompt + CLAUDE.md (MCPJungle + code style) + git status\n\nSame as before. Nothing new has been injected into my context.","session_id":"4c344f22-3b5d-4cbe-b69f-3f05fbe7c892","total_cost_usd":0.15374875000000002,"usage":{"input_tokens":10,"cache_creation_input_tokens":21939,"cache_read_input_tokens":0,"output_tokens":252,"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":21939}},"modelUsage":{"claude-opus-4-5-20251101":{"inputTokens":1571,"outputTokens":351,"cacheReadInputTokens":0,"cacheCreationInputTokens":21939,"webSearchRequests":0,"costUSD":0.15374875000000002,"contextWindow":200000}},"permission_denials":[],"uuid":"75705afd-0d9d-42fc-8bb6-8900a119cda7"}
Steps to Reproduce
- Create an agent at .claude/agents/orchestrator/orchestrator.md with custom system prompt
- Start interactive session to get session_id:
claude --agent orchestrator -- "return your session_id" (you'll need to get the last transcript or have a hook injecting it)
- Resume with -p flag:
claude --agent orchestrator --resume <session_id> -p "do you have orchestrator directions loaded?"
- Expected: Agent reports having orchestrator context
- Actual: Agent reports no orchestrator-specific directions loaded
Additional context:
- Also affects --output-format stream-json without -p when stdin is piped (SDK usage)
- Version: Claude Code v2.0.76
Claude Model
None
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.0.76 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Non-interactive/CI environment
Additional Information
_No response_
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗