Skip to content

[bug] tmux PTY attach inherits TERM=dumb in container environments #150

@ThePlenkov

Description

@ThePlenkov

Bug Description

When CAO runs inside a Docker container or devcontainer, the TERM environment variable is often unset or set to dumb. The tmux attach-session subprocess inherits this, causing broken terminal rendering — no colors, garbled cursor positioning, and corrupted TUI output from agent CLIs.

Steps to Reproduce

  1. Run CAO inside a Docker container where TERM is unset or TERM=dumb
  2. Launch an agent (e.g. Claude Code, Codex)
  3. Connect to the terminal via the web UI WebSocket

Expected Behavior

Terminal renders correctly with colors and proper cursor positioning.

Actual Behavior

Terminal output is garbled. Agent TUIs (which rely on xterm-256color capabilities) render incorrectly. Status bars, spinners, and interactive elements are broken.

Root Cause

In cli_agent_orchestrator/api/main.py, the tmux attach subprocess inherits the process environment without ensuring TERM is set:

proc = subprocess.Popen(
    ["tmux", "attach-session", "-t", f"{session_name}:{window_name}"],
    stdin=slave_fd,
    stdout=slave_fd,
    stderr=slave_fd,
    close_fds=True,
    preexec_fn=os.setsid,
)

Proposed Fix

Default TERM to xterm-256color when spawning tmux:

pty_env = os.environ.copy()
pty_env.setdefault("TERM", "xterm-256color")

proc = subprocess.Popen(
    ["tmux", "attach-session", "-t", f"{session_name}:{window_name}"],
    stdin=slave_fd,
    stdout=slave_fd,
    stderr=slave_fd,
    close_fds=True,
    preexec_fn=os.setsid,
    env=pty_env,
)

This is a minimal change — it only sets TERM if not already defined, preserving any user-configured value.

Environment

  • CAO: main branch
  • Docker: 27.x (base image: mcr.microsoft.com/devcontainers/python:3.13)
  • tmux: 3.4+

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions