Project custom agents (.claude/agents/) become unavailable to Agent tool after /compact, in same session, no worktree transition

Status Open
Reported on v2.1.224
Maintainer reply None cached
Activity 1 comment · opened Aug 19, 2026

Summary

Project-level custom agents (.claude/agents/*.md) that were successfully dispatched earlier in a session become unavailable to the Agent/Task tool immediately after a /compact context-compaction cycle, with no restart or EnterWorktree/ExitWorktree transition involved. Agent(subagent_type: <custom>) fails with "Agent type not found," listing only built-in types.

Environment

  • Claude Code CLI 2.1.224
  • macOS 26.5.1 (Darwin 25.5.0)
  • Session's cwd is a git worktree checkout (git worktree add-created, not entered mid-session via EnterWorktree) — .claude/agents/*.md present in that checkout from before session start
  • 7 custom project agents defined under .claude/agents/, valid YAML frontmatter (name, description, tools, model)

Reproduction

  1. Start a session with cwd already inside a git worktree containing .claude/agents/*.md.
  2. Successfully dispatch several of the custom agent types via Agent(subagent_type: "<custom-name>") — confirmed working, results returned normally.
  3. Run /compact (user-invoked, not auto-compaction) to reduce context size, intending to continue in the same session afterward.
  4. After compaction completes, dispatch the same custom agent type again by the same name.

Expected

Per docs (code.claude.com/docs/en/sub-agents): agent definitions are stored separately from conversation history, and compaction operates only on message history — so the same custom agents used successfully pre-compact should remain dispatchable post-compact in the same session.

Actual

Agent tool call fails: Agent type '<name>' not found. Available agents: claude, claude-code-guide, Explore, general-purpose, Plan, statusline-setup — every one of the 7 project-defined agents is gone from the registry, despite the files being unchanged on disk and having worked moments before compaction.

Notes

  • No EnterWorktree/ExitWorktree occurred in this session — cwd was rooted in the worktree from session start, which rules out the specific mechanism in #73387 (though the failure signature — same error message format, same "only built-ins visible" symptom — looks related and may share a root cause: whatever cwd/registry cache /compact rebuilds context from is not re-walking .claude/agents/).
  • Distinct from #23620 (agent-team state lost on compaction) — no CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS in use here; this is plain project subagent dispatch via the Agent tool.
  • Did not test whether waiting ~15 min (the self-heal window reported in #73387) resolves it in this case, or whether claude --resume reloads the registry without losing conversation state — both worth a maintainer/reporter follow-up.

Impact

Any long session that relies on /compact to manage context length loses access to project-specific subagents afterward, silently pushing toward built-in fallback agents that don't carry the task-specific tool restrictions/model choice/instructions the custom agents were defined for — defeating the purpose of having them.

Possibly related: #73387, #23620

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗