Last week I lost a 45-minute Codex session because my thumb grazed the close button on a terminal tab.

No warning. No confirmation. Just gone. The session context, chain of thought, and iterative refinements I’d been building all evaporated because of one bad click. If you’ve worked with AI coding agents (Codex, Claude Code, Cursor, whatever), you probably know this feeling. These tools build context over a conversation. Lose that in the middle, and you’re paying for it in both time and mental energy.

The Problem: Context Fatigue

When you work with AI agents, context is everything. You spend the first few minutes setting up the problem, feeding in files, establishing constraints. By minute 20, the agent understands your codebase, your preferences, your current goal. Closing that tab resets all of it.

Windows Terminal also makes this easy to do by accident. The close button sits right there on each tab. One stray click, and you’re starting over.

This is not theoretical for me. I run multiple terminal profiles side by side: one for general shell work, one for OpenClaw sessions, and one for SSH tunnels. Tabs pile up fast, and muscle memory does not always cooperate.

The Fix: 30 Seconds in settings.json

Windows Terminal supports custom themes, and themes control tab behavior. Here’s the relevant bit:

{
  "theme": "no-close-button",
  "themes": [
    {
      "name": "no-close-button",
      "tab": {
        "background": "terminalBackground",
        "showCloseButton": "never",
        "unfocusedBackground": "#00000000"
      },
      "window": {
        "applicationTheme": "dark"
      }
    }
  ]
}

That’s it. Set "showCloseButton": "never" in your theme, reference the theme at the top level, and close buttons disappear from all tabs.

You can still close tabs with Ctrl+Shift+W when you actually want to, but the accidental click vector is gone.

Where to find the file

Press Ctrl+Shift+, in Windows Terminal to open settings.json directly. Or find it at:

%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json

Bonus: Separate Profiles for AI Work

While you’re in the settings, consider creating a dedicated terminal profile for your AI agent sessions:

{
  "guid": "{some-guid-here}",
  "name": "AI Sessions",
  "source": "Microsoft.WSL",
  "colorScheme": "One Half Dark",
  "icon": "path/to/your/icon.png"
}

Visual differentiation helps more than you’d think. When your AI session tab looks different from your regular shell, you’re less likely to close the wrong one. I use a distinct icon and color scheme for my OpenClaw profile so it stands out in the tab bar.

The Deeper Layer: tmux as a Safety Net

Removing the close button handles the UI side, but what about SSH disconnects or terminal crashes? That’s where tmux (or screen) comes in.

# Start a named session for your AI work
tmux new-session -s ai-work

# Detach anytime with Ctrl+B, then D
# Reattach later
tmux attach -t ai-work

If you run your AI agent inside tmux, closing the terminal tab doesn’t kill the process. The session keeps running, and you can reattach without losing anything. Combine this with the no-close-button theme and you’ve got two layers of protection.

One caveat: vanilla tmux does not survive system reboots. The tmux server process dies, and all sessions go with it. If that matters to you, look into tmux-resurrect for manual save/restore, or tmux-continuum for automatic persistence across reboots. Without these plugins, tmux protects you from accidental closes and disconnects, but not from a full restart.

Why This Matters More Than It Sounds

Developer experience conversations usually focus on big things: CI/CD pipelines, IDE plugins, deployment workflows. But small frictions add up. Accidentally closing a tab and losing 30 minutes of AI-assisted work does not just waste time, it breaks flow state. And that is where real productive work happens.

A 30-second config change that prevents that? Worth writing about.

Quick Checklist

  1. Open Windows Terminal settings (Ctrl+Shift+,)
  2. Add a theme with "showCloseButton": "never"
  3. Set that theme as your default
  4. Create a separate profile for AI sessions with a distinct icon
  5. Run long sessions inside tmux for crash protection
  6. Stop losing context to misclicks

The best productivity hack is often the smallest one.


Credit: The showCloseButton theme option exists thanks to the Windows Terminal team and the community discussion in microsoft/terminal#19792. If this feature helped you, consider giving the issue a thumbs up.