deepseek-ai / deepseek-ai/awesome-deepseek-agent
Claude Code with DeepSeek Anthropic-compatible API fails during project analysis: Invalid user_id
- Dominant language
- No language data
- Stars
- 6.1k
- Forks
- 724
- PR merge metrics
- No merged PRs in 30d
Description
## Description
I encountered a compatibility issue when using Claude Code with DeepSeek's Anthropic-compatible API endpoint.
Claude Code can start successfully, and it works in a clean empty directory. However, when I run it inside a real project directory and ask it to read or analyse the codebase, it starts by searching/listing files and then fails during a subsequent API request with the following error:
```text
API Error: 400 Invalid 'user_id': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'.
```
Environment
Tool: Claude Code
API endpoint: https://api.deepseek.com/anthropic
Model: deepseek-v4-pro[1m]
OS: macOS
Usage scenario: Claude Code project-level code analysis
My environment variables are configured as follows:
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=sk-xxxx
export ANTHROPIC_MODEL='deepseek-v4-pro[1m]'
export ANTHROPIC_DEFAULT_OPUS_MODEL='deepseek-v4-pro[1m]'
export ANTHROPIC_DEFAULT_SONNET_MODEL='deepseek-v4-pro[1m]'
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v4-flash
I also previously tested with:
export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-v4-flash
export CLAUDE_CODE_EFFORT_LEVEL=max
But the issue still appears after disabling these two variables.
Steps to reproduce
Configure Claude Code to use DeepSeek's Anthropic-compatible endpoint.
Run Claude Code in a clean empty directory.
It starts successfully.
Run Claude Code inside an actual code project.
Ask Claude Code to read or analyse the project code, for example:
Please read this codebase and explain how it works.
Claude Code starts file search/listing operations.
The request then fails with:
API Error: 400 Invalid 'user_id': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'.
What I have already tried
I have tried the following:
Cleared global Claude Code configuration and cache.
Removed local project-level .claude configuration.
Removed .mcp.json and mcp-server.json.
Disabled Claude Code plugins.
Disabled MCP-related configuration.
Removed Claude Code backups and old project history.
Tested in a clean directory, where Claude Code can start successfully.
Tested again in the real project directory, where the error happens during codebase analysis.
Because the clean directory works but project-level analysis fails, it seems that the issue may be triggered by the request generated during Claude Code's tool/codebase workflow.
Expected behaviour
Claude Code should be able to continue project-level code analysis through DeepSeek's Anthropic-compatible endpoint without the Invalid user_id error.
Actual behaviour
Claude Code starts normally, performs some file search/listing operations, and then the API request fails with a 400 error:
Invalid 'user_id': string does not match pattern.
Possible cause
This may be related to how the DeepSeek Anthropic-compatible endpoint handles Claude Code requests involving tool calls, project context, session metadata, or user identification fields.
The error message mentions user_id, but I could not find any invalid user_id in my local Claude Code configuration. It is possible that some field generated by Claude Code during project analysis is being interpreted or validated as user_id by the compatibility layer.
Related reference
There is a similar Claude Code issue where invalid tool/MCP names caused a pattern validation error:
[https://github.com/anthropics/claude-code/issues/858](https://github.com/anthropics/claude-code/issues/858?utm_source=chatgpt.com)
Although my error is shown as user_id, the behaviour seems similar in that a field generated during Claude Code execution may not match the expected pattern.
Request
Could you please confirm whether DeepSeek's Anthropic-compatible API fully supports the current Claude Code request format, especially during project-level code analysis involving tool calls?
If this is a known compatibility issue, could you provide a recommended workaround, such as:
a specific Claude Code version,
a recommended DeepSeek model setting,
environment variables to disable certain Claude Code features,
or guidance on which request fields need to be sanitised?
Thank you.
Contributor guide
Assessment
This issue has not been assessed yet.