[BUG] Compaction is broken in the CC SDK
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?
/compact and auto-compaction no longer work on CC SDK v2.0.17. They fail with the following error:
[ERROR] Error: Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"This credential is only authorized for use with Claude Code and cannot be used for other API requests."},"request_id":"req_011CU9VQuTnSY4cWnorF9wrD"}
What Should Happen?
/compact should compact the conversation and allow me to continue on a new session with a fresh context window that includes the compaction summary of the my conversation so far.
You can see in our logs below that our UserPromptSubmit hook runs _after_ the API request fails, which is weird. It's like just the text /compact alone causes the failure.
Error Messages/Logs
[2025-10-15T18:53:41.979Z] [CC-SDK-STDERR]: [ERROR] Error: Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"This credential is only authorized for use with Claude Code and cannot be used for other API requests."},"request_id":"req_011CU9VQuTnSY4cWnorF9wrD"}
at generate (/$bunfs/root/claude:199:83027)
at makeRequest (/$bunfs/root/claude:353:5345)
at processTicksAndRejections (native:7:39)
[2025-10-15T18:53:43.313Z] [2f2a5756-7075-469a-8a83-476048f131f2/1760554420945] Committing with lastAssistantMessageId: start
[2025-10-15T18:53:43.570Z] [2f2a5756-7075-469a-8a83-476048f131f2/1760554420945] Created checkpoint with commit message: conductor-checkpoint-start
[2025-10-15T18:53:45.655Z] [CC-SDK-STDERR]: [ERROR] "Error: Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"This credential is only authorized for use with Claude Code and cannot be used for other API requests.\"},\"request_id\":\"req_011CU9VRBZf64SwCKMNQYxbb\"}\n at generate (/$bunfs/root/claude:199:83027)\n at makeRequest (/$bunfs/root/claude:353:5345)\n at processTicksAndRejections (native:7:39)"
[2025-10-15T18:53:45.936Z] [CC-SDK-STDERR]: [ERROR] "Error: Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"This credential is only authorized for use with Claude Code and cannot be used for other API requests.\"},\"request_id\":\"req_011CU9VRCF5sZTzH7YMidgmf\"}\n at generate (/$bunfs/root/claude:199:83027)\n at makeRequest (/$bunfs/root/claude:353:5345)\n at processTicksAndRejections (native:7:39)"
[2025-10-15T18:53:57.297Z] [CC-SDK-STDERR]: [ERROR] "Error: Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"This credential is only authorized for use with Claude Code and cannot be used for other API requests.\"},\"request_id\":\"req_011CU9VS3EP7iGjYc96oFMwz\"}\n at generate (/$bunfs/root/claude:199:83027)\n at makeRequest (/$bunfs/root/claude:353:5345)\n at processTicksAndRejections (native:7:39)"
Steps to Reproduce
- Using the Claude Code SDK v2.0.17, send a message like "2 + 2"
- Send another message like
/compact. You should now see the error log in stderr. - Send another message asking "what we've discussed so far", and Claude Code will have no memory of the first question asked.
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.0.0
Claude Code Version
2.0.17
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Non-interactive/CI environment
Additional Information
FWIW, we only tested this on 2.0.0 (working fine) and 2.0.17 (failing). We're not certain exactly when this bug was introduced.
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗