Skip to content

feat: approve a project's .envrc once and load it for agents and worktree setup - #27683

Closed
otavio wants to merge 11 commits into
pingdotgg:mainfrom
OSSystems:feat/first-class-direnv-support
Closed

otavio wants to merge 11 commits into
pingdotgg:mainfrom
OSSystems:feat/first-class-direnv-support

Conversation

@otavio

@otavio otavio commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Problem

Projects that provide their toolchain through direnv (use flake, devenv, use mise) only work in T3 terminals, where the shell hook runs. Providers are never launched through a shell, so agents start without the project's PATH, compilers and pinned runtimes, and worktree setup scripts can't see the project environment either. Today the workaround is a direnv allow setup script in every worktree, which competes with the project's own runOnWorktreeCreate.

Change

T3 asks once per project to approve its .envrc, then loads it automatically on the server host:

  • Approval: a composer banner (web, desktop, mobile) shows the .envrc and asks. An approval is bound to the file's path and content; T3 writes direnv's own allow record, so new worktrees with matching content are allowed without asking. A changed .envrc asks again with a diff. direnv deny is never overridden, files over 64 KiB are refused, and agents can't approve. Approving needs the operate grant.
  • Providers: Codex, Claude, OpenCode, Pi, Antigravity, Grok, Muse and every ACP agent start with the direnv environment; PATH is applied before the agent binary is resolved. Cursor (in-process @cursor/sdk) and Windows are not supported. Codex runs one shared process per project, since one process can carry only one environment.
  • Changes: an approved change restarts a provider session only when the whole session is idle; busy sessions keep their environment until their next idle restart.
  • Worktree setup: a new "Load direnv environment" setup stage gives setup scripts the worktree's full environment diff, including unset variables.
  • Failures: a broken, blocked or timed-out .envrc starts the session with the normal environment and shows one notice with a "Review .envrc" action.
  • Settings → Worktrees (web and mobile): "Load direnv environment" and "Trust .envrc changes", as an environment default with per-project overrides. A thread details indicator shows On, Off or Needs approval.
  • Docs: the project settings user guide covers approval, changes and turning it off.

Out of scope: static per-project variables, git commands the server runs itself (commit hooks), terminals and previews, and environment managers without direnv.

Scope and approval

Proposed in #6715 (October 7 proposal, revised design). Maintainer approval of direction and scope is still pending; this is a draft so the full change can be reviewed alongside the discussion. The open questions for maintainers are listed in the revised design comment.

Verification

  • Focused server tests for approval, diffs, trust, deny, oversized files, the setting, session restarts under concurrent turns and background work, the setup stage, and per-project Codex sessions; shared client logic has unit tests.
  • End to end with real direnv 2.38: a new worktree was allowed automatically and its setup script saw the .envrc variables.
  • Captured on web against a synthetic project with the Replay provider:

First .envrc in a project

First .envrc asks for approval

Approving it (MP4)

Approving the .envrc

A changed .envrc shows a diff

A changed .envrc shows a diff

A new worktree's setup script sees the environment

Setup script in a new worktree sees the environment

Settings → Worktrees

direnv settings

Not yet captured: mobile and desktop.

Done with Claude Opus 5.5 in T3 Code (Claude Code harness).

Otavio Salvador added 11 commits October 30, 2026 09:14
Projects that provide their toolchain through direnv (Nix dev shells, devenv, mise) only worked in
integrated terminals: agents never go through a shell, so they ran without the project's tools.

Before a provider process starts, ProviderSessionManagerV2 loads the `.envrc` governing the
session's cwd, as a shell with the direnv hook would, and the Codex, Claude, OpenCode, Pi, Grok,
ACP registry and Antigravity adapters apply it to their launch environment. Trust stays with
direnv: only `.envrc` files approved with `direnv allow` are loaded. A blocked or failing one
becomes a system notice on the run and the agent starts without it. Cursor runs in-process through
its SDK, which takes no environment, and OpenCode 2 shares one server across all of an instance's
projects, so both are left out.

Every turn reopens its session, so that is where the shell hook's staleness check runs: direnv
compares the files it watches against the environment the process started with, and when the user
allowed or edited the `.envrc`, or `flake.lock` changed, an idle session the thread owns alone is
released and reopened with the new environment. The native thread resumes as it does after an
idle release. A busy or shared session keeps its environment until it idles.

A blocked `.envrc` notice offers "Allow .envrc" on web and mobile, backed by a
`projectEnvironment.allowDirenv` RPC that resolves the directory from the thread. The behavior is
on by default and can be turned off per environment or project with "Load direnv environment".
Allowing a project's .envrc is guarded by the orchestration operate grant,
but the web and mobile buttons showed for every client, so a read-only
session only learned it couldn't act after clicking. The buttons now read
the command's permission for the thread's environment and stay hidden
without the grant; the warning itself still shows.
A direnv environment can remove variables, such as a toolchain path an .envrc replaces, so a
terminal launch needs a way to drop inherited keys, and a change to them counts as a new launch.
The registry resolved the agent binary before the direnv environment was applied, so tools the
project provides through its .envrc were not found. Apply it first, and keep the process
environment's own variables on top.
One provider process carries one environment, so sharing a Codex app-server across projects
would give every project the first one's direnv environment. Derive the shared session per
project; threads with a stored session id keep it.
Loading only .envrc files allowed from a shell left every new worktree blocked until a setup
script ran direnv allow, which competes with the project's own setup script. T3 Code now asks
once per project and per .envrc content, records the approval, and writes direnv's allow record
for the exact content reviewed in each checkout it loads. A change asks again with a diff unless
the project trusts changes, a direnv deny is never overridden, and an .envrc too large to show
cannot be approved in the app.

Agent sessions pick up an approved change by restarting, but only while the whole session is
idle, so turns and background work in threads sharing the process are never cut off.
A new Load direnv environment setup stage evaluates the worktree's approved .envrc before the
setup script, so projects no longer need a direnv allow setup script. A failure is shown on the
stage and setup continues.
…is on

A banner above the composer shows the .envrc, or the diff of a change, to approve, turn off, or
put off. The thread details panel shows On, Off or Needs approval when the project has one, and
Settings > Worktrees holds the project's direnv and trust-changes settings.
The new task and thread screens show the same approval banner as the web, and the worktrees
settings page gains the project's direnv and trust-changes settings.
Muse launches its own process but was the one process-based provider still started without the
thread's direnv environment, so tools a project provides through its .envrc were missing.
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XXL 1,000+ changed lines (additions + deletions). labels Oct 30, 2026
@maria-rcks

Copy link
Copy Markdown
Collaborator

Note

Written by gpt-6.1-sol on behalf of Maria

the prior-approval rule applies to this new project environment workflow. the draft adds in-app .envrc approval and trust, automatic loading, idle restart behavior and project-scoped Codex sessions. its scope section says maintainer approval is still pending. the maintainer note in #6715 preserves automatic activation as a requirement; it does not approve this implementation's trust and lifecycle choices. draft status does not postpone triage. see prior approval. obtain and link explicit approval for direction and scope, including those choices, before resubmitting. the underlying missing project toolchain remains recorded in #6715.

@maria-rcks maria-rcks closed this Oct 31, 2026
@poelzi

poelzi commented Nov 12, 2026

Copy link
Copy Markdown

Seriously ??? How should we actually use t3-code without this ?

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

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants