Skip to content

Commit c71bbea

Browse files
committed
feat(cli,core): add Auto approval mode with LLM classifier (#auto-mode)
Add a fifth approval mode positioned between Auto-Edit and YOLO that uses an LLM classifier to evaluate each tool call and auto-approve safe ones while blocking risky ones — letting agents work autonomously on long sessions without forcing users to confirm every shell/network call. Three-layer filter when L4 returns 'ask'/'default': L5.1 acceptEdits fast-path: Edit/Write inside workspace -> allow L5.2 safe-tool allowlist: Read/Grep/LS/TodoWrite/... -> allow L5.3 LLM classifier: two-stage (fast/thinking) via sideQuery Anti-injection: assistant text and tool results are stripped from the classifier transcript; each tool projects its args through a new `toAutoClassifierInput` method to redact sensitive/voluminous fields. Pending action is rendered as a user-role text turn so it survives the OpenAI Chat Completions converter (which drops orphan tool_calls). Safety: fail-closed on classifier failure; denial-tracking caps 3 consecutive blocks / 2 consecutive unavailable before falling back to manual confirmation; dangerous allow rules (Bash interpreter wildcards, any Agent/Skill allow) are temporarily stripped while in AUTO and restored on exit — settings.json is never modified. Config: --approval-mode auto # CLI flag tools.approvalMode: "auto" # settings.json permissions.autoMode.hints.{allow,deny}: string[] # natural-lang permissions.autoMode.environment: string[]
1 parent 870bdf2 commit c71bbea

44 files changed

Lines changed: 3745 additions & 20 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/users/features/_meta.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default {
1414
display: 'hidden',
1515
},
1616
'approval-mode': 'Approval Mode',
17+
'auto-mode': 'Auto Mode',
1718
mcp: 'MCP',
1819
lsp: 'LSP (Language Server Protocol)',
1920
'token-caching': 'Token Caching',

docs/users/features/approval-mode.md

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Approval Mode
22

3-
Qwen Code offers four distinct permission modes that allow you to flexibly control how AI interacts with your code and system based on task complexity and risk level.
3+
Qwen Code offers five distinct permission modes that allow you to flexibly control how AI interacts with your code and system based on task complexity and risk level.
44

55
## Permission Modes Comparison
66

@@ -9,19 +9,23 @@ Qwen Code offers four distinct permission modes that allow you to flexibly contr
99
| **Plan**| ❌ Read-only analysis only | ❌ Not executed | • Code exploration <br>• Planning complex changes <br>• Safe code review | Lowest |
1010
| **Default**| ✅ Manual approval required | ✅ Manual approval required | • New/unfamiliar codebases <br>• Critical systems <br>• Team collaboration <br>• Learning and teaching | Low |
1111
| **Auto-Edit**| ✅ Auto-approved | ❌ Manual approval required | • Daily development tasks <br>• Refactoring and code improvements <br>• Safe automation | Medium |
12+
| **Auto**| ✅ Classifier-evaluated | ✅ Classifier-evaluated | • Long autonomous sessions <br>• When Auto-Edit is too cautious but YOLO is too risky | Medium |
1213
| **YOLO**| ✅ Auto-approved | ✅ Auto-approved | • Trusted personal projects <br>• Automated scripts/CI/CD <br>• Batch processing tasks | Highest |
1314

1415
### Quick Reference Guide
1516

1617
- **Start in Plan Mode**: Great for understanding before making changes
1718
- **Work in Default Mode**: The balanced choice for most development work
1819
- **Switch to Auto-Edit**: When you're making lots of safe code changes
20+
- **Try Auto Mode**: When you want fewer interruptions but still want safety on shell commands and network calls — an LLM classifier evaluates each call
1921
- **Use YOLO sparingly**: Only for trusted automation in controlled environments
2022

2123
> [!tip]
2224
>
2325
> You can quickly cycle through modes during a session using **Shift+Tab** (or **Tab** on Windows). The terminal status bar shows your current mode, so you always know what permissions Qwen Code has.
2426
27+
> The cycle order is: **plan → default → auto-edit → auto → yolo → plan → ...**
28+
2529
## 1. Use Plan Mode for safe code analysis
2630

2731
Plan Mode instructs Qwen Code to create a plan by analyzing the codebase with **read-only** operations, perfect for exploring codebases, planning complex changes, or reviewing code safely.
@@ -182,7 +186,118 @@ Shift+Tab (or Tab on Windows) # Switch from other modes
182186
3. **Automatically**​ applies all file changes without confirmation
183187
4. If tests need to be run, it will **request approval**​ to execute `npm test`
184188

185-
## 4. YOLO Mode - Full Automation
189+
## 4. Auto Mode - Classifier-Driven Approval
190+
191+
Auto Mode sits between Auto-Edit and YOLO. An LLM classifier evaluates each
192+
shell command, network call, and out-of-workspace edit and auto-approves
193+
the ones it judges safe while blocking risky ones. Most read-only operations
194+
and in-workspace edits skip the classifier for speed.
195+
196+
See [auto-mode.md](./auto-mode.md) for the full reference (hints
197+
configuration, troubleshooting, FAQ).
198+
199+
### When to use Auto Mode
200+
201+
- **Long autonomous sessions**: When Default Mode interrupts too often but
202+
YOLO is too risky.
203+
- **Trusted projects**: Internal codebases where the agent should keep
204+
moving but you still want a guardrail on destructive shell commands and
205+
outbound network calls.
206+
- **Headless / scheduled runs**: Where Auto-Edit isn't enough (the agent
207+
needs to run shell commands too) but you want safety on `rm -rf /`,
208+
`curl ... | sh`, credential exfiltration, etc.
209+
210+
### How to use Auto Mode
211+
212+
**Turn on Auto Mode during a session**
213+
214+
Press **Shift+Tab** (or **Tab** on Windows) to cycle into Auto Mode. The
215+
status bar shows the active mode.
216+
217+
**Use the `/approval-mode` command**
218+
219+
```
220+
/approval-mode auto
221+
```
222+
223+
The first time you enter Auto Mode, an information message explains how it
224+
works. The notice does not appear again.
225+
226+
**Start a new session in Auto Mode**
227+
228+
```jsonc
229+
// .qwen/settings.json
230+
{
231+
"tools": {
232+
"approvalMode": "auto",
233+
},
234+
}
235+
```
236+
237+
### What Auto Mode auto-approves vs blocks
238+
239+
The classifier is biased toward blocking when uncertain. Defaults:
240+
241+
- **Auto-approved**: read-only commands (ls, cat, git status, grep, find),
242+
package install in cwd, build/test commands, file edits inside the
243+
workspace, local-only operations.
244+
- **Blocked**: irreversible destruction (rm -rf /, fdisk, mkfs),
245+
code-from-external execution (curl | sh, eval of remote content),
246+
credential exfiltration, unauthorized persistence (.bashrc edits,
247+
crontab), security weakening, force-push to main/master.
248+
249+
You can customize the classifier's judgement via natural-language hints in
250+
settings.json. See [auto-mode.md](./auto-mode.md#configuring-hints).
251+
252+
### Safety guardrails
253+
254+
- **Hard rules remain in force**: `permissions.deny` rules block actions
255+
before the classifier ever runs.
256+
- **Over-broad allow rules are stripped while in Auto Mode**: e.g.
257+
`permissions.allow: ["Bash"]` (allow every shell command) defeats the
258+
classifier; entering Auto Mode temporarily disables such rules so the
259+
classifier can do its job. The rules are restored when you leave Auto
260+
Mode. Settings on disk are never modified.
261+
- **Fail-closed**: when the classifier API is unreachable, the action is
262+
blocked rather than allowed. After two consecutive unavailable calls,
263+
the next tool call falls back to manual approval.
264+
- **Loop guard**: after three consecutive policy blocks, the next call
265+
also falls back to manual approval so the agent isn't stuck cycling on
266+
a dead-end approach.
267+
268+
### Example
269+
270+
```
271+
/approval-mode auto
272+
Refactor the auth module to use OAuth2. Run the full test suite afterwards.
273+
```
274+
275+
Qwen Code makes the file edits (in-workspace edits skip the classifier),
276+
runs `npm test` (classifier judges safe), and surfaces a block if it ever
277+
tries something risky like `rm -rf /Users/me/.aws`. You can review the
278+
reason inline and decide whether to switch to Default Mode for that step.
279+
280+
### Configure Auto Mode as default
281+
282+
```jsonc
283+
// .qwen/settings.json
284+
{
285+
"tools": {
286+
"approvalMode": "auto",
287+
},
288+
"permissions": {
289+
"autoMode": {
290+
"hints": {
291+
"allow": ["Running pytest, mypy, and ruff on this Python repo"],
292+
"deny": ["Any network call to intranet.example.com"],
293+
},
294+
"environment": ["Open-source monorepo; commits are signed"],
295+
},
296+
},
297+
}
298+
```
299+
300+
## 5. YOLO Mode - Full Automation
186301

187302
YOLO Mode grants Qwen Code the highest permissions, automatically approving all tool calls including file editing and shell commands.
188303

0 commit comments

Comments
 (0)