Skip to content

Conversation

@dbrtly
Copy link

@dbrtly dbrtly commented Nov 9, 2025

XDG configurations bring flexibility to files previously written only to ~/.gemini directory.

Summary

Following XDG conventions for the path to gemini's configuration makes it easy to use Gemini as a developer tool while developing gemini and enables a clean home directory for users who like that.

Details

Preserved the existing behaviour while enabling compatibility with environment variables (eg. $XDG_CONFIG_HOME) on all platforms and if neither ~/.gemini/ exists nor the environment variables are set, Gemini will use the platform-specific location for cache/config/data/state files.

Related Issues

closes #1825

How to Validate

for config:
if ~/.gemini/ exists and $XDG_CONFIG_HOME is not set then use ~/.gemini/.
if ~/.gemini/ does not exist and $XDG_CONFIG_HOME is set then use $XDG_CONFIG_HOME/config/
if ~/.gemini/ does not exist and $XDG_CONFIG_HOME is not set then use platform-specific location.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • [ X] Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • [ X] MacOS
      • [ X] npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@google-cla
Copy link

google-cla bot commented Nov 9, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@dbrtly dbrtly force-pushed the xdg branch 2 times, most recently from 96415c9 to e05b9b6 Compare November 9, 2025 20:48
@dbrtly dbrtly mentioned this pull request Nov 10, 2025
@dbrtly dbrtly marked this pull request as ready for review November 12, 2025 10:53
@dbrtly dbrtly requested a review from a team as a code owner November 12, 2025 10:53
@cornmander cornmander self-requested a review November 12, 2025 16:29
};

export default function envPaths(name: string) {
if (typeof name !== 'string') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't think this is necessary as envPaths only accepts string

Copy link
Author

Choose a reason for hiding this comment

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

removed as suggested

return {
...actual,
default: actual,
homedir: vi.fn(() => path.join('/mock', 'home')),
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of doing this, can you capture the actual value and then use that to compare in the test? see below

Copy link
Author

Choose a reason for hiding this comment

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

removed as suggested

@@ -318,7 +324,12 @@ describe('MemoryTool', () => {
expect(result).not.toBe(false);

if (result && result.type === 'edit') {
const expectedPath = path.join('~', GEMINI_DIR, 'GEMINI.md');
const expectedPath = path.join(
'/mock',
Copy link
Collaborator

Choose a reason for hiding this comment

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

capture expectedHome = os.homedir() then check that expectedPath starts with expectedHome

Copy link
Author

Choose a reason for hiding this comment

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

refactored as suggested

};
};

export default function envPaths(name: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a debugLogger statement here? I worry about users ending up intermittently using the XDG paths vs. homedir paths because XDG paths aren't used consistently, for example in cronjobs.

Copy link
Author

Choose a reason for hiding this comment

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

Do we still need this with the reduced scope?

@dbrtly dbrtly force-pushed the xdg branch 2 times, most recently from 524fe01 to 4c5cf7b Compare November 15, 2025 13:45
@dbrtly
Copy link
Author

dbrtly commented Nov 15, 2025

I reflected on the code and was unhappy about the complexity. Only XDG nerds are going to care about this and that the change should prioritise the experience of the majority of users.

The XDG Base Directory Specification does not prescribe os-specific paths for windows or macos. So I reverted to simpler code that respects the XDG environment variables if they are set and if not set, ignores XDG continuing with the established practice of $HOME/.gemini

A consequence of this version is simpler debugging if some but not all env var are set.

@daniel-bartley
Copy link

for config:
if ~/.gemini/ exists and $XDG_CONFIG_HOME is not set then use ~/.gemini/.
if $XDG_CONFIG_HOME is set then use $XDG_CONFIG_HOME/gemini/

@marmitar
Copy link

marmitar commented Nov 17, 2025

Hi, I decided to test this today with npx -y @google/gemini-cli@github:dbrtly/gemini-cli#xdg. I noticed that some places still use GEMINI_DIR. Specifically, .env and context.fileName are always loaded from ~/.gemini, even with XDG_CONFIG_HOME set and the files present at $XDG_CONFIG_HOME/gemini. OAuth and settings.json are loaded correctly, though.

@dbrtly
Copy link
Author

dbrtly commented Nov 19, 2025

Hi, I decided to test this today with npx -y @google/gemini-cli@github:dbrtly/gemini-cli#xdg. I noticed that some places still use GEMINI_DIR. Specifically, .env and context.fileName are always loaded from ~/.gemini, even with XDG_CONFIG_HOME set and the files present at $XDG_CONFIG_HOME/gemini. OAuth and settings.json are loaded correctly, though.

Thanks @marmitar. I expanded the scope to every file that referenced GEMINI_DIR. Turns out that is quite a few.

@dbrtly dbrtly requested a review from cornmander November 19, 2025 11:55
@dbrtly
Copy link
Author

dbrtly commented Nov 19, 2025

@cornmander after a break, have spotted a few things I have todo before ready for you.

@dbrtly
Copy link
Author

dbrtly commented Nov 28, 2025

Somehow, there a failing tests on main.

I introduced new functions
https://github.com/dbrtly/gemini-cli/blob/xdg/packages/core/src/config/storage.ts#L33-L48

And amend the code to use them.

Will update the implementation of those with conditional logic in next PR and add tests on these functions

@dbrtly dbrtly marked this pull request as draft December 1, 2025 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

respect XDG specs

5 participants