Skip to content

cli: include the port in the ssh-terminfo cache key - #14472

Merged
jparise merged 2 commits into
ghostty-org:mainfrom
stepankandrushin:ssh-cache-port
Oct 3, 2026
Merged

jparise merged 2 commits into
ghostty-org:mainfrom
stepankandrushin:ssh-cache-port

Conversation

@stepankandrushin

@stepankandrushin stepankandrushin commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

The ssh-terminfo cache keyed destinations as user@hostname from ssh -G, ignoring the port. Two machines behind one address on different ports (e.g. user@host:2221 and user@host:2218) shared a key, so once the first was cached the terminfo install was skipped for the second, which still got TERM=xterm-ghostty without the terminfo installed.

The key now carries the port when it isn't 22: user@host:port, or user@[addr]:port for IPv6. Port 22 keeps the old user@host form, so existing caches stay valid.

+ssh-cache accepts the new form: a bare host query matches that host on every port, a bare host:port query that port for any user, and user@host:port one exact entry.

AI disclosure: the cause was found and the patch written with Claude Code (Claude Opus 5.5). Reviewed and tested by me.

Discussed in #14465.

The ssh-terminfo cache keyed destinations as user@hostname from `ssh -G`,
ignoring the port. Two machines behind one address on different ports
(e.g. user@host:2221 and user@host:2218) shared a key, so once the first
was cached the terminfo install was skipped for the second, which still
got TERM=xterm-ghostty without the terminfo installed.

The key now carries the port when it isn't 22: user@host:port, or
user@[addr]:port for IPv6. Port 22 keeps the old user@host form, so
existing caches stay valid.

`+ssh-cache` accepts the new form: a bare `host` query matches that host
on every port, a bare `host:port` query that port for any user, and
`user@host:port` one exact entry.

AI disclosure: the cause was found and the patch written with Claude
Code (Claude Opus 5.5). Reviewed and tested by me.
@ghostty-bot ghostty-bot Bot added the cli `ghostty` command-line interface label Sep 30, 2026
@jparise jparise self-assigned this Oct 1, 2026

@jparise jparise left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just spotted a few small things.

Comment thread src/cli/ssh_cache.zig Outdated
Comment thread src/cli/ssh-cache/DiskCache.zig Outdated
Comment thread src/cli/ssh-cache/DiskCache.zig Outdated
- matchesQuery treats a missing port as port 22.
- isValidPort uses std.ascii.isDigit and rejects leading zeros, so
  host:22 and host:022 can't become distinct keys.
@stepankandrushin

Copy link
Copy Markdown
Contributor Author

Thanks for the review! All three addressed:

  • matchesQuery now treats a missing port as port 22, so host:22 and user@host:22 match user@host entries (and vice versa).
  • Switched to std.ascii.isDigit.
  • Ports with leading zeros are rejected, so host:022 is no longer a valid key.

Tests added for each.

@jparise
jparise merged commit befcdfd into ghostty-org:main Oct 3, 2026
@github-actions github-actions Bot added this to the 1.4.0 milestone Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli `ghostty` command-line interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants