Skip to content

Fix agent servers loading environment from home dir instead of project dir#52763

Merged
benbrandt merged 3 commits intozed-industries:mainfrom
derekparker:fix/agent-env-from-project-worktree
Mar 31, 2026
Merged

Fix agent servers loading environment from home dir instead of project dir#52763
benbrandt merged 3 commits intozed-industries:mainfrom
derekparker:fix/agent-env-from-project-worktree

Conversation

@derekparker
Copy link
Copy Markdown
Contributor

All local agent server types were calling local_directory_environment
with paths::home_dir(), causing direnv and shell environment to be
loaded from ~ rather than the project's worktree directory. This meant
project-specific .envrc variables (e.g. Google Vertex credentials)
were never picked up by external agents like Claude.

Added default_environment() on ProjectEnvironment that resolves the
default visible worktree path and uses it for environment loading,
falling back to home_dir() only when no worktree is available.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

  • Fixed default environment variable context for external agents

…t dir

All local agent server types were calling `local_directory_environment`
with `paths::home_dir()`, causing direnv and shell environment to be
loaded from `~` rather than the project's worktree directory. This meant
project-specific `.envrc` variables (e.g. Google Vertex credentials)
were never picked up by external agents like Claude.

Added `default_environment()` on `ProjectEnvironment` that resolves the
default visible worktree path and uses it for environment loading,
falling back to home_dir() only when no worktree is available.
Extract `default_worktree_path` as a separate public method on
`ProjectEnvironment` for testability and reuse. Add integration tests
verifying environment loading uses the project worktree directory.
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 30, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @derekparker on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-codeowner-coordinator zed-codeowner-coordinator bot requested review from a team, cameron1024 and reflectronic and removed request for a team March 30, 2026 19:01
@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Mar 30, 2026
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 30, 2026
@benbrandt benbrandt enabled auto-merge (squash) March 31, 2026 15:28
@benbrandt benbrandt merged commit f7ab907 into zed-industries:main Mar 31, 2026
38 checks passed
@derekparker derekparker deleted the fix/agent-env-from-project-worktree branch March 31, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants