Skip to content

feat: add Qwen Code adapter with Windows Bun detection#342

Closed
btxbtxbtx wants to merge 20 commits intomksglu:nextfrom
btxbtxbtx:qwen-code-adapter
Closed

feat: add Qwen Code adapter with Windows Bun detection#342
btxbtxbtx wants to merge 20 commits intomksglu:nextfrom
btxbtxbtx:qwen-code-adapter

Conversation

@btxbtxbtx
Copy link
Copy Markdown

Summary

Adds a new platform adapter for Qwen Code (Alibaba's CLI coding agent), enabling context-mode to work with Qwen Code via its Hook system.

Changes

New files (4)

  • src/adapters/qwen-code/index.ts — QwenCodeAdapter class (~280 lines)
  • src/adapters/qwen-code/hooks.ts — Hook definitions mapping Qwen Code tool names
  • configs/qwen-code/settings.json — Hook configuration template
  • configs/qwen-code/QWEN.md — Routing instructions for Qwen Code's system prompt

Modified files (4)

  • src/adapters/types.ts — Added "qwen-code" to PlatformId union
  • src/adapters/client-map.ts — Added qwen-code → qwen-code mapping
  • src/adapters/detect.ts — Added env var detection (QWEN_PROJECT_DIR, QWEN_SESSION_ID), config dir detection (~/.qwen/), and getAdapter() case
  • src/runtime.ts — Fixed bunExists() and bunCommand() on Windows to check D:\bun\bin, %LOCALAPPDATA%\bun\bin, and ~/.bun/bin/bun.exe

Testing

  • TypeScript compilation: zero errors
  • Build: npm run build succeeds
  • ctx doctor on Qwen Code: all checks pass (FTS5, Bun detection, hooks)
  • Verified with Node 22.20.0 on Windows 10

@mksglu mksglu changed the base branch from main to next April 25, 2026 09:05
@mksglu
Copy link
Copy Markdown
Owner

mksglu commented Apr 25, 2026

Hi @btxbtxbtx! Did you test that on local? Thanks.

mksglu added a commit that referenced this pull request Apr 25, 2026
Qwen Code (by Alibaba/Qwen team) uses an identical hook wire protocol
to Claude Code — verified from qwen-code source (hookRunner.ts,
claude-converter.ts). Same JSON stdin/stdout, same event names, same
response format (hookSpecificOutput, updatedInput, additionalContext).

Adapter differences from Claude Code (justified by source evidence):
- Config dir: ~/.qwen/ (not ~/.claude/)
- Env vars: QWEN_PROJECT_DIR, QWEN_SESSION_ID
- Session ID priority: session_id field first (Claude: transcript_path)
- MCP clientInfo: qwen-cli-mcp-client-* (dynamic pattern match)
- No plugin registry (uses settings.json directly)

Files:
- src/adapters/qwen-code/index.ts — standalone adapter (not copy-paste)
- src/adapters/types.ts — add "qwen-code" to PlatformId
- src/adapters/client-map.ts — add qwen-code + pattern entries
- src/adapters/detect.ts — env vars, config dir, clientInfo pattern match
- configs/qwen-code/QWEN.md — routing instructions
- tests/adapters/qwen-code.test.ts — 20 TDD tests
- tests/adapters/detect.test.ts — env var + clientInfo detection tests
- tests/adapters/client-map.test.ts — mapping test

348 adapter tests pass (14 files). Replaces PR #342 which was 95%
copy-paste of Claude Code adapter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mksglu
Copy link
Copy Markdown
Owner

mksglu commented Apr 25, 2026

Thanks @btxbtxbtx for the initiative! We've implemented Qwen Code support differently on next (2861d45) based on a deep review of the Qwen Code source:

Why we went a different route:
Your PR was ~95% copy-paste of the Claude Code adapter. After verifying from Qwen Code's source (hookRunner.ts, claude-converter.ts) that the wire protocol is identical, we built a standalone adapter that only overrides what's genuinely different:

Difference Evidence
Config dir: ~/.qwen/ QWEN_CONFIG_DIR = '.qwen' in source
Env vars: QWEN_PROJECT_DIR hookRunner.ts sets this alongside CLAUDE_PROJECT_DIR
Session ID: session_id first Qwen prioritizes direct field over transcript_path
MCP client: qwen-cli-mcp-client-* Dynamic pattern from mcp-client.ts
No plugin registry settings.json only

What shipped:

  • Standalone adapter (not a copy-paste — shared protocol, different config paths)
  • Pattern-based MCP clientInfo detection (handles qwen-cli-mcp-client-<serverName>)
  • 20 TDD tests + routing instructions
  • 348 adapter tests pass

Windows Bun detection from your PR is a good general improvement — consider submitting that as a separate focused PR.

@mksglu mksglu closed this Apr 25, 2026
@mksglu
Copy link
Copy Markdown
Owner

mksglu commented Apr 25, 2026

Update: Windows Bun detection also shipped on next (9403e2d). bunFallbackPaths() now checks %LOCALAPPDATA%\bun\bin\bun.exe and ~/.bun/bin/bun.exe on Windows. This benefits all platforms, not just Qwen Code.

README and CONTRIBUTING.md updated with Qwen Code install docs + platform matrix (13th platform). Thanks again for the initial work.

@btxbtxbtx
Copy link
Copy Markdown
Author

checking comments

@btxbtxbtx
Copy link
Copy Markdown
Author

Sorry for the noise — this was an accidental test comment. Please disregard.

@mksglu
Copy link
Copy Markdown
Owner

mksglu commented Apr 26, 2026

Sorry for the noise — this was an accidental test comment. Please disregard.

Thank you!! @btxbtxbtx Let's test Qwen Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants