A flexible background process management plugin for OpenCode, offering robust process tracking and lifecycle management.
Create or edit your OpenCode configuration file (typically ~/.config/opencode/config.json):
{
"plugins": ["@zenobius/opencode-background"]
}I need to run and monitor multiple background processes for a build pipeline:
1. Start a long-running build process tagged as ["build", "critical"] that runs: `bun build ./src/index.ts --outdir dist --target bun`
2. Start a test runner tagged as ["test", "validation"] that runs: `bun test --watch`
3. Start a global process tagged as ["lint"] for linting: `mise run lint` (should persist across sessions)
4. List all current processes and show me their statuses
5. List only the processes tagged with "critical" or "validation"
6. Kill the test runner process, then list remaining processes
7. Show all currently running processes one more time to verify
Walk me through each step so I can see how the plugin handles concurrent processes, filtering, and termination.
Demonstrates:
- Creating multiple background processes
- Using tags for categorization
- Global vs session-specific processes
- Listing and filtering by tags
- Process termination
- Real-time status tracking
Let's test running a web server in the background using json-server:
- Start a json-server instance with: bunx json-server --watch db.json
- Tag it as ["server", "json-api"] for easy management
- Test that it's still running
- Execute a sync cmd (without background) to curl results from the server
- Test that it's still running
- Run a subagent that runs cmds to test the server too
- Confirm the subagent's results
Demonstrates:
- Long-running background services (JSON API server)
- Interleaving background processes with foreground commands
- Process monitoring across concurrent operations
- Subagent coordination with background processes
- Data persistence through process lifecycle
- Full CRUD operations validation while service runs continuously
- Real-time process status verification
- 🚀 Create background processes with real-time output tracking
- 🏷️ Tag and categorize processes
- 🔍 Advanced process filtering
- 🔪 Selective process termination
- 🌐 Global and session-specific process support
- ♻️ Automatic cleanup on session end and application close
⚙ createBackgroundProcess
command=/tmp/long-process.sh
name="Long Running Process"
tags=["long-process", "processing"]
global=false # Optional: default is false
-
Session-Specific Processes (default):
- Automatically terminated when the session ends
- Useful for temporary, session-bound operations
- Tracked in-memory for the current session
-
Global Processes:
- Persist across sessions
- Continues running until explicitly stopped
- Useful for long-running services or background operations
# List processes in current session
⚙ listBackgroundProcesses
sessionId=current_session_id
# List processes with specific tags
⚙ listBackgroundProcesses
tags=["processing"]
# Kill a specific process
⚙ killProcesses
processId=specific-process-id
# Kill all processes in a session
⚙ killProcesses
sessionId=current_session_id
command: Shell command to executename(optional): Descriptive name for the processtags(optional): List of tags to categorize the processglobal(optional):false(default): Session-specific processtrue: Process persists across sessions
sessionId(optional): Filter processes by sessionstatus(optional): Filter processes by statustags(optional): Filter processes by tags
processId(optional): Kill a specific processsessionId(optional): Kill processes in a specific sessionstatus(optional): Kill processes with a specific statustags(optional): Kill processes with specific tags
- Processes are tracked in-memory using a singleton
BackgroundProcessManager - Output stream captures up to the last 100 lines of process output
- Processes can be in states:
pending,running,completed,failed,cancelled - Processes include detailed metadata: start/completion times, error tracking
- ALL processes are killed when OpenCode closes
- Processes generate unique IDs automatically if not specified
Contributions are welcome! Please file issues or submit pull requests on the GitHub repository.
MIT License. See the LICENSE file for details.