[Bug] /compact and auto-compact fail with 'Tool names must be unique' when MCP servers are configured
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
The /compact command and auto-compact fail with "Tool names must be unique" error when MCP servers are configured. This prevents conversation compaction entirely, leaving long sessions unrecoverable.
This appears to be related to #10704 and #10668 (Task tool/subagent failures with same error), but manifests specifically during compaction operations.
Error Messages/Logs
Error during compaction: Error: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"tools: Tool names must be unique."},"request_id":"req_..."}
Stack trace from debug logs:
[DEBUG] Getting matching hook commands for PreCompact with query: auto
[DEBUG] Found 0 hook matchers in settings
[DEBUG] Matched 0 unique hooks for query "auto" (0 before deduplication)
[ERROR] Error streaming, falling back to non-streaming mode: 400 {"type":"error","error":{"type":"invalid_request_error","message":"tools: Tool names must be unique."}}
[ERROR] Error in non-streaming fallback: 400 {"type":"error","error":{"type":"invalid_request_error","message":"tools: Tool names must be unique."}}
[ERROR] Error: Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"tools: Tool names must be unique."}}
at B9.generate (cli.js:459:10797)
at q_.makeStatusError (cli.js:796:2195)
at q_.makeRequest (cli.js:796:5419)
What Should Happen?
The /compact command should successfully compress the conversation history regardless of MCP server configuration.
Steps to Reproduce
- Configure multiple MCP servers (see configuration below)
- Have an extended conversation that triggers auto-compact or run
/compact - Observe the error: "Error during compaction: Error: API Error: 400 ... tools: Tool names must be unique"
MCP Server Configuration
{
"mcpServers": {
"vercel": {
"type": "http",
"url": "https://mcp.vercel.com"
},
"playwright": {
"type": "stdio",
"command": "npx",
"args": ["@playwright/mcp@latest"]
},
"stripe": {
"type": "http",
"url": "https://mcp.stripe.com/"
},
"shadcn": {
"type": "stdio",
"command": "npx",
"args": ["shadcn@latest", "mcp"]
},
"context7": {
"type": "http",
"url": "https://mcp.context7.com/mcp"
}
}
}
Root Cause Analysis
The compaction API call appears to include tool definitions that get duplicated somewhere in the process. This is the same root cause as #10704 (Task tool failures) but affecting the compaction code path.
The error occurs during PreCompact hook processing, suggesting tool definitions are being assembled for the compaction API call and contain duplicates.
Claude Model
claude-opus-4-5-20251101
Is this a regression?
Unknown - first encountered on v2.0.70
Claude Code Version
2.0.70
Platform
Anthropic API
Operating System
macOS 15.6.1 (Darwin 24.6.0)
Terminal/Shell
VS Code integrated terminal
Related Issues
- #10704 - Subagent launch fails with 'Tool names must be unique' when MCP server is configured
- #10668 - Task agent fails with 'tools: Tool names must be unique' when parent has many MCP tools
- #7530 - Error during compaction (general compaction failures)
Workaround
Start a new session. The compaction failure means the current session's context cannot be reduced.
This issue has 15 comments on GitHub. Read the full discussion on GitHub ↗