# Fix agent servers loading environment from home dir instead of project dir \(\#52763\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/f7ab90721616d7c6ee84fa9bf10cdf925e8e9b1f)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: f7ab90721616d7c6ee84fa9bf10cdf925e8e9b1f

Requested commit: f7ab90721616d7c6ee84fa9bf10cdf925e8e9b1f

Commit: f7ab90721616d7c6ee84fa9bf10cdf925e8e9b1f

Tree: 8a76bc05a5d4b658a359a27a2971c47b7341204a

Author: Derek Parker

Committer: GitHub

## Message

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

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:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- Fixed default environment variable context for external agents
```

## Parents

- [0f173eb8ae049bc484a4e8a63213e49e17d61eab](https://git.cafe/gitcafe/zed/commit/0f173eb8ae049bc484a4e8a63213e49e17d61eab?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/f7ab90721616d7c6ee84fa9bf10cdf925e8e9b1f?format=markdown)
