aws / aws/amazon-q-developer-cli

FR: Add `decision: ask` support for PreToolUse hooks

Offen
#3,596 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
2k
Forks
439
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

## Feature Request: Add `decision: ask` support for PreToolUse hooks

### Summary

Add support for a `decision: ask` response in PreToolUse hooks that prompts the user for confirmation before executing a tool, similar to Claude Code's hook system.

### Motivation

Currently, PreToolUse hooks only support two outcomes:
- **Exit 0**: Allow tool execution
- **Exit 2**: Block tool execution (returns STDERR to LLM)

There's no way for a hook to trigger an interactive user confirmation prompt. This limits the ability to implement "soft" security policies where certain commands (e.g., `sudo`) should require explicit user approval rather than being outright blocked.

### Proposed Solution

Allow hooks to output a JSON response to STDOUT with `decision: ask`:

```json
{
"decision": "ask",
"message": "⚠️ This command uses sudo:\n\n sudo apt update\n\nAllow execution?"
}
```

When the CLI receives this response:
1. Display the `message` to the user
2. Prompt for confirmation (y/n)
3. If approved, proceed with tool execution
4. If denied, return denial to the LLM

### Proposed Hook Output Behavior

| Exit Code | STDOUT | Behavior |
|-----------|--------|----------|
| 0 | Empty | Allow |
| 0 | `{"decision": "ask", "message": "..."}` | Prompt user |
| 2 | - | Block (STDERR to LLM) |
| Other | - | Warning, allow |

### Use Case Example

A security hook that prompts for sudo commands instead of blocking them:

```python
#!/usr/bin/env python3
import json, sys, re

input_data = json.load(sys.stdin)
command = input_data.get("tool_input", {}).get("command", "")

if re.search(r'(^|;|&&|\|\||\|)\s*sudo(\s|$)', command):
print(json.dumps({
"decision": "ask",
"message": f"⚠️ This command uses sudo:\n\n {command}\n\nAllow execution?"
}))
sys.exit(0)
```

### Prior Art

- [Claude Code hooks](https://docs.anthropic.com/en/docs/claude-code/hooks) support `decision: ask` for interactive approval flows

### Additional Context

This feature would enable more flexible security policies where users can make case-by-case decisions rather than having blanket allow/deny rules.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Es werden keine Dateien, Tests oder Einstiegspunkte genannt. Beginne damit, die Verarbeitung des PreToolUse-Hooks und die Verarbeitung der Hook-Standardausgabe sowie der Exit-Codes zu lokalisieren. Verfolge den CLI-Pfad, der eine Nachricht anzeigen und eine Bestätigung anfordern kann; als erledigt gilt die Implementierung des vorgeschlagenen Verhaltens für Fragen, Genehmigen und Ablehnen, ohne die bestehenden Ergebnisse für Erlauben, Blockieren oder Warnen zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust
Bereich
cli
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.