[BUG] Background sessions don't load user agents from ~/.claude/agents/ into the Agent tool registry (related: #41973, #58353)
Preflight Checklist
- [x] I have searched existing issues — closest are #41973 (same symptom in
mcp servemode) and #58353 (samebgsession mode, different missing feature). This is the intersection —bgsessions specifically failing to load user agents. - [x] This is a single bug report.
- [x] I am using the latest version of Claude Code (2.1.140).
What's wrong
Background sessions (i.e. anything spawned by claude daemon / launched as a bg job from an interactive session or from FleetView) expose a different Agent-tool registry than the rest of Claude Code reports for the same user.
claude agentsfrom any shell correctly reports user agents in~/.claude/agents/(3 user + 5 built-in = 8 total).- Inside a bg session, attempting
subagent_type: "<user-agent-name>"via theAgenttool is rejected with:
```
Agent type 'utility-bot' not found. Available agents: claude, claude-code-guide, Explore, general-purpose, Plan, statusline-setup
claude agents
Note: the "Available agents" list is **different** from what reports — it includes claude-code-guide (not in claude agents`) and excludes all three user agents.
Effect: any bg-session work that should be routed to a user-defined model-specific agent (e.g. utility-bot → Haiku for docs, developer → Sonnet for code) silently falls back to general-purpose, which defaults to the main session's model (Opus in my case). Result: routine bg work runs on Opus when it should run on Haiku or Sonnet — quietly burning budget.
Hard evidence of the divergence
From the same shell, same user, same machine:
$ claude agents
8 active agents
User agents:
developer · sonnet
plan · opus
utility-bot · haiku
Built-in agents:
claude · inherit
Explore · haiku
general-purpose · inherit
Plan · inherit
statusline-setup · sonnet
From inside a bg session, attempting Agent with any user-agent name:
Agent type 'utility-bot' not found. Available agents: claude, claude-code-guide, Explore, general-purpose, Plan, statusline-setup
Differences:
- Bg session sees
claude-code-guide—claude agentsdoesn't list it. - Bg session does NOT see
developer,utility-bot,plan(the user agents).
What should happen
bg sessions should merge ~/.claude/agents/ into the Agent-tool runtime registry the same way interactive sessions do. If that's intentionally divergent for some reason, the behaviour should at least be documented and the claude agents CLI output should match what bg sessions actually see.
Workarounds tried (all failed)
settings.json:agentskey — REJECTED by schema validator:
```
Unrecognized field: agents. Check for typos or refer to the documentation for valid fields
additionalProperties: {}
The schema's top-level is overridden by a strict validator. Only agent` (singular, string) is accepted.
subagent_typeresolved by name only — confirmed deterministic rejection on every invocation. No retry/refresh path from inside the bg session.
--agents '<json>'— Per #41973 the same flag also fails to fix the analogous bug inmcp servemode. I have not personally retested forbg, but the user reports for #41973 align with the symptom.
Suggested fix
In the bg session-template boot path (the code that builds options.agentDefinitions.activeAgents), apply the same ~/.claude/agents/ + project .claude/agents/ discovery that claude agents and interactive sessions already use. The disk-level discovery clearly works (proven by claude agents); only the bg template's wiring of that discovery into the Agent tool resolver is missing.
Concrete repro
- Add
~/.claude/agents/utility-bot.md:
``markdown``
---
name: utility-bot
description: Fast, low-context tasks (commit messages, doc updates, formatting).
model: haiku
---
You are the Utility Bot...
- Confirm the CLI sees it:
claude agents→ showsutility-bot · haikuunder "User agents". - From an interactive session, spawn a bg session (any FleetView/slash flow that triggers
claude daemon run --origin transient). - In the bg session, call the
Agenttool withsubagent_type: "utility-bot". - Observe:
Agent type 'utility-bot' not found. Available agents: claude, claude-code-guide, Explore, general-purpose, Plan, statusline-setup.
Environment
- Claude Code Version: 2.1.140
- Platform: macOS (Darwin 25.5.0)
- Process tree: bg agent under
claude daemon ... --origin transient --spawned-by "slash" - state.json:
"template": "bg","sessionKind": "bg"in the session's JSONL records. - Env:
CLAUDECODE=1,CLAUDE_JOB_DIR=~/.claude/jobs/<id>.
Related
- #41973 — Same root cause class for
mcp servemode (also non-interactive, also strips user agents from the Agent-tool registry). - #58353 — Same
bgsession-mode environmental stripping, but for Claude.ai remote connectors instead of user agents. Strongly suggests the broader fix is "bg-template environment parity with interactive".
5 Comments
Found 1 possible duplicate issue:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Thanks for the report and the repro — confirmed. The agent loader had a catch-all that dropped everything (including your
~/.claude/agents/definitions) to built-ins-only if any sub-loader threw, and the plugin loader can throw in daemon-spawned workers. Fixed: each loader now fails independently, so a plugin-loader error no longer drops your custom agents.Ships in v2.1.142. Appreciate you linking #41973/#58353 — same init-path-gap class, helped narrow it fast.
The registry-divergence symptom + the budget-silent-burn consequence together is one of the more insidious failure modes I've seen in the Agent Teams surface. The fact that
claude agents(the diagnostic CLI) and the bg-session-resident Agent tool registry are reading from different sources means the operator's mental model and the runtime's behavior have diverged before any work even starts.This pairs unfortunately with #54018 and #54879 — both also "subagent dispatch silently degrades" patterns. Together they describe a category: the subagent runtime contract is not the same across spawn paths. Foreground/interactive sees one set of teammates,
claude daemonsees another, async-loop sees yet another. Operators who write fleet code against the foreground contract get a different runtime when they background-detach.For the "Opus when it should be Haiku" budget-burn part specifically: a
claude daemon-shape user's whole reason to define a Haiku-model utility-bot is cost containment for long-running async work. When the bg session silently falls back to the default-modelgeneral-purposeagent, the user is now paying ~10× per token for the exact workload they explicitly engineered around — and the only signal is the monthly bill.Two thoughts on hardening:
~/.claude/agents/, project-local, daemon-context, etc.) so the divergence is debuggable from a single error message rather than requiring aclaude agentscross-check.Subscribing — same shape of issue blocks any production fleet that splits work between interactive PM and background workers.
Addressed by a merged fix. Please reopen with a fresh repro if you still see this on a current version.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.