opencode-idle-continueOpenCode plugin that automatically sends prompts to continue processing when idle. Supports traditional mode and subagent mode with file monitoring and hot reload.
0
1,077
近 7 天 52
38.6
生态多维模型
1 天前
2026-08-18
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-idle-continue@1.1.2"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-idle-continue@1.1.2"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-idle-continueopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
English | 中文版文档
opencode-idle-continue
OpenCode plugin that automatically sends prompts to continue processing when idle.
Features
- Idle Detection: Monitors OpenCode idle status and triggers continuation logic during idle periods
- Automatic Prompt Delivery: Reads prompt content from specified markdown files and sends to OpenCode for continued processing
- Hot Reload: Automatically reloads prompt files when modified without restarting the plugin
- File Change Monitoring: Maintains a list of files to monitor for content/timestamp changes
- Wait State Management: Enters wait state when sent prompts don't change monitored files, with interval backoff mechanism
- User Input Detection: Detects user typing activity even if the input is later deleted without sending
- Page Scroll Detection: Detects when users are scrolling through page content and pauses idle detection
- AI Stuck Detection & Recovery: Monitors AI response activity and automatically recovers from stuck states
- Two Working Modes:
- Traditional Mode: Direct prompt delivery with file monitoring and interval backoff
- Subagent Mode: Triggers OpenCode's native Task tool to launch sub-agents with automatic session management
Installation
Method 1: Global Installation
npm install -g opencode-idle-continue
After global installation, install to your desired location:
# Install to system config
opencode-idle-continue install system
# Install to current project
opencode-idle-continue install local
# Install to specific directory
opencode-idle-continue install /path/to/project
Method 2: Local Development Installation
bash install-local.sh
This script:
- Builds the
dist/directory - Creates tarball
dist/opencode-idle-continue-1.0.0.tgz - Copies
dist/contents to.opencode/plugins/idle-continue/ - Installs
@opencode-ai/plugindependency in.opencode/ - Updates
opencode.jsonto add plugin reference./plugins/idle-continue/index.js
After installation, restart OpenCode to load the plugin.
Configuration
All parameters are configured via idle-continue.json. Configuration file lookup order:
- Project root directory
.opencode/directory~/.config/opencode/directory
Prompt File Lookup Order
The prompt file (idle-prompt.md by default) is searched from the current directory upward, checking two locations per level:
{dir}/{prompt_file}(e.g.,idle-prompt.md){dir}/.opencode/{prompt_file}(e.g.,.opencode/idle-prompt.md)
Then {dir} moves up one level (parent directory) and checks the same two locations again. For example, if the current directory is /a/b/c/d, the search order is /a/b/c/d, /a/b/c, /a/b, /a, each checking both {prompt_file} and .opencode/{prompt_file}. The system root directory (e.g., /) is never searched.
If no prompt file is found, the behavior depends on enable_default_prompt:
- When
enable_default_promptisfalse(default), no message is sent - When
enable_default_promptistrue, the built-in default prompt is used
Configuration Fields
| Field | Type | Default | Description |
|---|---|---|---|
prompt_file |
string | "idle-prompt.md" |
Path to prompt file |
watch_files |
string[] | ["task.md", "wish-list.md"] |
List of files to monitor |
check_interval_minutes |
number | 30 |
Check interval during wait state (minutes) |
max_idle_cycles |
number | 5 |
Max consecutive idle cycles before interval doubling |
enabled |
boolean | true |
Whether the plugin is enabled |
log_enabled |
boolean | false |
Whether to enable logging |
enable_default_prompt |
boolean | false |
Whether to use built-in default prompt when prompt file doesn't exist |
subagent_enabled |
boolean | false |
Whether to enable subagent mode |
subagent_agent_type |
string | "explore" |
Subagent type (only when subagent_enabled=true) |
subagent_delay_ms |
number | 60_000 |
Subagent trigger delay in milliseconds (only when subagent_enabled=true) |
debounce_delay_ms |
number | 5000 |
Idle debounce confirmation delay in milliseconds (default 5s) |
stuck_threshold_minutes |
number | 20 |
AI stuck detection threshold in minutes (default 20min) |
ai_stuck_action |
string | "ignore" |
AI stuck recovery action: "ignore", "abort", or "abort_and_retry" |
ai_stuck_retry_prompt |
string | "continue" |
Prompt text for retry when ai_stuck_action is "abort_and_retry" |
Example idle-continue.json
{
"prompt_file": "idle-prompt.md",
"watch_files": ["task.md", "wish-list.md"],
"check_interval_minutes": 30,
"max_idle_cycles": 5,
"enabled": true,
"stuck_threshold_minutes": 20,
"ai_stuck_action": "abort_and_retry",
"ai_stuck_retry_prompt": "continue"
}
Working Principles
Mode 1: Traditional Mode (Default)
- Idle Detection: Monitors system idle status. Triggers when OpenCode is idle.
- User Activity Detection:
- Input Detection: Detects user typing activity in real-time, even if input is later deleted without sending
- Scroll Detection: Detects page scrolling and pauses idle detection while user is navigating content
- Idle detection is skipped when user is actively typing or scrolling
- Send Prompt: Reads prompt content from specified markdown file and sends to OpenCode for continued processing. If prompt file doesn't exist:
- When
enable_default_promptisfalse(default), no message is sent - When
enable_default_promptistrue, sends built-in default prompt
- When
- AI Stuck Detection & Recovery:
- Monitors AI response activity through heartbeat events (message updates, part updates, deltas)
- Detects stuck state when session is busy but no activity for configured threshold (default 20 minutes)
- Configurable recovery actions:
"ignore"- Do nothing (default)"abort"- Abort the stuck session"abort_and_retry"- Abort session, wait 30 seconds, then send retry prompt
- Prompt Hot Reload: Checks if prompt file has been modified each time
prompt_fileis used. Uses cached content if unchanged, reloads and updates cache if modified, no need to restart plugin. - File Change Monitoring: Maintains a list of files to monitor for content/timestamp changes.
- Wait State: If no changes in monitored files after sending prompt, enters wait state. Wait state requires:
- Continuous system idle
- No changes in monitored files
- Interval Backoff: During wait state, sends prompt every interval (default 30 minutes). If 5 consecutive checks still idle (files unchanged), next wait interval doubles.
Mode 2: Subagent Mode
- Idle Detection: Same as traditional mode, monitors system idle status.
- Delayed Execution: Waits specified time (default 60 seconds) after detecting true idle.
- Trigger Subagent: Calls Task tool via main agent to launch subagent. Leverages OpenCode Host's native capabilities to automatically create sub-sessions, render clickable links, and save complete message history.
- Subagent Management: Host automatically handles sub-session lifecycle including creation, execution, completion, and history preservation.
- User Interaction: Users can click links to switch to sub-session view and view subagent's complete output.
Files
idle-prompt.md— Default prompt file, contains prompt content sent to OpenCodetask.md— Default monitored file, records current taskswish-list.md— Default monitored file, records pending wish listidle-continue.json— Configuration file
Default Prompt: When enable_default_prompt is true and the prompt file doesn't exist, uses the built-in default prompt:
You are a helpful AI assistant. Please continue working on the current task or project context. Review any existing files, understand the current state, and suggest next steps or continue with the implementation.
CLI Commands
# Install to system config
opencode-idle-continue install system
# Install to current project
opencode-idle-continue install local
# Install to specific directory
opencode-idle-continue install /path/to/project
# Refresh plugin cache
opencode-idle-continue update
# Remove plugin
opencode-idle-continue uninstall
# Show help
opencode-idle-continue --help
# Show version
opencode-idle-continue --version
Build and Package
Source code is pure JavaScript ESM, no transpile needed. Build copies src/ to dist/:
npm run build
Build command:
node tools/build.mjs
Output:
dist/index.js— Plugin entry (same assrc/index.js)dist/opencode-true-idle-detector.js— Idle detection module with user activity and stuck detectiondist/subagent-trigger.js— Subagent trigger moduledist/wait-state.js— Wait state moduledist/file-utils.js— File utility moduledist/cli/index.js— CLI entry pointdist/package.json— npm package distribution manifest
Works with both node and bun.
Project Structure
opencode-idle-continue/
│
├── src/
│ ├── index.js ← Plugin only entry. Exports { id, server }
│ ├── opencode-true-idle-detector.js ← OpenCodeTrueIdleDetector class (idle detection debouncing state machine)
│ ├── subagent-trigger.js ← SubagentTrigger class (subagent trigger)
│ ├── wait-state.js ← WaitState class (wait state and backoff)
│ ├── file-utils.js ← File utilities (prompt loading, file snapshots, change detection)
│ └── cli/
│ └── index.js ← CLI entry point for installation commands
│
├── src/__tests__/
│ ├── opencode-true-idle-detector.test.js ← Idle detection state machine tests
│ ├── prompt.test.js ← Prompt file reading/hot reload tests
│ ├── file-watch.test.js ← File snapshot/change detection tests
│ ├── wait-state.test.js ← Wait state and backoff tests
│ └── index.test.js ← Integration tests
│
├── dist/
│ ├── index.js ← Build output
│ ├── opencode-true-idle-detector.js ← Build output
│ ├── subagent-trigger.js ← Build output
│ ├── wait-state.js ← Build output
│ ├── file-utils.js ← Build output
│ ├── cli/
│ │ └── index.js ← CLI entry point
│ └── package.json ← npm package distribution manifest
│
├── tools/
│ └── build.mjs ← Build script
│
├── install-local.sh ← Build + local installation script
├── clean.sh ← Uninstallation script
│
├── package.json ← npm package configuration
├── README.md ← English documentation
├── README.zh.md ← Chinese documentation
├── LICENSE
└── .gitignore
License
MIT
Changelog
See CHANGELOG.md for a list of changes in each version.