šŸ¤– AI Tools
Ā· 9 min read

How to Use Qwen 3.7 with Claude Code (Cross-Harness Setup Guide)


Qwen 3.7 supports the Anthropic API protocol natively. This means you can use it as a drop-in backend for Claude Code without any adapters, proxies, or protocol translation layers. The model speaks the same API language that Claude Code expects, including tool use, streaming, and multi-turn conversations.

This is not a hack or workaround. Alibaba built Anthropic API compatibility directly into Qwen 3.7’s serving infrastructure. The model handles Anthropic-format tool calls, system prompts, and response structures natively.

This guide walks through the complete setup: how cross-harness works, configuring Claude Code to use Qwen 3.7 via OpenRouter or the direct API, testing your setup, optimizing performance, and working around known limitations.

For general Qwen 3.7 information, see our Qwen 3.7 complete guide. For Claude Code basics, check How to use Claude Code.

What is cross-harness compatibility?

Cross-harness means a model implements another provider’s API protocol. Qwen 3.7 implements the Anthropic Messages API, which is the protocol Claude Code uses to communicate with its backend model.

When Claude Code sends a request, it expects:

  • Anthropic-format message structure (system prompt separate from messages)
  • Anthropic-format tool use (tool definitions, tool_use content blocks, tool_result responses)
  • Anthropic-format streaming (server-sent events with specific event types)

Qwen 3.7 handles all of these natively. From Claude Code’s perspective, it is talking to an Anthropic-compatible endpoint. It does not know or care that the model behind the endpoint is Qwen.

This matters because Claude Code is one of the best agentic coding tools available, but it normally requires a Claude model. Cross-harness compatibility lets you use Claude Code’s excellent interface and tooling with Qwen 3.7’s capabilities and pricing.

Prerequisites

Before starting, you need:

  1. Claude Code installed (see How to use Claude Code if you have not set it up)
  2. An API key from either:
    • OpenRouter (easiest, recommended for getting started)
    • Alibaba’s Aliyun BaiLian API (direct, potentially lower latency)
  3. A terminal with Claude Code accessible

OpenRouter acts as a unified gateway that routes requests to Qwen 3.7’s Anthropic-compatible endpoint. This is the easiest setup because OpenRouter handles the protocol routing for you.

Step 1: Get your OpenRouter API key

Sign up at openrouter.ai and generate an API key from the dashboard. Add credits to your account (Qwen 3.7 Max is $2.50/$7.50 per million tokens through OpenRouter).

Step 2: Configure Claude Code

Set the environment variables that tell Claude Code to use OpenRouter instead of the default Anthropic endpoint:

export ANTHROPIC_BASE_URL="https://openrouter.ai/api/v1"
export ANTHROPIC_API_KEY="sk-or-v1-your-openrouter-key"
export ANTHROPIC_MODEL="qwen/qwen-3.7-max"

Add these to your shell profile (~/.bashrc, ~/.zshrc, or equivalent) to persist them across sessions:

# ~/.zshrc or ~/.bashrc
export ANTHROPIC_BASE_URL="https://openrouter.ai/api/v1"
export ANTHROPIC_API_KEY="sk-or-v1-your-openrouter-key"
export ANTHROPIC_MODEL="qwen/qwen-3.7-max"

Step 3: Verify the connection

Open a new terminal and launch Claude Code:

claude

Run a simple test to confirm Qwen 3.7 is responding:

> What model are you? Respond with your exact model identifier.

The response should indicate Qwen 3.7 rather than Claude. If you see a Claude response, your environment variables are not being picked up. Check that you sourced your shell profile or opened a new terminal.

Step 4: Test tool use

Claude Code’s power comes from tool use (file reading, writing, command execution). Test that tools work correctly:

> Read the contents of package.json and tell me what dependencies are installed.

If the model successfully reads the file and reports the contents, tool use is working. If you get errors about tool calls failing, check the troubleshooting section below.

Method 2: Direct Aliyun API

For lower latency and direct access without a middleman, you can point Claude Code directly at Alibaba’s API endpoint.

Step 1: Get your Aliyun API key

Sign up for the Aliyun BaiLian platform and generate an API key. You will need to add payment information and may need to verify your identity depending on your region.

Step 2: Configure Claude Code

export ANTHROPIC_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
export ANTHROPIC_API_KEY="sk-your-aliyun-api-key"
export ANTHROPIC_MODEL="qwen-3.7-max"

Step 3: Verify and test

Same verification steps as Method 1. The direct API may have slightly lower latency since requests do not route through OpenRouter’s infrastructure.

Configuration tips

Optimizing for long sessions

Qwen 3.7 Max supports 35-hour autonomous sessions with 1,158 tool calls. To take advantage of this in Claude Code:

# Increase timeout for long-running operations
export ANTHROPIC_TIMEOUT=600  # 10 minutes per request

# Enable extended context
export ANTHROPIC_MAX_TOKENS=65536

Note: Verify these environment variables work with your version of Claude Code, as configuration options may change between releases.

Using Qwen 3.7 Plus instead

If you need vision capabilities (processing screenshots, diagrams), switch to Plus:

# OpenRouter
export ANTHROPIC_MODEL="qwen/qwen-3.7-plus"

# Direct API
export ANTHROPIC_MODEL="qwen-3.7-plus"

Note that Plus has a lower max output (32,768 tokens) and slightly lower agent performance. Use Max for pure coding tasks.

Switching between models

Create shell aliases to quickly switch between Qwen 3.7 and Claude:

# ~/.zshrc
alias claude-qwen='export ANTHROPIC_BASE_URL="https://openrouter.ai/api/v1" && export ANTHROPIC_API_KEY="sk-or-v1-your-key" && export ANTHROPIC_MODEL="qwen/qwen-3.7-max" && claude'

alias claude-default='unset ANTHROPIC_BASE_URL && export ANTHROPIC_API_KEY="sk-ant-your-anthropic-key" && unset ANTHROPIC_MODEL && claude'

Now you can run claude-qwen for Qwen 3.7 or claude-default for standard Claude.

Testing your setup

Run these tests to confirm everything works correctly:

Test 1: Basic response

> Explain what a mutex is in one paragraph.

Expected: A clear, technical explanation. If you get an error, your API key or base URL is wrong.

Test 2: File operations

> List all files in the current directory and count them.

Expected: The model uses the ls tool or file listing tool and reports results. If tools fail, the Anthropic protocol compatibility may not be working correctly.

Test 3: Multi-step task

> Create a new file called test-qwen.txt with the content "Hello from Qwen 3.7", then read it back to confirm it was written correctly, then delete it.

Expected: Three sequential tool calls (write, read, delete) all succeeding. This tests multi-turn tool use which is critical for agentic workflows.

Test 4: Code generation

> Write a Python function that implements binary search, save it to binary_search.py, then write a test file that verifies it works.

Expected: Multiple file writes with working code. This tests the model’s coding ability within the Claude Code harness.

Performance considerations

Latency

Qwen 3.7 via OpenRouter adds one network hop compared to direct Anthropic API calls. Expect:

  • Time-to-first-token: 1-3 seconds (vs ~0.5s for Claude direct)
  • Streaming throughput: comparable once streaming starts
  • Direct Aliyun API: slightly faster than OpenRouter

For interactive coding sessions, the latency difference is noticeable but not disruptive. For long autonomous sessions, it is irrelevant since the model spends most of its time thinking, not waiting for network.

Cost comparison

Using Qwen 3.7 Max through Claude Code vs using Claude Sonnet:

ModelInputOutputTypical session cost
Claude Sonnet 4.6$3.00/1M$15.00/1M~$1.50
Qwen 3.7 Max$2.50/1M$7.50/1M~$0.95
Qwen 3.7 Plus$1.50/1M$4.50/1M~$0.60

Qwen 3.7 Max is cheaper than Claude Sonnet on output tokens (where most cost accumulates in agentic workflows), making it a cost-effective alternative for heavy Claude Code usage.

Context window advantage

Qwen 3.7’s 1M token context window is significantly larger than Claude’s 200K. In Claude Code, this means:

  • Larger codebases can fit in context without truncation
  • Longer conversation histories before context is lost
  • More tool call results can be retained in memory

For large monorepo work, this is a meaningful advantage.

Known limitations

What works well

  • Standard tool use (file read/write, command execution)
  • Multi-turn conversations with tool results
  • Streaming responses
  • System prompts and instructions
  • Long context sessions

What may have issues

  • Computer use tools: Claude Code’s computer use features (screenshot, mouse, keyboard) may not work perfectly since they rely on Claude-specific tool schemas
  • Caching: Anthropic’s prompt caching protocol may not be supported, meaning you pay full input price on every turn
  • Rate limits: OpenRouter and Aliyun have different rate limits than Anthropic. High-frequency tool calls may hit limits sooner
  • Model-specific behaviors: Some Claude Code features may rely on Claude-specific response patterns that Qwen handles differently

Workarounds

If you hit tool use issues, try adding explicit instructions in your first message:

> Before we start: you have access to tools for reading files, writing files, and executing commands. Use them proactively. Do not ask for permission before using tools.

This helps Qwen 3.7 match the proactive tool-use behavior that Claude Code expects.

Troubleshooting

ā€Authentication failedā€ error

Your API key is wrong or expired. Verify:

# Test OpenRouter key
curl https://openrouter.ai/api/v1/models \
  -H "Authorization: Bearer sk-or-v1-your-key"

ā€œModel not foundā€ error

Check the model identifier. OpenRouter uses qwen/qwen-3.7-max, while the direct API uses qwen-3.7-max. These are different strings.

Tools not working

If the model responds with text instead of using tools, the Anthropic protocol may not be routing correctly. Verify your ANTHROPIC_BASE_URL is set and that you are using the correct endpoint path.

Slow responses

If responses are very slow (>10 seconds to first token):

  1. Check your network connection to the API endpoint
  2. Try switching between OpenRouter and direct API
  3. Check if the provider is experiencing high load (OpenRouter shows status on their dashboard)

Context getting truncated

If the model seems to forget earlier parts of the conversation, you may be hitting context limits. Qwen 3.7 supports 1M tokens, but OpenRouter may impose lower limits. Check your provider’s documentation for context window limits on the specific model.

FAQ

Does Qwen 3.7 really work with Claude Code?

Yes. Qwen 3.7 implements the Anthropic Messages API protocol natively, including tool use, streaming, and multi-turn conversations. It works as a drop-in backend for Claude Code without any adapters or proxies.

Is this officially supported by Anthropic?

No. This uses Claude Code’s ability to point at alternative API endpoints. Anthropic does not officially support or endorse using non-Claude models with Claude Code. It works because the protocol is the same, but you will not get support from Anthropic if something breaks.

Which is better for Claude Code: Qwen 3.7 Max or Plus?

Max. Claude Code is a text-based terminal tool, so Plus’s vision capabilities are not useful here. Max has better agent performance (Terminal-Bench Hard 50.8% vs 42.3%) and a longer output window (65K vs 32K tokens).

How does Qwen 3.7 in Claude Code compare to actual Claude?

Qwen 3.7 Max scores 56.6 on the Intelligence Index and 50.8% on Terminal-Bench Hard. Claude Sonnet 4.6 scores approximately 54.2 and 48.1% respectively. Qwen 3.7 Max is competitive with or slightly ahead of Claude Sonnet for agentic coding tasks, at a lower output token price.

Can I use Qwen 3.7 with other Anthropic-ecosystem tools?

Yes. Any tool that uses the Anthropic Messages API can potentially work with Qwen 3.7. This includes custom agents built with the Anthropic SDK, tools that support configurable API endpoints, and other harnesses that speak the Anthropic protocol.

Will my Claude Code settings and CLAUDE.md files still work?

Yes. CLAUDE.md files, project settings, and custom instructions are processed by Claude Code before being sent to the model. They work regardless of which model is behind the API endpoint.

Is there any data privacy concern with routing through OpenRouter?

OpenRouter processes your requests to route them to the correct provider. If data privacy is a concern, use the direct Aliyun API endpoint instead. Review OpenRouter’s privacy policy and Alibaba’s data handling practices for your specific compliance requirements.

Related: Qwen 3.7 Complete Guide Ā· How to Use Claude Code Ā· How to Use Qwen 3.7 API Ā· OpenRouter Complete Guide