aws / aws/amazon-q-developer-cli

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

Open
#3,596 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2k
Forks
439
PR merge metrics
No merged PRs in 30d

Description

## 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.