[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

  1. Start with 29 agents in .claude/agents/ folder
  2. Delete/move most agent files (e.g., keep only 5 agents)
  3. Start a NEW Claude Code session
  4. Check context window usage - all 29 original agents still loaded
  5. 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

  1. Dynamically generate Task tool from .claude/agents/ directory
  2. Load agent definitions on-demand rather than persist
  3. Implement context window optimization for large codebases
  4. Add command to manually refresh/optimize tool definitions

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗