Stop a force-push and ask before risky commands in Qwen Code
See, control, and price every tool call Qwen Code makes: shell, file edits, MCP. Qwen Code's hooks are Claude Code's contract, so this is the same hook, one file.
Install
curl -fsSL https://agenticcontrolplane.com/install.sh | bash
irm https://agenticcontrolplane.com/install.ps1 | iex
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
{
"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 ispermissionDecision: "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 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 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-editandyolo. 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 setACP_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:
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. What Qwen Code itself shows with /stats: Qwen Code 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.
Protected in 3 steps
Out of the box, ACP records every tool call your agents make. A short safety floor applies in every mode: catastrophic commands (rm -rf on your home or system folders, disk wipes) are always blocked, and force-push, destructive SQL, piping a download into a shell, and deleting outside your project are held for your approval. Your own rules (ask first / never) start applying when you turn on enforce. No rule can loosen the floor; a workspace owner or admin can switch it off on the Policies page (you were asked at install). With --local the always-blocked list is narrower: rm -rf on your home or root, disk wipes, fork bombs.
-
1
Install. One command, then approve this machine in the browser.
curl -fsSL https://agenticcontrolplane.com/install.sh | bash -
2
Turn on your rules. Run
/acp-enforcein your agent. The starter rules start applying:rmand keychain reads are held for your approval (you approve on the console Approvals page or from the approval email); everything else keeps running and is recorded. Add your own with/acp-ask Bash.curl,/acp-deny Bash.git.push,/acp-allow Bash.npm, or on the Policies page. With--localthere is no mode switch: the rules in~/.acp/policy.jsonapply from the first call, and the starter file asks beforerm,curl,git push,chmodandchown. -
3
See it work. Ask your agent to do something risky, for example
git push --forceon a scratch repo. ACP holds the call for your approval; the call and your answer land in the audit log (/acp-whyfor the last hold, the console Activity page, or~/.acp/audit.jsonlwith--local). In Qwen Code, a held call shows as a block in the agent; approve it on the console Approvals page or from the approval email, then ask the agent to retry.
Copy-paste rules for the things people are most afraid of (force-push, prod database, rm -rf, a secret in a curl, overnight runs, a cost cap): Rules that stop the scary things.