BUG: Custom agent definitions fail with 'Not logged in' on OAuth (v2.1.81)
Bug Description
All custom agent definitions in ~/.claude/agents/definitions/*.md fail immediately with "Not logged in · Please run /login" when spawned as subagents. Built-in agents (general-purpose, Explore, Plan) work fine.
Environment
- Claude Code version: 2.1.81
- OS: macOS (Darwin 25.3.0)
- Auth method: OAuth (claude.ai subscription, no API key)
- Shell: zsh
Steps to Reproduce
- Create a custom agent definition at
~/.claude/agents/definitions/MyAgent.md:
---
name: MyAgent
description: Test agent
model: opus
---
Respond to prompts.
- Start a Claude Code session (OAuth authenticated)
- Spawn the custom agent:
Use the Agent tool with subagent_type: "MyAgent" and prompt: "Say hello"
- Result: Immediate failure — "Not logged in · Please run /login" with 0 tokens, 0 tool uses, ~50ms
- Spawn a built-in agent (
general-purpose) with same prompt → works fine
What Was Tested
| Agent Type | Definition | Result |
|-----------|-----------|--------|
| general-purpose | Built-in | ✅ Works (14k tokens) |
| general-purpose + model: opus | Built-in + override | ✅ Works |
| general-purpose + isolation: worktree | Built-in + override | ✅ Works |
| Architect | Custom .md (opus, worktree) | ❌ Fails (0 tokens) |
| Engineer | Custom .md (opus, worktree) | ❌ Fails (0 tokens) |
| Designer | Custom .md (opus) | ❌ Fails (0 tokens) |
| Algorithm | Custom .md | ❌ Fails (0 tokens) |
| Intern | Custom .md | ❌ Fails (0 tokens) |
Note: Engineer and Designer worked earlier in the same session but failed later, suggesting OAuth token propagation to custom agent subprocesses degrades over time. Built-in general-purpose continues to work throughout.
Expected Behavior
Custom agent definitions should authenticate using the same OAuth session as the parent process, just like built-in agents do.
Additional Context
- This worked reliably before (user reports it worked as recently as March 23, 2026)
- v2.1.81 (March 20) included an OAuth token race condition fix — this may have introduced a regression in how tokens are propagated to custom agent subprocesses
/loginin the parent session does not fix the issue for custom agents- Related issues: #16594 (hardcoded model names in built-ins), #20931 (custom agent loading)
- The
ANTHROPIC_API_KEYenv var is NOT set (pure OAuth auth) CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1is enabled in settings
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗