Skip to content

Background Terminal Sessions #3968

Closed
Closed

Description

@roshanasingh4

What feature would you like to see?

Summary

Enable codex-cli to run terminal sessions in the background, similar to how Claude Code supports background terminals. This would allow long-running processes to continue without needing to keep the CLI window open, with the option to reattach later.

Problem

  • Developers often run commands that take hours (servers, builds, migrations, log tails).
  • Currently, they must keep codex-cli in the foreground or rely on external tools like tmux, screen, or nohup.
  • This is inconvenient, error-prone, and inconsistent across platforms.

Goals

  • Start commands as background sessions that survive terminal closure.
  • Detach and reattach to a session with full TTY support.
  • Provide log streaming and export without requiring reattachment.
  • Ensure sessions are listed, inspectable, and manageable directly from codex-cli.
  • Cross-platform support (macOS, Linux, WSL).

Non-Goals

  • Full tmux replacement.
  • Orchestrating sessions across multiple hosts.

Proposed UX

Examples

  • Start a background process:
    codex run --bg --name api-dev "pnpm dev"

diff
Copy code

  • List sessions:
    codex sessions list

diff
Copy code

  • Tail logs without attaching:
    codex sessions logs api-dev --follow

arduino
Copy code

  • Attach/detach:
    codex sessions attach api-dev

bash
Copy code

  • Stop/clean up:
    codex sessions stop api-dev
    codex sessions rm api-dev

markdown
Copy code

Config Options

  • Storage directory for session metadata and logs
  • Maximum session count
  • Log rotation and retention settings
  • Idle timeout or TTL for auto-expiration

Benefits

  • Improves developer productivity by reducing reliance on external tools.
  • Provides a unified workflow for running and managing long-running processes.
  • Makes codex-cli more competitive with similar tools that already provide background terminal support.

Alternatives Considered

  • Continue relying on tmux/screen. Works but adds complexity and reduces portability.
  • Use nohup or & in shell. Limited functionality, no reattachment or lifecycle management.

Acceptance Criteria

  • Background sessions survive CLI and terminal restarts.
  • Users can list, inspect, attach, detach, and stop sessions.
  • Logs are captured and exportable.
  • Works across macOS, Linux, and WSL with minimal setup.

Are you interested in implementing this feature?

Yes

Additional information

No response

Activity

  1. bearyung commented on Sep 23, 2025

    @bearyung

    this will be extremely useful. when using Claude Code CLI, Claude can automatically run several server (dotnet run dev, npm run dev) in background, and check the server side error during the frontend test using playwright mcp, observe the errors thrown in different servers (maybe one for auth, one for transaction and one for user preference), and fix the bug automatically, build and kill those servers and run that again to verify the fix.

    Also I used to ask Claude Code to add different diagnoses logs on server side when testing the APIs.

  2. roshanasingh4 commented on Sep 25, 2025

    @roshanasingh4
    Author

    Thanks @bearyung - your example really highlights the value here.

    Even a minimal version with run --bg, sessions list, attach/detach, and basic log capture would cover most needs. Lifecycle management (TTL, cleanup, export) could be added incrementally once the core flow is solid.

    Would be great to hear if maintainers see this phased approach as feasible.

  3. tekn0x commented on Oct 4, 2025

    @tekn0x

    Yes please. I currently add this to my prompts as a work around: "You also need to run all servers as background processes or else you will get stuck forever. Tail any logs you need to see."

  4. eladcandroid commented on Oct 5, 2025

    @eladcandroid

    Helpful issue
    That's the current state:

    Image

    Wating too long time..

  5. marked background processes #3553 as a duplicate of this issue on Nov 11, 2025
  6. changed the title [-]Feature Request: Background Terminal Sessions[/-] [+]Background Terminal Sessions[/+] on Nov 13, 2025
  7. myudak commented on Nov 28, 2025

    @myudak

    yeah pls, i hate this limitation, the gpts are so lazy in the codex

  8. zssz commented on Mar 16, 2026

    @zssz

    I have a working implementation for one piece of this in my fork and wanted to ask whether maintainers would be open to taking it.

    This change adds an experimental app-server API:

    • thread/backgroundTerminals/list

    Motivation:

    • a client can keep long-lived background terminals running on the server
    • after reconnect or client restart, it had no authoritative way to rediscover those sessions
    • the only server API in this area was thread/backgroundTerminals/clean, so clients had to fall back to heuristics based on historical turn items or live output
    • this listing API gives reconnect flows a stable source of truth and reduces client-side guesswork

    What the branch adds:

    • protocol + app-server wiring for thread/backgroundTerminals/list
    • live unified-exec metadata: callId, processId, command, cwd, tty, startedAt
    • thread/core support to enumerate active background terminals
    • deterministic ordering by startedAt
    • protocol tests, app-server tests, schema updates, and README docs

    Ready branch:

    Verification run:

    • cargo run -p codex-app-server-protocol --bin write_schema_fixtures
    • cargo test -p codex-app-server-protocol
    • cargo test -p codex-app-server --test all thread_background_terminals

    I can’t open the upstream PR directly because openai/codex currently restricts PR creation to collaborators. If this looks like a useful direction, would a maintainer be willing to either:

    • open the PR from my fork branch, or
    • grant temporary collaborator access so I can open the draft PR myself?

    If you’d prefer this discussed in a separate issue instead of this umbrella one, I can do that too.

  9. xbyang42 commented on Jun 15, 2026

    @xbyang42

    I hope the official team can implement this feature, similar to Claude Code's run_in_background.
    A typical use case is having Codex perform deep learning auto research. Claude Code can submit a training task and then suspend the command to the background. Once training is complete, it can be reactivated for the next steps of testing and result analysis. In contrast, Codex, on the other hand, constantly polls to check if training is finished—even though the training task might last for several days.

  10. weathon commented on Jul 22, 2026

    @weathon

    Yes, I am running deep learning research and codex keep polling on it, burning tokens fast

  11. etraut-openai commented on Aug 5, 2026

    @etraut-openai
    Contributor

    /ps and app-server APIs implement background-terminal management.

  12. PierreMesure commented on Aug 16, 2026

    @PierreMesure

    On my setup, Codex regularly tries to use nohup and fails before actually using a background terminal command compatible with /ps. To the point that I had to add that the AGENTS.md:

    ## Don't use nohup
    
    Your sandbox doesn't let you.
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

    enhancementNew feature or requesttool-callsIssues related to tool calling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions