• keh4l's avatar
    fix(gateway): always apply full mimicry for OAuth accounts regardless of client identity · 6dc89765
    keh4l authored
    Before: isClaudeCodeRequest() checked whether the client looks like a
    real Claude Code CLI (UA, system prompt, X-App header, metadata format).
    If it looked like Claude Code, all mimicry was skipped — the assumption
    being that a real CLI needs no help.
    
    Problem: third-party tools like opencode partially impersonate Claude
    Code (sending claude-cli UA + claude-code beta + CC system prompt) but
    miss critical details (billing attribution block, tool-name obfuscation,
    cache breakpoints, full beta set). Some users' opencode instances pass
    the isClaudeCodeRequest check, causing sub2api to skip mimicry entirely,
    while Anthropic still detects the request as third-party.
    
    This explains why 'same opencode version, some users work, some don't'
    — it depends on which opencode features/config trigger the validator.
    
    Fix: OAuth accounts now unconditionally run the full mimicry pipeline,
    matching Parrot's behavior (Parrot never checks client identity).
    This is safe because our mimicry is strictly more complete than any
    third-party client's partial impersonation.
    
    Changed:
      - /v1/messages path: remove isClaudeCode gate
      - /v1/messages/count_tokens path: same
    6dc89765
gateway_service.go 313 KB