# terminal_view: Fix terminal opening in root directory when editing single file corktree \(\#42953\) · gitcafe/zed

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

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

Visibility: public

Requested revision: f17d2c92b6f8982d3be9d5858edb008efe1112f8

Requested commit: f17d2c92b6f8982d3be9d5858edb008efe1112f8

Commit: f17d2c92b6f8982d3be9d5858edb008efe1112f8

Tree: 66c5fd431302ed18e73994f544425cef90f5519e

Author: Engin Açıkgöz

Committer: GitHub

## Message

```
terminal_view: Fix terminal opening in root directory when editing single file corktree (#42953)

Fixes #42945

## Problem
When opening a single file via command line (e.g., `zed
~/Downloads/file.txt`), the terminal panel was opening in the root
directory (/) instead of the file's directory.

## Root Cause
The code only checked for active project directory, which returns None
when a single file is opened. Additionally, file worktrees weren't
handling parent directory lookup.

## Solution
Added fallback logic to use the first project directory when there's no
active entry, and made file worktrees return their parent directory
instead of None.

## Testing
- All existing tests pass
- Added test coverage for file worktree scenarios
- Manually tested with `zed ~/Downloads/file.txt` - terminal now opens
in correct directory

This improves the user experience for users who frequently open single
files from the command line.

## Release Notes

- Fixed terminal opening in root directory when editing single files
from the command line
```

## Parents

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

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