Skip to content

Feature Request: Auto-close browser tab after confirmation #41

Closed

Description

@jellydn

What

Add intelligent browser tab closing after plan approval/deny, with environment-aware behavior:

  • Local Claude Code: Auto-close tab after decision (1-2s delay for UX confirmation)
  • Local OpenCode: Auto-close tab after decision (1-2s delay for UX confirmation)
  • Remote sessions: Keep tab open (already no browser opened, but if user opens manually, don't close)

Why

Current Problem: Browser tabs remain open indefinitely after plan decisions, creating friction:

  1. Manual cleanup required: Users must manually close tabs after each plan review
  2. Tab accumulation: Frequent plan reviews lead to many open tabs
  3. Broken workflow flow: The UI says "Return to your Claude Code terminal" but the tab stays open, requiring manual action
  4. Inconsistent with expectations: Users expect the tool to disappear after completing its purpose

User Impact: Every plan approval requires an extra manual step (closing tab) that breaks the seamless workflow.

How

Phase 1: Environment Detection (packages/server/remote.ts)

// Add new detection function
export function getPlanEnvironment(): 'claude-code' | 'opencode' | 'unknown' {
  // Check for Claude Code hook environment
  if (process.env.CLAIDE_HOOK !== undefined) {
    return 'claude-code'
  }
  
  // Check for OpenCode plugin environment
  if (process.env.OPENCODE_PLUGIN !== undefined) {
    return 'opencode'
  }
  
  // Fallback: detect via hook file presence or command context
  return 'unknown'
}

Phase 2: Frontend Closing Logic (packages/ui/components/Viewer.tsx)

// After approve/deny success:
const shouldCloseTab = !isRemoteSession && environment !== 'unknown'

if (shouldCloseTab) {
  setTimeout(() => {
    // Show brief "closing..." message
    setClosingState(true)
    
    // Attempt close (note: window.close() only works for window.open() windows)
    window.close()
    
    // Fallback: show message if close blocked
    setTimeout(() => {
      if (!window.closed) {
        setCloseFailed(true)
      }
    }, 500)
  }, 1500) // 1.5s delay to show success message
}

Phase 3: Graceful Fallback UI

If window.close() is blocked by browser security (script-opened windows restriction):

{closeFailed && (
  <div className="banner">
    You can safely close this tab and return to your terminal.
  </div>
)}

Implementation Files

  1. packages/server/remote.ts: Add getPlanEnvironment() function
  2. packages/ui/components/Viewer.tsx: Add close logic after approve/deny
  3. packages/ui/types.ts: Add PlanEnvironment type
  4. packages/server/index.ts: Pass environment to frontend via /api/plan response

Browser Security Note

window.close() only works on windows opened by window.open(). Since we use open/xdg-open/start, the browser may block closing. Fallback UI is essential.

Acceptance Criteria

  • Local Claude Code: Tab closes 1.5s after approval
  • Local OpenCode: Tab closes 1.5s after approval
  • Remote sessions: No close attempt (tab stays open if manually opened)
  • Fallback message shown if browser blocks window.close()
  • Success message visible for at least 1s before close attempt
  • Environment detection works for both plugins

Open Questions

  • Should there be a user setting to disable auto-close? (e.g., PLANNOTATOR_NO_AUTO_CLOSE=1)
  • Should the delay be configurable? Currently hardcoded 1500ms

Related: Current behavior shows "Return to your Claude Code terminal" message but doesn't actually close the tab.

Activity

  1. backnotprop commented on Jan 9, 2026

    @backnotprop
    Owner

    Quick win shipped in PR #49: Improved post-decision messaging to explicitly tell users they can close the tab.

    Before: "Return to your Claude Code to continue."
    After: "You can close this tab and return to Claude Code." + "Your response has been sent."


    Regarding true auto-close: window.close() is blocked by browser security for tabs not opened via window.open(). Since we use system commands (open, xdg-open, cmd /c start), browsers will block the close attempt.

    Keeping this issue open in case there's a workaround discovered, but the messaging improvement should help UX in the meantime.

  2. backnotprop commented on Jan 9, 2026

    @backnotprop
    Owner

    Published in release v0.4.15

  3. ovitrif commented on Jan 15, 2026

    @ovitrif

    FWIW we could close the browser, not the tab, if configured via env variable to do so.

    I am ok to use a dedicated browser ONLY for Plannotator.

    Already kinda using it this way via PLANNOTATOR_BROWSER env var.

  4. added
    enhancement
    on Jan 22, 2026
  5. changed the title [-]Auto-close browser tab after plan confirmation (with environment detection)[/-] [+]Auto-close browser tab after confirmation[/+] on Jan 22, 2026
  6. changed the title [-]Auto-close browser tab after confirmation[/-] [+]Feature Request: Auto-close browser tab after confirmation[/+] on Jan 22, 2026
  7. thoroc commented on Jan 30, 2026

    @thoroc
    Contributor

    @ovitrif only if the default value is NOT to close the browser until it is set by the user. I use finicky to route the request to browsers for different purposes and I would NOT like to have to figure out: 1) to tell finicky how to route this correctly 2) getting my current default browser session closed off.

  8. ovitrif commented on Jan 31, 2026

    @ovitrif

    @thoroc makes sense!
    Need to learn now what finicky is. Thx!

  9. backnotprop commented on Feb 11, 2026

    @backnotprop
    Owner

    PR #128 ships the initial opt-in auto-close setting — users can toggle it in Settings > General. Covers the core ask from this issue.

    Remaining items from #41 not yet addressed:

    • Delay before close (show success overlay briefly before closing)
    • Remote session awareness (skip close attempt for remote/SSH sessions)
    • Fallback UI when browser blocks window.close()
  10. backnotprop commented on Mar 4, 2026

    @backnotprop
    Owner

    I'm going to close this for now. If we want to see better capabilities, like actually closing a browser, I'm happy to reopen in a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions