# Qwen Code hooks: risky commands held for your OK

Install ACP for Qwen Code via its native hooks. Every tool call (shell, file edits, MCP) is policy-checked before it runs, with an audit record and output scanning. One command, one file: ~/.qwen/settings.json.

# Stop a force-push and ask before risky commands in Qwen Code

<p style="font-size:17px;line-height:1.6;color:var(--acp-text);max-width:660px;margin:8px 0 6px;">See, control, and price <strong>every tool call Qwen Code makes</strong>: shell, file edits, MCP. Qwen Code's hooks are <a href="/controls/qwen-code">Claude Code's contract</a>, so this is the same hook, one file.</p>

## Install



The installer detects Qwen Code (`~/.qwen` or `qwen` on your PATH). It merges `PreToolUse` and `PostToolUse` hooks plus the ACP MCP connector into `~/.qwen/settings.json`. Then it opens your browser once to set up a workspace and save the key to `~/.acp/credentials`. Restart Qwen Code and every tool call is checked from the next session.

## What the installer writes

```json
{
  "hooks": {
    "PreToolUse":  [{ "matcher": "*", "hooks": [{ "type": "command", "name": "acp", "command": "env ACP_CLIENT=qwen-code node $HOME/.acp/govern.mjs", "timeout": 5000 }] }],
    "PostToolUse": [{ "matcher": "*", "hooks": [{ "type": "command", "name": "acp", "command": "env ACP_CLIENT=qwen-code node $HOME/.acp/govern.mjs", "timeout": 5000 }] }]
  },
  "mcpServers": { "acp": { "command": "sh", "args": ["-c", "exec npx -y mcp-remote https://api.agenticcontrolplane.com/mcp --header \"Authorization: Bearer $(cat ~/.acp/credentials)\""] } }
}
```

Existing hooks and MCP servers are kept. Re-running the installer replaces only its own entries. It writes the user-level file because project-level hooks need folder trust and user-level hooks do not. If `disableAllHooks` is set, the installer warns you, and nothing runs until you remove it.

## How it works

- **Before each call** (`PreToolUse`): the hook sends the tool name and arguments to your workspace policy. The answer is allow, ask or deny. A deny is `permissionDecision: "deny"`, with the reason shown to the model.
- **When the answer is ask:** Qwen Code does not render a hook's ask, so the call is blocked in Qwen Code. It waits on the [console Approvals page](https://cloud.agenticcontrolplane.com/approvals) and in the approval email. Approve it there, then ask Qwen Code to retry. The workspace starts in audit mode, where everything is recorded and only the safety floor holds calls. The [rules page](/docs/rules) lists what the floor holds.
- **After each call** (`PostToolUse`): the tool output is recorded and scanned, and the session's model usage is priced from the transcript.
- **Every approval mode.** The hook runs in `plan`, `default`, `auto-edit` and `yolo`. Qwen Code's approval mode decides whether it prompts you. The hook decides whether the call runs.
- **If the gateway is unreachable,** this hook fails open in every kind of session. You get a loud warning and the lapse is logged locally. To fail closed instead, run `echo closed > ~/.acp/failmode` (or set `ACP_FAIL_MODE=closed`) on that machine.

## Add the cost X-ray

The hooks check and record tool calls. They never see the model call, so they cannot price it. For priced spend, prompt-cache hit rate and the loop-vs-leaf X-ray on the console, start Qwen Code with the launcher the installer put next to `claude-acp` and `codex-acp`:

```bash
qwen-acp
```

`qwen-acp` reads your workspace key from `~/.acp/credentials`. It sets `OPENAI_BASE_URL`, `OPENAI_API_KEY` and `OPENAI_MODEL` for that launch only. `ACP_QWEN_MODEL=<id>` picks the model behind the proxy, and the default is `gemini-3.5-flash`. Plain `qwen` is untouched. If the gateway is unreachable, the launcher starts plain `qwen` with a one-line note.

Qwen Code only honours those variables when its auth type is OpenAI. Pick "OpenAI" under `/auth` once. The launcher reminds you if it isn't set. Full walkthrough: [Turn on Cost X-Ray](/cost-tracking).

## Last tested

We wired this inside a fresh Linux container under the Terminal-Bench runner on 2026-09-03, with Qwen Code 0.23.0. The hook fired on the first tool call, and the session appeared in the workspace's runs API under the `qwen-code` client name. We have not re-run that test on later Qwen Code releases.

## Uninstall

Remove the two `acp` entries under `hooks` and the `acp` entry under `mcpServers` in `~/.qwen/settings.json`.
