Qwen3 tool-use: relative file paths in Write/Edit resolve to /tmp instead of the system-prompt working directory
Qwen3 tool-use: relative file paths in Write/Edit resolve to /tmp/… instead of the system-prompt working directory
Summary
When Qwen3 is driven as a coding agent through an Anthropic-compatible endpoint (Alibaba Model Studio "Token Plan") with an Anthropic-style Write tool (which requires an absolute file_path), and asked to create a file with a bare/relative filename, Qwen constructs the absolute path as /tmp/<name> rather than joining it to the working directory provided in the system prompt.
The tool call itself is well-formed and executes successfully — the file just lands in /tmp instead of the project directory, so from the user's perspective the edit "didn't happen." Passing an explicit absolute path works reliably.
This is a tool-argument grounding issue (weak use of the stated cwd), not a tool-calling failure.
Environment
- Model:
qwen3.8-max-preview(Token Plan), Anthropic-compatible endpoint (/apps/anthropic/v1/messages). - Harness: Claude Code pointed at the endpoint via
ANTHROPIC_BASE_URL/ANTHROPIC_AUTH_TOKEN/ANTHROPIC_MODEL. (Full, reproducible config: https://github.com/Gerry9000/qwen-on-claude-code) - Reproduces with the raw Messages API too (below), so it is independent of the harness.
Expected vs. actual
- Expected: given a stated cwd and a bare filename
notes.txt, producefile_path = <cwd>/notes.txt. - Actual: produces
file_path = /tmp/notes.txt(or a barenotes.txt), ignoring the stated cwd.
Minimal reproduction (raw Anthropic Messages API)
System prompt states the cwd; a Write tool is offered; the user asks for a bare filename:
{
"model": "qwen3.8-max-preview",
"max_tokens": 512,
"system": "You are a coding agent. The current working directory is /home/user/project. Write files relative to this directory unless told otherwise.",
"tools": [{"name":"Write","description":"Write content to a file at an absolute path",
"input_schema":{"type":"object","properties":{"file_path":{"type":"string"},"content":{"type":"string"}},"required":["file_path","content"]}}],
"messages": [{"role":"user","content":"Create a file named notes.txt containing hello. Use the Write tool."}]
}Observed file_path across 3 runs: /home/user/project/notes.txt, /home/user/project/notes.txt, notes.txt.
Without the explicit "write relative to this directory" instruction (just the tool + a system-prompt cwd), it consistently emits /tmp/notes.txt.
Evidence
- The
tool_useblock is valid: correctid, and the streamedinput_jsonreconstructs to valid JSON with bothfile_pathandcontent. So the model is not failing to call the tool. - In a real harness run (
Create dbgW.txt containing hi), the transcript shows:Write(file_path="/tmp/dbgW.txt", content="hi")→File created successfully at: /tmp/dbgW.txt. The file was created — in/tmp, not the cwd. - Explicit absolute path (
Writeto<cwd>/file.txt): 3/3 correct. - Emphasizing the cwd in the system prompt improves but does not eliminate it (2/3 above).
Impact
Agentic coding harnesses (Claude Code, and any tool loop that gives the model an absolute-path Write/Edit tool) will silently drop edits into /tmp when the model uses a relative name — a confusing, hard-to-notice failure mode for anyone running Qwen3 as a coding agent.
Suggested resolution
- Strengthen grounding so relative/bare filenames in tool arguments are joined to the system-prompt cwd; or
- If this is expected, document it (e.g. an FAQ for configuring third-party agent harnesses) with the workaround: always pass absolute paths, or have the harness resolve relative paths to the cwd before dispatch.
Reproducible harness config and a writeup of this + related integration gotchas: https://github.com/Gerry9000/qwen-on-claude-code
Source: QwenLM/Qwen3