[BUG] Deleted Agents Still Consume Tokens and Bloat Context Window
Resolved 💬 5 comments Opened Aug 2, 2025 by shawnsw Closed Jan 5, 2026
## Description
Agent definitions in the Task tool continue to consume significant context window space even after
the agent files are deleted from .claude/agents/. This causes unnecessary context window bloat and
degrades performance.
## Steps to Reproduce
- Start with 29 agents in
.claude/agents/folder - Delete/move most agent files (e.g., keep only 5 agents)
- Start a NEW Claude Code session
- Check context window usage - all 29 original agents still loaded
- Each deleted agent still consumes ~100-300 tokens in Task tool definition
## Impact
- Context Window Bloat: 15-20% of context window wasted on non-existent agents
- Performance: Performance degradation because of context window bloat
- Scalability: Adding more agents permanently increases context usage
## Expected Behavior
- Task tool should only load agents that exist in
.claude/agents/ - Deleted agents should free up context window space
- Context usage should scale with actual agent count
## Actual Behavior
- All historical agents remain in Task tool definition
- Context window permanently bloated with deleted agent descriptions
- No way to reclaim context space without modifying Claude Code itself
## Example
Current state:
- 5 agents in .claude/agents/ folder
- 29 agents in Task tool definition
- ~3,000 tokens wasted on 24 non-existent agents
- 20% of context window consumed by tools (should be ~5%)
## Suggested Solutions
- Dynamically generate Task tool from
.claude/agents/directory - Load agent definitions on-demand rather than persist
- Implement context window optimization for large codebases
- Add command to manually refresh/optimize tool definitions
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗