Qwen Code
A PreToolUse hook that checks Qwen Code shell commands, writes, edits and reads; risky ones ask, dangerous ones are denied.
Connect
shellfirm connect qwenshellfirm — connecting Qwen Code integration
/home/dev/.qwen/settings.json:
- add hooks.PreToolUse entry (matcher "run_shell_command|write_file|edit|read_file|read_many_files") running `shellfirm check --hook qwen --config-dir /home/dev/.config/shellfirm`
✓ written
Qwen Code shell commands, file writes and reads are now checked by shellfirm (PreToolUse hook: risky -> ask, dangerous -> deny; headless runs deny what would be asked). Restart running Qwen Code sessions.What it installs
{
"hooks": {
"PreToolUse": [
{
"matcher": "run_shell_command|write_file|edit|read_file|read_many_files",
"hooks": [
{
"type": "command",
"command": "shellfirm check --hook qwen --config-dir /home/dev/.config/shellfirm",
"timeout": 30
}
]
}
]
}
}The matcher is a list of exact tool names. run_shell_command is checked as a shell command (with its directory), write_file and edit as edits, read_file like cat <path>, and read_many_files (a tool only in Qwen Code versions that still expose it) like a read of every path in paths; a directory is read as everything in it (~/.ssh like ~/.ssh/*), and a directory or glob that reaches a key or credential file (~/.kube, ~/.ss?, **/* from the home directory) like a read of that file. Your other settings and hooks are kept. hooksConfig.disabled is a Gemini CLI setting: Qwen Code does not read it, so connect leaves it alone.
What Qwen Code sees
The answer has Claude Code's shape: hookSpecificOutput.permissionDecision with permissionDecisionReason.
| Command | Answer | Effect |
|---|---|---|
No check matches (ls) | nothing | Qwen Code's own approvals apply |
Risky, below the auto-deny threshold (cat ~/.ssh/id_rsa, Medium) | ask | You confirm in Qwen Code's prompt |
At or above the threshold, or deny-listed (git push -f origin main, High) | deny | Blocked, with the reason and a safer alternative |
Real ask answer:
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"ask","permissionDecisionReason":"shellfirm flagged this command as risky; confirm before running.\n[exfil:read_secret_file] [MEDIUM] This reads a private key or a credentials file. ...\nReason: Matched risky pattern(s) (severity MEDIUM, below the auto-deny threshold HIGH); confirm before running\nSafe alternative: read only what you need, not the secret itself (...)"}}Headless and IDE sessions
Headless runs and IDE (ACP) sessions of Qwen Code turn an ask into a deny:
nobody is there to confirm, so risky commands are blocked there. If shellfirm
cannot run, Qwen Code runs the tool call.
Options
| Option | Effect |
|---|---|
--scope user (default) | ~/.qwen/settings.json |
--scope project | ./.qwen/settings.json; Qwen Code asks you to approve project hooks |
--dry-run | Show what would change, write nothing |
--uninstall | Remove shellfirm's entries only |
qwen --safe-mode, qwen -y / --approval-mode yolo and a fresh QWEN_HOME started by an agent ask first, like the other hook bypasses (see self-protection).
Check the integration
Agent integrations:
qwen (user): hook yes, file tools yes, fail-closed no, MCP n/a