# Qwen Code Permissions & Control Model, Explained

Qwen Code (Alibaba, Gemini CLI lineage) ships five approval modes, Claude-style permission rules, an optional sandbox, and a hook system that is Claude Code's contract. What each layer gates, what the classifier mode decides for you, and where headless runs resolve an ask.

# The Qwen Code control model, explained

[Qwen Code](https://github.com/QwenLM/qwen-code) is Alibaba's open-source terminal coding agent. It is a fork of Gemini CLI, tuned for Qwen models, and it works with any OpenAI-compatible endpoint. Its 27 tools are named like Claude Code's, in snake_case, and it sends a large wrapper before your prompt ([see what harnesses send](/blog/what-coding-harnesses-send-before-your-prompt)).

Its control surface mirrors Claude Code's too. That makes it easy to govern.

*This page covers Qwen Code's own model. To add ACP, see the [install guide](/integrations/qwen-code). For the cross-harness picture, see [the controls comparison](/controls).*

## Layer 1: approval modes

Set `tools.approvalMode` in `settings.json`, or pass `--approval-mode` or `--yolo` on the command line:

| Mode | What runs without asking |
|---|---|
| `plan` | Nothing that modifies files or runs commands |
| `default` | Nothing. Every edit and shell command prompts |
| `auto-edit` | File edits. Commands still prompt |
| `auto` | Whatever an LLM classifier judges safe. Risky actions are blocked |
| `yolo` | Everything |

Check which mode your install starts in. In `auto`, a model call decides whether a shell command is safe, not a rule you wrote. The same command can get a different answer next time. Teams that want a fixed boundary set `default` or `auto-edit` and write the rest as rules.

## Layer 2: permission rules

The `permissions` block uses Claude Code's rule grammar:

```json
{
  "permissions": {
    "allow": ["Bash(git status)", "Read(./src/**)"],
    "ask":   ["Bash(git push *)"],
    "deny":  ["Read(./secrets/**)", "Bash(rm -rf *)", "mcp__untrusted"]
  }
}
```

`deny` beats `ask`, and `ask` beats `allow`. You manage rules with `/permissions` in the session.

The older `tools.allowed` and `tools.exclude` keys are deprecated but still honoured at startup, so audit both on an existing install. `tools.core` limits the built-in tools to an allowlist and fails closed for them, but MCP, skill and synthetic tools bypass it.

Settings resolve in a fixed order: defaults, the system defaults file, user `~/.qwen/settings.json`, project `.qwen/settings.json`, the system settings file at `/etc/qwen-code/settings.json`, environment, then flags. System settings override user and project settings. That is the enterprise pin: an operator can fix the approval mode and deny list for every user on a machine.

## Layer 3: sandbox

`tools.sandbox` accepts a boolean or a path. Docker and Podman are the container backends, and `tools.sandboxImage` or `--sandbox-image` picks the image. On macOS you can supply a seatbelt profile per project as `.qwen/sandbox-macos-custom.sb`. The sandbox is off by default.

As with every harness, the sandbox limits where the agent can act. It does not decide which actions run.

## Layer 4: hooks

Qwen Code's hook system is Claude Code's contract, almost field for field:

| | Qwen Code | Claude Code |
|---|---|---|
| Events | `PreToolUse`, `PostToolUse`, `SessionStart`, `Stop`, `UserPromptSubmit`, `PermissionRequest`, `PermissionDenied`, plus subagent, compaction and todo events | Same core set |
| stdin | `session_id`, `transcript_path`, `cwd`, `hook_event_name`, `tool_name`, `tool_input`, `tool_use_id`, `permission_mode`; `tool_response` on PostToolUse | Same |
| Decision | `hookSpecificOutput.permissionDecision`: `allow` / `ask` / `deny`, with `permissionDecisionReason`; exit code 2 blocks with stderr as the reason | Same |
| Matcher | Regex on the runtime tool id; `*` or empty matches all | Regex; `.*` |
| Timeout | **seconds**, default 60 (values of 1000 or more are still read as milliseconds, so older `timeout: 5000` configs keep working) | seconds |
| Location | `hooks` in `~/.qwen/settings.json` or `.qwen/settings.json` | `~/.claude/settings.json` |
| Off switch | `disableAllHooks: true` | none |

Two things follow. First, a hook written for Claude Code runs on Qwen Code with a client-name change, which is what the [ACP install](/integrations/qwen-code) does. The installer currently writes the older millisecond-style timeout (`5000`), which Qwen Code still accepts.

Second, hooks are the one layer that sees every tool call with its arguments before it runs, in all five approval modes including `yolo`. Permission rules gate the built-in prompts. The hook gates the call.

Project-level hooks need the folder to be trusted (`security.folderTrust`). User-level hooks in `~/.qwen/settings.json` don't, which is why the installer writes there.

## Headless runs

Qwen Code's docs say a hook's `ask` **degrades to `deny`** in headless runs and background subagents. In a `qwen --prompt` run in CI, rules and hooks decide, and anything that would have needed a person is refused.

Qwen Code does not keep a durable record of what was allowed, refused or attempted. A hook that reports each decision to a separate log fills that gap.

## Where Qwen Code sits

Against the [comparison table](/controls), Qwen Code has a full native permission model (five modes plus rules), an optional sandbox, Claude-style hooks that can allow, ask, deny and rewrite output, a documented headless behavior, and an enterprise pin through system settings. `--yolo` skips the prompts, but a hook still sees every call.

## Frequently asked questions


