@mmmbuto/qwen-code-termux 0.13.1-termux → 0.14.0-termux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +14 -7
  2. package/bundled/loop/SKILL.md +61 -0
  3. package/bundled/qc-helper/SKILL.md +151 -0
  4. package/bundled/qc-helper/docs/_meta.ts +30 -0
  5. package/bundled/qc-helper/docs/common-workflow.md +571 -0
  6. package/bundled/qc-helper/docs/configuration/_meta.ts +10 -0
  7. package/bundled/qc-helper/docs/configuration/auth.md +366 -0
  8. package/bundled/qc-helper/docs/configuration/memory.md +0 -0
  9. package/bundled/qc-helper/docs/configuration/model-providers.md +542 -0
  10. package/bundled/qc-helper/docs/configuration/qwen-ignore.md +55 -0
  11. package/bundled/qc-helper/docs/configuration/settings.md +655 -0
  12. package/bundled/qc-helper/docs/configuration/themes.md +160 -0
  13. package/bundled/qc-helper/docs/configuration/trusted-folders.md +61 -0
  14. package/bundled/qc-helper/docs/configuration.md +73 -0
  15. package/bundled/qc-helper/docs/extension/_meta.ts +9 -0
  16. package/bundled/qc-helper/docs/extension/extension-releasing.md +204 -0
  17. package/bundled/qc-helper/docs/extension/getting-started-extensions.md +299 -0
  18. package/bundled/qc-helper/docs/extension/introduction.md +338 -0
  19. package/bundled/qc-helper/docs/features/_meta.ts +19 -0
  20. package/bundled/qc-helper/docs/features/approval-mode.md +263 -0
  21. package/bundled/qc-helper/docs/features/arena.md +218 -0
  22. package/bundled/qc-helper/docs/features/channels/_meta.ts +7 -0
  23. package/bundled/qc-helper/docs/features/channels/dingtalk.md +134 -0
  24. package/bundled/qc-helper/docs/features/channels/overview.md +336 -0
  25. package/bundled/qc-helper/docs/features/channels/plugins.md +87 -0
  26. package/bundled/qc-helper/docs/features/channels/telegram.md +120 -0
  27. package/bundled/qc-helper/docs/features/channels/weixin.md +106 -0
  28. package/bundled/qc-helper/docs/features/checkpointing.md +77 -0
  29. package/bundled/qc-helper/docs/features/commands.md +312 -0
  30. package/bundled/qc-helper/docs/features/headless.md +318 -0
  31. package/bundled/qc-helper/docs/features/hooks.md +720 -0
  32. package/bundled/qc-helper/docs/features/language.md +139 -0
  33. package/bundled/qc-helper/docs/features/lsp.md +417 -0
  34. package/bundled/qc-helper/docs/features/mcp.md +281 -0
  35. package/bundled/qc-helper/docs/features/sandbox.md +241 -0
  36. package/bundled/qc-helper/docs/features/scheduled-tasks.md +139 -0
  37. package/bundled/qc-helper/docs/features/skills.md +289 -0
  38. package/bundled/qc-helper/docs/features/sub-agents.md +515 -0
  39. package/bundled/qc-helper/docs/features/token-caching.md +29 -0
  40. package/bundled/qc-helper/docs/ide-integration/_meta.ts +4 -0
  41. package/bundled/qc-helper/docs/ide-integration/ide-companion-spec.md +182 -0
  42. package/bundled/qc-helper/docs/ide-integration/ide-integration.md +144 -0
  43. package/bundled/qc-helper/docs/integration-github-action.md +241 -0
  44. package/bundled/qc-helper/docs/integration-jetbrains.md +81 -0
  45. package/bundled/qc-helper/docs/integration-vscode.md +39 -0
  46. package/bundled/qc-helper/docs/integration-zed.md +72 -0
  47. package/bundled/qc-helper/docs/overview.md +64 -0
  48. package/bundled/qc-helper/docs/quickstart.md +273 -0
  49. package/bundled/qc-helper/docs/reference/_meta.ts +3 -0
  50. package/bundled/qc-helper/docs/reference/keyboard-shortcuts.md +72 -0
  51. package/bundled/qc-helper/docs/support/Uninstall.md +42 -0
  52. package/bundled/qc-helper/docs/support/_meta.ts +6 -0
  53. package/bundled/qc-helper/docs/support/tos-privacy.md +112 -0
  54. package/bundled/qc-helper/docs/support/troubleshooting.md +123 -0
  55. package/bundled/review/SKILL.md +261 -0
  56. package/{dist/cli.js → cli.js} +159997 -128831
  57. package/locales/de.js +1964 -0
  58. package/locales/en.js +2005 -0
  59. package/locales/ja.js +1457 -0
  60. package/locales/pt.js +1954 -0
  61. package/locales/ru.js +1961 -0
  62. package/locales/zh.js +1811 -0
  63. package/package.json +30 -120
  64. package/dist/bundled/review/SKILL.md +0 -123
  65. /package/{dist/sandbox-macos-permissive-closed.sb → sandbox-macos-permissive-closed.sb} +0 -0
  66. /package/{dist/sandbox-macos-permissive-open.sb → sandbox-macos-permissive-open.sb} +0 -0
  67. /package/{dist/sandbox-macos-permissive-proxied.sb → sandbox-macos-permissive-proxied.sb} +0 -0
  68. /package/{dist/sandbox-macos-restrictive-closed.sb → sandbox-macos-restrictive-closed.sb} +0 -0
  69. /package/{dist/sandbox-macos-restrictive-open.sb → sandbox-macos-restrictive-open.sb} +0 -0
  70. /package/{dist/sandbox-macos-restrictive-proxied.sb → sandbox-macos-restrictive-proxied.sb} +0 -0
  71. /package/{dist/vendor → vendor}/ripgrep/COPYING +0 -0
  72. /package/{dist/vendor → vendor}/ripgrep/arm64-darwin/rg +0 -0
  73. /package/{dist/vendor → vendor}/ripgrep/arm64-linux/rg +0 -0
  74. /package/{dist/vendor → vendor}/ripgrep/x64-darwin/rg +0 -0
  75. /package/{dist/vendor → vendor}/ripgrep/x64-linux/rg +0 -0
  76. /package/{dist/vendor → vendor}/ripgrep/x64-win32/rg.exe +0 -0
  77. /package/{dist/vendor → vendor}/tree-sitter/tree-sitter-bash.wasm +0 -0
  78. /package/{dist/vendor → vendor}/tree-sitter/tree-sitter.wasm +0 -0
@@ -0,0 +1,720 @@
1
+ # Qwen Code Hooks Documentation
2
+
3
+ ## Overview
4
+
5
+ Qwen Code hooks provide a powerful mechanism for extending and customizing the behavior of the Qwen Code application. Hooks allow users to execute custom scripts or programs at specific points in the application lifecycle, such as before tool execution, after tool execution, at session start/end, and during other key events.
6
+
7
+ Hooks are enabled by default. You can temporarily disable all hooks by setting `disableAllHooks` to `true` in your settings file (at the top level, alongside `hooks`):
8
+
9
+ ```json
10
+ {
11
+ "disableAllHooks": true,
12
+ "hooks": {
13
+ "PreToolUse": [...]
14
+ }
15
+ }
16
+ ```
17
+
18
+ This disables all hooks without deleting their configurations.
19
+
20
+ ## What are Hooks?
21
+
22
+ Hooks are user-defined scripts or programs that are automatically executed by Qwen Code at predefined points in the application flow. They allow users to:
23
+
24
+ - Monitor and audit tool usage
25
+ - Enforce security policies
26
+ - Inject additional context into conversations
27
+ - Customize application behavior based on events
28
+ - Integrate with external systems and services
29
+ - Modify tool inputs or responses programmatically
30
+
31
+ ## Hook Architecture
32
+
33
+ The Qwen Code hook system consists of several key components:
34
+
35
+ 1. **Hook Registry**: Stores and manages all configured hooks
36
+ 2. **Hook Planner**: Determines which hooks should run for each event
37
+ 3. **Hook Runner**: Executes individual hooks with proper context
38
+ 4. **Hook Aggregator**: Combines results from multiple hooks
39
+ 5. **Hook Event Handler**: Coordinates the firing of hooks for events
40
+
41
+ ## Hook Events
42
+
43
+ Hooks fire at specific points during a Qwen Code session. When an event fires and a matcher matches, Qwen Code passes JSON context about the event to your hook handler. For command hooks, input arrives on stdin. Your handler can inspect the input, take action, and optionally return a decision. Some events fire once per session, while others fire repeatedly inside the agentic loop.
44
+
45
+ <div align="center">
46
+ <img src="https://img.alicdn.com/imgextra/i4/O1CN01sYWUTh1RDJl7Lz2ne_!!6000000002077-2-tps-812-1212.png" alt="Hook Lifecycle Diagram" width="400"/>
47
+ </div>
48
+
49
+ The following table lists all available hook events in Qwen Code:
50
+
51
+ | Event Name | Description | Use Case |
52
+ | -------------------- | ------------------------------------------- | ----------------------------------------------- |
53
+ | `PreToolUse` | Fired before tool execution | Permission checking, input validation, logging |
54
+ | `PostToolUse` | Fired after successful tool execution | Logging, output processing, monitoring |
55
+ | `PostToolUseFailure` | Fired when tool execution fails | Error handling, alerting, remediation |
56
+ | `Notification` | Fired when notifications are sent | Notification customization, logging |
57
+ | `UserPromptSubmit` | Fired when user submits a prompt | Input processing, validation, context injection |
58
+ | `SessionStart` | Fired when a new session starts | Initialization, context setup |
59
+ | `Stop` | Fired before Qwen concludes its response | Finalization, cleanup |
60
+ | `SubagentStart` | Fired when a subagent starts | Subagent initialization |
61
+ | `SubagentStop` | Fired when a subagent stops | Subagent finalization |
62
+ | `PreCompact` | Fired before conversation compaction | Pre-compaction processing |
63
+ | `SessionEnd` | Fired when a session ends | Cleanup, reporting |
64
+ | `PermissionRequest` | Fired when permission dialogs are displayed | Permission automation, policy enforcement |
65
+
66
+ ## Input/Output Rules
67
+
68
+ ### Hook Input Structure
69
+
70
+ All hooks receive standardized input in JSON format through stdin. Common fields included in every hook event:
71
+
72
+ ```json
73
+ {
74
+ "session_id": "string",
75
+ "transcript_path": "string",
76
+ "cwd": "string",
77
+ "hook_event_name": "string",
78
+ "timestamp": "string"
79
+ }
80
+ ```
81
+
82
+ Event-specific fields are added based on the hook type. Below are the event-specific fields for each hook event:
83
+
84
+ ### Individual Hook Event Details
85
+
86
+ #### PreToolUse
87
+
88
+ **Purpose**: Executed before a tool is used to allow for permission checks, input validation, or context injection.
89
+
90
+ **Event-specific fields**:
91
+
92
+ ```json
93
+ {
94
+ "permission_mode": "default | plan | auto_edit | yolo",
95
+ "tool_name": "name of the tool being executed",
96
+ "tool_input": "object containing the tool's input parameters",
97
+ "tool_use_id": "unique identifier for this tool use instance"
98
+ }
99
+ ```
100
+
101
+ **Output Options**:
102
+
103
+ - `hookSpecificOutput.permissionDecision`: "allow", "deny", or "ask" (REQUIRED)
104
+ - `hookSpecificOutput.permissionDecisionReason`: explanation for the decision (REQUIRED)
105
+ - `hookSpecificOutput.updatedInput`: modified tool input parameters to use instead of original
106
+ - `hookSpecificOutput.additionalContext`: additional context information
107
+
108
+ **Note**: While standard hook output fields like `decision` and `reason` are technically supported by the underlying class, the official interface expects the `hookSpecificOutput` with `permissionDecision` and `permissionDecisionReason`.
109
+
110
+ **Example Output**:
111
+
112
+ ```json
113
+ {
114
+ "hookSpecificOutput": {
115
+ "hookEventName": "PreToolUse",
116
+ "permissionDecision": "allow",
117
+ "permissionDecisionReason": "My reason here",
118
+ "updatedInput": {
119
+ "field_to_modify": "new value"
120
+ },
121
+ "additionalContext": "Current environment: production. Proceed with caution."
122
+ }
123
+ }
124
+ ```
125
+
126
+ #### PostToolUse
127
+
128
+ **Purpose**: Executed after a tool completes successfully to process results, log outcomes, or inject additional context.
129
+
130
+ **Event-specific fields**:
131
+
132
+ ```json
133
+ {
134
+ "permission_mode": "default | plan | auto_edit | yolo",
135
+ "tool_name": "name of the tool that was executed",
136
+ "tool_input": "object containing the tool's input parameters",
137
+ "tool_response": "object containing the tool's response",
138
+ "tool_use_id": "unique identifier for this tool use instance"
139
+ }
140
+ ```
141
+
142
+ **Output Options**:
143
+
144
+ - `decision`: "allow", "deny", "block" (defaults to "allow" if not specified)
145
+ - `reason`: reason for the decision
146
+ - `hookSpecificOutput.additionalContext`: additional information to be included
147
+
148
+ **Example Output**:
149
+
150
+ ```json
151
+ {
152
+ "decision": "allow",
153
+ "reason": "Tool executed successfully",
154
+ "hookSpecificOutput": {
155
+ "additionalContext": "File modification recorded in audit log"
156
+ }
157
+ }
158
+ ```
159
+
160
+ #### PostToolUseFailure
161
+
162
+ **Purpose**: Executed when a tool execution fails to handle errors, send alerts, or record failures.
163
+
164
+ **Event-specific fields**:
165
+
166
+ ```json
167
+ {
168
+ "permission_mode": "default | plan | auto_edit | yolo",
169
+ "tool_use_id": "unique identifier for the tool use",
170
+ "tool_name": "name of the tool that failed",
171
+ "tool_input": "object containing the tool's input parameters",
172
+ "error": "error message describing the failure",
173
+ "is_interrupt": "boolean indicating if failure was due to user interruption (optional)"
174
+ }
175
+ ```
176
+
177
+ **Output Options**:
178
+
179
+ - `hookSpecificOutput.additionalContext`: error handling information
180
+ - Standard hook output fields
181
+
182
+ **Example Output**:
183
+
184
+ ```json
185
+ {
186
+ "hookSpecificOutput": {
187
+ "additionalContext": "Error: File not found. Failure logged in monitoring system."
188
+ }
189
+ }
190
+ ```
191
+
192
+ #### UserPromptSubmit
193
+
194
+ **Purpose**: Executed when the user submits a prompt to modify, validate, or enrich the input.
195
+
196
+ **Event-specific fields**:
197
+
198
+ ```json
199
+ {
200
+ "prompt": "the user's submitted prompt text"
201
+ }
202
+ ```
203
+
204
+ **Output Options**:
205
+
206
+ - `decision`: "allow", "deny", "block", or "ask"
207
+ - `reason`: human-readable explanation for the decision
208
+ - `hookSpecificOutput.additionalContext`: additional context to append to the prompt (optional)
209
+
210
+ **Note**: Since UserPromptSubmitOutput extends HookOutput, all standard fields are available but only additionalContext in hookSpecificOutput is specifically defined for this event.
211
+
212
+ **Example Output**:
213
+
214
+ ```json
215
+ {
216
+ "decision": "allow",
217
+ "reason": "Prompt reviewed and approved",
218
+ "hookSpecificOutput": {
219
+ "additionalContext": "Remember to follow company coding standards."
220
+ }
221
+ }
222
+ ```
223
+
224
+ #### SessionStart
225
+
226
+ **Purpose**: Executed when a new session starts to perform initialization tasks.
227
+
228
+ **Event-specific fields**:
229
+
230
+ ```json
231
+ {
232
+ "permission_mode": "default | plan | auto_edit | yolo",
233
+ "source": "startup | resume | clear | compact",
234
+ "model": "the model being used",
235
+ "agent_type": "the type of agent if applicable (optional)"
236
+ }
237
+ ```
238
+
239
+ **Output Options**:
240
+
241
+ - `hookSpecificOutput.additionalContext`: context to be available in the session
242
+ - Standard hook output fields
243
+
244
+ **Example Output**:
245
+
246
+ ```json
247
+ {
248
+ "hookSpecificOutput": {
249
+ "additionalContext": "Session started with security policies enabled."
250
+ }
251
+ }
252
+ ```
253
+
254
+ #### SessionEnd
255
+
256
+ **Purpose**: Executed when a session ends to perform cleanup tasks.
257
+
258
+ **Event-specific fields**:
259
+
260
+ ```json
261
+ {
262
+ "reason": "clear | logout | prompt_input_exit | bypass_permissions_disabled | other"
263
+ }
264
+ ```
265
+
266
+ **Output Options**:
267
+
268
+ - Standard hook output fields (typically not used for blocking)
269
+
270
+ #### Stop
271
+
272
+ **Purpose**: Executed before Qwen concludes its response to provide final feedback or summaries.
273
+
274
+ **Event-specific fields**:
275
+
276
+ ```json
277
+ {
278
+ "stop_hook_active": "boolean indicating if stop hook is active",
279
+ "last_assistant_message": "the last message from the assistant"
280
+ }
281
+ ```
282
+
283
+ **Output Options**:
284
+
285
+ - `decision`: "allow", "deny", "block", or "ask"
286
+ - `reason`: human-readable explanation for the decision
287
+ - `stopReason`: feedback to include in the stop response
288
+ - `continue`: set to false to stop execution
289
+ - `hookSpecificOutput.additionalContext`: additional context information
290
+
291
+ **Note**: Since StopOutput extends HookOutput, all standard fields are available but the stopReason field is particularly relevant for this event.
292
+
293
+ **Example Output**:
294
+
295
+ ```json
296
+ {
297
+ "decision": "block",
298
+ "reason": "Must be provided when Qwen Code is blocked from stopping"
299
+ }
300
+ ```
301
+
302
+ #### SubagentStart
303
+
304
+ **Purpose**: Executed when a subagent (like the Task tool) is started to set up context or permissions.
305
+
306
+ **Event-specific fields**:
307
+
308
+ ```json
309
+ {
310
+ "permission_mode": "default | plan | auto_edit | yolo",
311
+ "agent_id": "identifier for the subagent",
312
+ "agent_type": "type of agent (Bash, Explorer, Plan, Custom, etc.)"
313
+ }
314
+ ```
315
+
316
+ **Output Options**:
317
+
318
+ - `hookSpecificOutput.additionalContext`: initial context for the subagent
319
+ - Standard hook output fields
320
+
321
+ **Example Output**:
322
+
323
+ ```json
324
+ {
325
+ "hookSpecificOutput": {
326
+ "additionalContext": "Subagent initialized with restricted permissions."
327
+ }
328
+ }
329
+ ```
330
+
331
+ #### SubagentStop
332
+
333
+ **Purpose**: Executed when a subagent finishes to perform finalization tasks.
334
+
335
+ **Event-specific fields**:
336
+
337
+ ```json
338
+ {
339
+ "permission_mode": "default | plan | auto_edit | yolo",
340
+ "stop_hook_active": "boolean indicating if stop hook is active",
341
+ "agent_id": "identifier for the subagent",
342
+ "agent_type": "type of agent",
343
+ "agent_transcript_path": "path to the subagent's transcript",
344
+ "last_assistant_message": "the last message from the subagent"
345
+ }
346
+ ```
347
+
348
+ **Output Options**:
349
+
350
+ - `decision`: "allow", "deny", "block", or "ask"
351
+ - `reason`: human-readable explanation for the decision
352
+
353
+ **Example Output**:
354
+
355
+ ```json
356
+ {
357
+ "decision": "block",
358
+ "reason": "Must be provided when Qwen Code is blocked from stopping"
359
+ }
360
+ ```
361
+
362
+ #### PreCompact
363
+
364
+ **Purpose**: Executed before conversation compaction to prepare or log the compaction.
365
+
366
+ **Event-specific fields**:
367
+
368
+ ```json
369
+ {
370
+ "trigger": "manual | auto",
371
+ "custom_instructions": "custom instructions currently set"
372
+ }
373
+ ```
374
+
375
+ **Output Options**:
376
+
377
+ - `hookSpecificOutput.additionalContext`: context to include before compaction
378
+ - Standard hook output fields
379
+
380
+ **Example Output**:
381
+
382
+ ```json
383
+ {
384
+ "hookSpecificOutput": {
385
+ "additionalContext": "Compacting conversation to maintain optimal context window."
386
+ }
387
+ }
388
+ ```
389
+
390
+ #### Notification
391
+
392
+ **Purpose**: Executed when notifications are sent to customize or intercept them.
393
+
394
+ **Event-specific fields**:
395
+
396
+ ```json
397
+ {
398
+ "message": "notification message content",
399
+ "title": "notification title (optional)",
400
+ "notification_type": "permission_prompt | idle_prompt | auth_success"
401
+ }
402
+ ```
403
+
404
+ > **Note**: `elicitation_dialog` type is defined but not currently implemented.
405
+
406
+ **Output Options**:
407
+
408
+ - `hookSpecificOutput.additionalContext`: additional information to include
409
+ - Standard hook output fields
410
+
411
+ **Example Output**:
412
+
413
+ ```json
414
+ {
415
+ "hookSpecificOutput": {
416
+ "additionalContext": "Notification processed by monitoring system."
417
+ }
418
+ }
419
+ ```
420
+
421
+ #### PermissionRequest
422
+
423
+ **Purpose**: Executed when permission dialogs are displayed to automate decisions or update permissions.
424
+
425
+ **Event-specific fields**:
426
+
427
+ ```json
428
+ {
429
+ "permission_mode": "default | plan | auto_edit | yolo",
430
+ "tool_name": "name of the tool requesting permission",
431
+ "tool_input": "object containing the tool's input parameters",
432
+ "permission_suggestions": "array of suggested permissions (optional)"
433
+ }
434
+ ```
435
+
436
+ **Output Options**:
437
+
438
+ - `hookSpecificOutput.decision`: structured object with permission decision details:
439
+ - `behavior`: "allow" or "deny"
440
+ - `updatedInput`: modified tool input (optional)
441
+ - `updatedPermissions`: modified permissions (optional)
442
+ - `message`: message to show to user (optional)
443
+ - `interrupt`: whether to interrupt the workflow (optional)
444
+
445
+ **Example Output**:
446
+
447
+ ```json
448
+ {
449
+ "hookSpecificOutput": {
450
+ "decision": {
451
+ "behavior": "allow",
452
+ "message": "Permission granted based on security policy",
453
+ "interrupt": false
454
+ }
455
+ }
456
+ }
457
+ ```
458
+
459
+ ## Hook Configuration
460
+
461
+ Hooks are configured in Qwen Code settings, typically in `.qwen/settings.json` or user configuration files:
462
+
463
+ ```json
464
+ {
465
+ "hooks": {
466
+ "PreToolUse": [
467
+ {
468
+ "matcher": "^bash$", // Regex to match tool names
469
+ "sequential": false, // Whether to run hooks sequentially
470
+ "hooks": [
471
+ {
472
+ "type": "command",
473
+ "command": "/path/to/script.sh",
474
+ "name": "security-check",
475
+ "description": "Run security checks before tool execution",
476
+ "timeout": 30000
477
+ }
478
+ ]
479
+ }
480
+ ],
481
+ "SessionStart": [
482
+ {
483
+ "hooks": [
484
+ {
485
+ "type": "command",
486
+ "command": "echo 'Session started'",
487
+ "name": "session-init"
488
+ }
489
+ ]
490
+ }
491
+ ]
492
+ }
493
+ }
494
+ ```
495
+
496
+ ### Matcher Patterns
497
+
498
+ Matchers allow filtering hooks based on context. Not all hook events support matchers:
499
+
500
+ | Event Type | Events | Matcher Support | Matcher Target (Values) |
501
+ | ------------------- | ---------------------------------------------------------------------- | --------------- | -------------------------------------------------------------------------------------- |
502
+ | Tool Events | `PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `PermissionRequest` | ✅ Yes (regex) | Tool name: `bash`, `read_file`, `write_file`, `edit`, `glob`, `grep_search`, etc. |
503
+ | Subagent Events | `SubagentStart`, `SubagentStop` | ✅ Yes (regex) | Agent type: `Bash`, `Explorer`, etc. |
504
+ | Session Events | `SessionStart` | ✅ Yes (regex) | Source: `startup`, `resume`, `clear`, `compact` |
505
+ | Session Events | `SessionEnd` | ✅ Yes (regex) | Reason: `clear`, `logout`, `prompt_input_exit`, `bypass_permissions_disabled`, `other` |
506
+ | Notification Events | `Notification` | ✅ Yes (exact) | Type: `permission_prompt`, `idle_prompt`, `auth_success` |
507
+ | Compact Events | `PreCompact` | ✅ Yes (exact) | Trigger: `manual`, `auto` |
508
+ | Prompt Events | `UserPromptSubmit` | ❌ No | N/A |
509
+ | Stop Events | `Stop` | ❌ No | N/A |
510
+
511
+ **Matcher Syntax**:
512
+
513
+ - Regex pattern matched against the target field
514
+ - Empty string `""` or `"*"` matches all events of that type
515
+ - Standard regex syntax supported (e.g., `^bash$`, `read.*`, `(bash|run_shell_command)`)
516
+
517
+ **Examples**:
518
+
519
+ ```json
520
+ {
521
+ "hooks": {
522
+ "PreToolUse": [
523
+ {
524
+ "matcher": "^bash$", // Only match bash tool
525
+ "hooks": [...]
526
+ },
527
+ {
528
+ "matcher": "read.*", // Match read_file, read_multiple_files, etc.
529
+ "hooks": [...]
530
+ },
531
+ {
532
+ "matcher": "", // Match all tools (same as "*" or omitting matcher)
533
+ "hooks": [...]
534
+ }
535
+ ],
536
+ "SubagentStart": [
537
+ {
538
+ "matcher": "^(Bash|Explorer)$", // Only match Bash and Explorer agents
539
+ "hooks": [...]
540
+ }
541
+ ],
542
+ "SessionStart": [
543
+ {
544
+ "matcher": "^(startup|resume)$", // Only match startup and resume sources
545
+ "hooks": [...]
546
+ }
547
+ ]
548
+ }
549
+ }
550
+ ```
551
+
552
+ ## Hook Execution
553
+
554
+ ### Parallel vs Sequential Execution
555
+
556
+ - By default, hooks execute in parallel for better performance
557
+ - Use `sequential: true` in hook definition to enforce order-dependent execution
558
+ - Sequential hooks can modify input for subsequent hooks in the chain
559
+
560
+ ### Security Model
561
+
562
+ - Hooks run in the user's environment with user privileges
563
+ - Project-level hooks require trusted folder status
564
+ - Timeouts prevent hanging hooks (default: 60 seconds)
565
+
566
+ ### Exit Codes
567
+
568
+ Hook scripts communicate their result through exit codes:
569
+
570
+ | Exit Code | Meaning | Behavior |
571
+ | --------- | ------------------ | ----------------------------------------------- |
572
+ | `0` | Success | stdout/stderr not shown |
573
+ | `2` | Blocking error | Show stderr to model and block tool call |
574
+ | Other | Non-blocking error | Show stderr to user only but continue tool call |
575
+
576
+ **Examples**:
577
+
578
+ ```bash
579
+ #!/bin/bash
580
+
581
+ # Success (exit 0 is default, can be omitted)
582
+ echo '{"decision": "allow"}'
583
+ exit 0
584
+
585
+ # Blocking error - prevents operation
586
+ echo "Dangerous operation blocked by security policy" >&2
587
+ exit 2
588
+ ```
589
+
590
+ > **Note**: If no exit code is specified, the script defaults to `0` (success).
591
+
592
+ ## Best Practices
593
+
594
+ ### Example 1: Security Validation Hook
595
+
596
+ A PreToolUse hook that logs and potentially blocks dangerous commands:
597
+
598
+ **security_check.sh**
599
+
600
+ ```bash
601
+ #!/bin/bash
602
+
603
+ # Read input from stdin
604
+ INPUT=$(cat)
605
+
606
+ # Parse the input to extract tool info
607
+ TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name')
608
+ TOOL_INPUT=$(echo "$INPUT" | jq -r '.tool_input')
609
+
610
+ # Check for potentially dangerous operations
611
+ if echo "$TOOL_INPUT" | grep -qiE "(rm.*-rf|mv.*\/|chmod.*777)"; then
612
+ echo '{
613
+ "decision": "deny",
614
+ "reason": "Potentially dangerous operation detected",
615
+ "hookSpecificOutput": {
616
+ "hookEventName": "PreToolUse",
617
+ "permissionDecision": "deny",
618
+ "permissionDecisionReason": "Dangerous command blocked by security policy"
619
+ }
620
+ }'
621
+ exit 2 # Blocking error
622
+ fi
623
+
624
+ # Allow the operation with a log
625
+ echo "INFO: Tool $TOOL_NAME executed safely at $(date)" >> /var/log/qwen-security.log
626
+
627
+ # Allow with additional context
628
+ echo '{
629
+ "decision": "allow",
630
+ "reason": "Operation approved by security checker",
631
+ "hookSpecificOutput": {
632
+ "hookEventName": "PreToolUse",
633
+ "permissionDecision": "allow",
634
+ "permissionDecisionReason": "Security check passed",
635
+ "additionalContext": "Command approved by security policy"
636
+ }
637
+ }'
638
+ exit 0
639
+ ```
640
+
641
+ Configure in `.qwen/settings.json`:
642
+
643
+ ```json
644
+ {
645
+ "hooks": {
646
+ "PreToolUse": [
647
+ {
648
+ "hooks": [
649
+ {
650
+ "type": "command",
651
+ "command": "${SECURITY_CHECK_SCRIPT}",
652
+ "name": "security-checker",
653
+ "description": "Security validation for bash commands",
654
+ "timeout": 10000
655
+ }
656
+ ]
657
+ }
658
+ ]
659
+ }
660
+ }
661
+ ```
662
+
663
+ ### Example 2: User Prompt Validation Hook
664
+
665
+ A UserPromptSubmit hook that validates user prompts for sensitive information and provides context for long prompts:
666
+
667
+ **prompt_validator.py**
668
+
669
+ ```python
670
+ import json
671
+ import sys
672
+ import re
673
+
674
+ # Load input from stdin
675
+ try:
676
+ input_data = json.load(sys.stdin)
677
+ except json.JSONDecodeError as e:
678
+ print(f"Error: Invalid JSON input: {e}", file=sys.stderr)
679
+ exit(1)
680
+
681
+ user_prompt = input_data.get("prompt", "")
682
+
683
+ # Sensitive words list
684
+ sensitive_words = ["password", "secret", "token", "api_key"]
685
+
686
+ # Check for sensitive information
687
+ for word in sensitive_words:
688
+ if re.search(rf"\b{word}\b", user_prompt.lower()):
689
+ # Block prompts containing sensitive information
690
+ output = {
691
+ "decision": "block",
692
+ "reason": f"Prompt contains sensitive information '{word}'. Please remove sensitive content and resubmit.",
693
+ "hookSpecificOutput": {
694
+ "hookEventName": "UserPromptSubmit"
695
+ }
696
+ }
697
+ print(json.dumps(output))
698
+ exit(0)
699
+
700
+ # Check prompt length and add warning context if too long
701
+ if len(user_prompt) > 1000:
702
+ output = {
703
+ "hookSpecificOutput": {
704
+ "hookEventName": "UserPromptSubmit",
705
+ "additionalContext": "Note: User submitted a long prompt. Please read carefully and ensure all requirements are understood."
706
+ }
707
+ }
708
+ print(json.dumps(output))
709
+ exit(0)
710
+
711
+ # No processing needed for normal cases
712
+ exit(0)
713
+ ```
714
+
715
+ ## Troubleshooting
716
+
717
+ - Check application logs for hook execution details
718
+ - Verify hook script permissions and executability
719
+ - Ensure proper JSON formatting in hook outputs
720
+ - Use specific matcher patterns to avoid unintended hook execution