Skip to content

Add support for plan_exit tool event to notify when Plan agent completes #59

@de-abreu

Description

@de-abreu

Problem

OpenCode has two main agent modes: Plan and Build. When using Plan mode, the agent creates a plan and then calls the plan_exit tool to request user approval. Currently, there's no way to get notified when the Plan agent finishes its work and is waiting for user input.

This is different from:

  • complete - fires when a session fully completes (Build mode finishing)
  • subagent_complete - fires when subagents (general, explore) finish
  • question - fires when the question tool is invoked

The plan_exit is a distinct event that indicates the Plan agent has produced a plan and is waiting for the user to either approve it or switch to Build mode.

Proposed Solution

Add a new event type plan_exit that hooks into the tool.execute.before event and detects when input.tool === "plan_exit".

Configuration

{
  "events": {
    "plan_exit": { "sound": true, "notification": true, "command": true }
  },
  "messages": {
    "plan_exit": "Plan ready for review: {sessionTitle}"
  }
}

Implementation Approach

Similar to how question is handled via tool.execute.before:

// In index.ts
"tool.execute.before": async (input) => {
  if (input.tool === "question") {
    await handleEvent(config, "question", projectName, null)
  }
  if (input.tool === "plan_exit") {
    await handleEvent(config, "plan_exit", projectName, null)
  }
}

Event Config

Following existing patterns:

// In config.ts
export type EventType = "permission" | "complete" | "subagent_complete" | "error" | "question" | "interrupted" | "user_cancelled" | "plan_exit"

// Default config
events: {
  // ... existing events
  plan_exit: { sound: true, notification: true, command: true },
}

messages: {
  // ... existing messages  
  plan_exit: "Plan ready for review: {sessionTitle}",
}

Use Case

As a user, I want to:

  1. Switch to Plan mode and describe what I want
  2. Let the Plan agent work (may take a while for complex tasks)
  3. Get notified when it's done creating the plan
  4. Review the plan and decide whether to proceed

Currently, I have no notification when step 3 happens, so I need to keep checking the terminal.

Alternative Considered

I considered using subagent_complete, but:

  1. Plan is not a subagent - it's one of the two main agent modes
  2. Enabling subagent_complete would also notify for "general" and "explore" subagents, which is not desired

Environment

  • OpenCode version: latest
  • opencode-notifier version: latest
  • Platform: Linux (NixOS)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions