feat: Semantic History — resolve bare filenames against OSC 7 CWD on click
JI
7d ago+67+67+01234567890123456789-4-4-0123456789
Summary
When a user clicks a bare filename (e.g. README.md, src/main.py) in the terminal, resolve it against the terminal's current working directory (reported via OSC 7) and open it if the file exists on disk.
This is the terminal equivalent of iTerm2's Semantic History feature, and the #1 workflow gap for AI coding agent users (Claude Code, Codex, etc.) who frequently see bare filenames in output.
Changes
resolveTerminalOpenURLTarget()now accepts an optionalworkingDirectoryparameter- Before falling through to browser URL heuristics (
resolveBrowserNavigableURL), it checks whetherCWD/clicked_textresolves to an existing file viaFileManager.default.fileExists(atPath:) - Line/column suffixes (e.g.
file.swift:42:10) are stripped before the file existence check GHOSTTY_ACTION_OPEN_URLhandler now retrieves the terminal's CWD fromworkspace.panelDirectories[surfaceId](per-panel) orworkspace.currentDirectory(workspace-level fallback)
Before / After
| Scenario | Before | After |
|---|---|---|
Click README.md | Opens https://README.md (bug #1154) or no action | Opens /Users/me/project/README.md in editor |
Click src/main.py:42 | No action | Opens /Users/me/project/src/main.py in editor |
Click /absolute/path.md | Opens correctly ✅ | No change ✅ |
Click https://google.com | Opens correctly ✅ | No change ✅ |
Click nonexistent.xyz | Falls through | Falls through (file doesn't exist, no change) |
How it works
User clicks "file.md" in terminal output
→ resolveTerminalOpenURLTarget("file.md", workingDirectory: "/Users/me/project")
→ Not an absolute path
→ CWD check: does /Users/me/project/file.md exist?
→ Yes → return .external(URL(fileURLWithPath: "/Users/me/project/file.md"))
→ NSWorkspace.shared.open() → opens in default editor
Why this matters
AI coding agents output bare filenames constantly:
I've updated the following files:
proposal_draft.md
workflow_v2.md
src/coordinator.ts
In iTerm2, every one of these is Cmd+clickable. In cmux, none of them are. This PR fixes that.
Related
- Closes #2199
- Related to #1154 (relative paths misrouted to browser URL — this PR also fixes that case when the file exists locally)
Test plan
- Click bare filename in terminal output → opens in editor
- Click
file.swift:42→ opens file (line number stripped) - Click absolute path → still works as before
- Click URL → still works as before
- Click non-existent filename → falls through to existing behavior
- Works in split panes with different CWDs
🤖 Generated with Claude Code
Summary by CodeRabbit
- Bug Fixes
- Improved file path resolution when opening files from terminal output: relative paths and bare filenames (including trailing :line or :line:column numeric suffixes) are now resolved against the terminal's working directory, and files are opened only if the resolved path exists.
- Other
- Enhanced debug logging for open-from-terminal actions to include the resolved working directory.