A custom tool for opencode that allows the LLM agent to pause and ask you for free-form text input during execution.
Get more done in a single request!
Instead of the agent guessing what you want and making mistakes, it can ask for clarification mid-task. This means:
- No more back-and-forth - Clarify once, get it right the first time
- Fewer LLM requests - One comprehensive task instead of multiple correction cycles
- Better results - Agent gets exactly the context it needs before proceeding
Example: Instead of "refactor this code" → agent guesses wrong → you correct → agent tries again...
Now it's: "refactor this code" → agent asks "class-based or functional?" → you answer → done correctly first time! ✅
- 📝 Free-form text input - Not just approve/deny, actual text responses
- 🔌 Pure custom tool - No modifications to opencode required
- ⏱️ Timeout handling - Default 5 minute timeout, configurable
- ❌ Cancellation support - User can cancel, agent abort signal respected
- 📄 Multi-line responses - Type as much as you want
The tool requires @opencode-ai/plugin. If you don't have it installed:
# Navigate to your global opencode config directory
cd ~/.config/opencode
# Initialize package.json if it doesn't exist
npm init -y
# Install the plugin package
npm install @opencode-ai/pluginNote: If you're working within the opencode monorepo, this package is already available.
# Clone this repo (or download the files)
git clone https://github.com/Whiteknight07/opencode-ask-user.git
cd opencode-ask-user
# Create the tool directory if it doesn't exist
mkdir -p ~/.config/opencode/tool
# Copy the tool
cp ask_user.ts ~/.config/opencode/tool/
# Copy the CLI helper (IMPORTANT: outside of tool/ directory)
cp ask-user-cli.ts ~/.config/opencode/
⚠️ Important: The CLI helper must be placed outside thetool/directory, otherwise opencode will try to load it as a tool and cause display issues.
Open a separate terminal window and run:
bun run ~/.config/opencode/ask-user-cli.tsYou'll see:
🤖 opencode ask_user CLI
Waiting for questions from the agent...
Press Ctrl+C to exit
────────────────────────────────────────────────────────────
In your main terminal, run opencode as usual. When the agent calls ask_user, the question will appear in the CLI helper terminal.
- Type your response
- Press Enter on an empty line to submit
- Or type
cancelto cancel the request
The tool uses file-based IPC (Inter-Process Communication):
┌──────────────────────────────────────────────────────────────┐
│ opencode (Terminal 1) │ CLI Helper (Terminal 2) │
├──────────────────────────────┼───────────────────────────────┤
│ LLM calls ask_user("...") │ Polling ~/.opencode/ask_user │
│ │ │ │ │
│ Write question.json ────────┼────────►│ │
│ │ │ ▼ │
│ Poll for response... │ Display question to user │
│ │ │ │ │
│ │ │ User types response │
│ │◄─────────────────┼──Write response.json │
│ │ │ │
│ Return response to LLM │ │
└──────────────────────────────────────────────────────────────┘
| Parameter | Type | Required | Description |
|---|---|---|---|
question |
string | Yes | The question to ask the user |
title |
string | No | Optional title/context for the question |
timeout |
number | No | Timeout in seconds (default: 300 = 5 min) |
The tool returns a JSON string:
{
"responded": true,
"response": "User's text response here",
"cancelled": false
}Or if cancelled/timeout:
{
"responded": false,
"response": "",
"cancelled": true,
"reason": "Timeout after 300 seconds waiting for user response"
}Make sure you've installed the plugin:
cd ~/.config/opencode
npm install @opencode-ai/pluginMake sure ask-user-cli.ts is placed outside the tool/ directory:
# Correct location
~/.config/opencode/ask-user-cli.ts ✅
# Wrong location (will cause issues)
~/.config/opencode/tool/ask-user-cli.ts ❌- Make sure the CLI helper is running in a separate terminal
- Check that
~/.opencode/ask_user/directory exists - Try restarting the CLI helper
MIT