Bug: tildeifyPath treats sibling home directories as the current home (missing path-separator bound)

Open Beginner friendly
#29,175 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
cli

Research direction

Start in packages/core/src/utils/paths.ts and inspect the tildeifyPath() implementation and its callers in Footer.tsx and BackgroundTaskDisplay.tsx. Add focused coverage in packages/core/src/utils/paths.test.ts for exact home paths, child paths, sibling prefixes, and Windows paths; done means only the home directory and its descendants are tilde-prefixed.

Written by the indexing model from the issue text.

Description

area/core effort/small kind/bug priority/p2 status/bot-triaged
What happened?

tildeifyPath() uses path.startsWith(homeDir) and then path.replace(homeDir, '~'). There is no check that the match is a full path segment.

If homedir() is /Users/al (or C:\Users\Al on Windows):

  • /Users/al/proj~/proj (correct)
  • /Users/albert/proj~bert/proj (wrong)
  • /Users/al~ (correct)

startsWith('/Users/al') is true for /Users/albert/..., so a different user's (or a longer username's) directory is displayed as under ~.

Used in the CLI footer and background-task display (Footer.tsx, BackgroundTaskDisplay.tsx). packages/core/src/utils/paths.test.ts never tests this function.

Repro (unit-level):

  1. Stub homedir() / GEMINI_CLI_HOME to /Users/al.
  2. Call tildeifyPath('/Users/albert/Documents/app').
  3. Actual: ~bert/Documents/app. Expected: /Users/albert/Documents/app unchanged.
What did you expect to happen?

Only the home directory itself, or paths under home + path.sep, should be tilde-prefixed.

Sibling prefixes (/Users/albert when home is /Users/al) must be left unchanged.

Client information

Reproduced from source on current main. Platform: macOS.
CLI Version: 0.59.0-nightly.20260825.g812f7a2bc

Login information

Not auth-related. Display-path helper in packages/core/src/utils/paths.ts.

Anything else we need to know?

Suggested fix: treat as home only when
p === home or p.startsWith(home + path.sep)
(and on Windows also home + '/' if callers pass forward slashes). Then replace that exact prefix with ~.

Add unit tests in paths.test.ts for:

  • exact home → ~
  • child of home → ~/...
  • sibling prefix (/Users/al vs /Users/albert) → unchanged
  • Windows C:\Users\Al vs C:\Users\Albert

I'd like to send a focused PR with tests after this is labeled help wanted.

Dominant language
TypeScript
Stars
107k
Forks
14.6k
Avg merge
2d 4h
Merged PRs (30d)
43

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google-gemini/gemini-cli

All issues in google-gemini/gemini-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.