Tool-created worktrees do not select or run local environments

Open 💬 0 comments Opened Jun 11, 2026 by bradleygibsongit

I’m creating Codex app worktree threads through the Thread Tools / create_thread flow, but tool-created worktrees do not appear to select or run the project’s Codex local environment.

The same project has a native local environment checked in at .codex/environments/environment.toml with setup configured.

What I expected

When a worktree thread is created for a project that has a Codex local environment, the worktree should either:

  • use the project’s selected/default local environment automatically, or
  • let the tool caller select one, e.g. with localEnvironmentConfigPath / environmentName / similar.

That setup should run before the agent starts, the same way the app UI worktree flow is documented to support local environments.

What happened

The worktree is created successfully, and the checked-in environment file/scripts are present in the new worktree, but the setup script does not appear to run.

Setup artifacts that should have been created/copied/installed are missing:

  • .env.local
  • .vercel/project.json
  • node_modules

Reproduction steps

  1. In a local Git project, create a Codex local environment file:

``text
.codex/environments/environment.toml
``

  1. Configure a setup script in that environment. In my test repo, the setup script copies local ignored files from the source checkout into the worktree and installs dependencies:
  • copies .env.local
  • copies .vercel
  • runs npm ci
  1. Confirm the repo has the setup scripts checked in, for example:

``text
scripts/codex/setup.sh
scripts/codex/run-dev.sh
``

  1. From another Codex thread, create a new worktree thread with create_thread:

``json
{
"target": {
"type": "project",
"projectId": "/path/to/project",
"environment": {
"type": "worktree",
"startingState": { "type": "working-tree" }
}
},
"prompt": "Inspect whether native setup ran. Do not run setup manually."
}
``

  1. In the created worktree thread, inspect only. Do not manually run the setup script or install dependencies.

Clean test result

I tested this twice, including once after restarting the Codex app.

The created worktree contained:

  • .codex/environments/environment.toml: present
  • environment name: mywaste-wholesaler
  • scripts/codex/setup.sh: present and executable
  • scripts/codex/run-dev.sh: present and executable

But setup artifacts were missing:

  • .env.local: missing
  • .vercel/project.json: missing
  • node_modules/.package-lock.json: missing

The final inspection report was:

Native setup appeared to run: Fail
Env file present: Fail
Vercel link present: Fail
Dependencies present: Fail

Why this matters

This blocks using a Codex thread as an orchestrator for app-visible worktree agents. The tool can create the worktree, but it cannot currently make that worktree runnable via the same native local environment setup configured in the app.

The workaround is to either:

  • create the worktree manually through the app UI and select the environment, or
  • ask the agent to manually run setup after creation.

The second workaround is not ideal because it defeats the purpose of native Codex local environments and contaminates clean setup verification.

Requested fix

Please expose local environment selection in create_thread / worktree creation, or make tool-created worktrees use the project’s selected/default local environment automatically.

For example:

{
  "environment": {
    "type": "worktree",
    "startingState": { "type": "working-tree" },
    "localEnvironmentConfigPath": ".codex/environments/environment.toml"
  }
}

Related issues

This looks related to other cases where worktree flows do not consistently carry/select/run local environments:

  • #18981
  • #23648
  • #10476
  • #13576

View original on GitHub ↗