Skip to content

Expand ~ in path options from the config file - #8055

Open
harshbhx wants to merge 1 commit into
coder:mainfrom
harshbhx:fix/7051-expand-tilde-config
Open

harshbhx wants to merge 1 commit into
coder:mainfrom
harshbhx:fix/7051-expand-tilde-config

Conversation

@harshbhx

Copy link
Copy Markdown
Contributor

Fixes #7051

Summary

Expand a leading ~ in path options (such as user-data-dir and extensions-dir) so they work in config.yaml the same way they do on the command line.

Problem

The shell expands ~ in command-line arguments, but nothing expands it in values read from the config file. With

user-data-dir: ~/.config/code-server-data

the value reaches path.resolve as-is (src/node/cli.ts#L469) and is resolved against the current working directory. Depending on where code-server is started, the result is <cwd>/~/.config/code-server-data or /~/.config/..., which leads to errors like:

Unable to read file '/~/.config/code-server-user-data/extensions/extensions.json'

Solution

As suggested in the issue ("it would be nice if we manually expand it when we read the config"), path options now go through a small expandTilde helper before path.resolve:

  • ~ → the home directory
  • ~/foo (or ~\foo on Windows) → <home>/foo
  • everything else, including ~user/... and a ~ in the middle of a path, is left unchanged

Because the expansion happens in parse, it covers every option marked path: true (user-data-dir, extensions-dir, builtin-extensions-dir, cert, cert-key, socket, i18n), whether it comes from the CLI or the config file. CLI values are already expanded by the shell, so the change is a no-op for them.

Changes

File Change
src/node/util.ts Add expandTilde()
src/node/cli.ts Call expandTilde() before path.resolve() for path options
test/unit/node/util.test.ts Unit tests for expandTilde()
test/unit/node/cli.test.ts Test that parseConfigFile expands ~ in user-data-dir and extensions-dir

Before / After

config.yaml:

user-data-dir: ~/.config/code-server-data
Resolved user-data-dir (started from /srv)
Before /srv/~/.config/code-server-data
After /home/<user>/.config/code-server-data

How to test

  1. Put user-data-dir: ~/.config/code-server-data in ~/.config/code-server/config.yaml.
  2. cd /tmp && code-server
  3. Check that the data directory is ~/.config/code-server-data in your home and that no /tmp/~ directory was created.

Testing done

  • New tests in util.test.ts and cli.test.ts
  • cli and util unit test suites: 144/144 passing
  • The new config test fails when expandTilde is a no-op, so it covers the bug
  • prettier --check and eslint clean on the changed files
  • Not tested on Windows (the ~\ branch is covered only by the path.sep check)

Notes for reviewers

  • ~user expansion is intentionally not supported; it would need a user database lookup and isn't what the issue asks for.
  • Positional arguments (_) aren't path options and are unchanged.

The shell expands ~ in command-line arguments, but values read from
config.yaml were passed to path.resolve as-is, so
`user-data-dir: ~/.config/code-server-data` resolved to
`<cwd>/~/.config/code-server-data`.

Fixes coder#7051
Copilot AI balanced review requested due to automatic review settings October 14, 2026 07:45
@harshbhx
harshbhx requested a review from a team as a code owner October 14, 2026 07:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

Expand ~ from config

2 participants