# project: Restart context servers when their working directory changes \(\#61365\) · gitcafe/zed

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

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

Visibility: public

Requested revision: ac44e9f5df57a9e1a9d6deacddead974edabc8e7

Requested commit: ac44e9f5df57a9e1a9d6deacddead974edabc8e7

Commit: ac44e9f5df57a9e1a9d6deacddead974edabc8e7

Tree: 915b1351977eb42e5a29ce0570450c79335ba494

Author: Apoorva Verma

Committer: GitHub

## Message

```
project: Restart context servers when their working directory changes (#61365)

# Objective

Fixes #60879

Open Zed from Finder/Dock and the agent's MCP servers run from `/`
instead of your project. They get spawned before any worktree exists, so
there's no root to give them and they grab Zed's own cwd. The worktree
shows up right after, but `maintain_servers` only restarts on a config
change and the working dir isn't part of the config, so nothing kicks
it.

## Solution

Track each server's working dir and restart when it changes. Direction 1
from @SomeoneToIgnore's triage. Could also defer startup until the first
worktree lands, happy to switch if you'd rather.

## Testing

Added a test: file-only worktree (root is `None`) → start server → add a
real worktree → server restarts. Fails without the fix.
- Fixed agent MCP servers running from the wrong directory when started
before a worktree was available
```

## Parents

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

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