asdf-vm/asdf · error

unable to fetch current directory: %w

Error message

unable to fetch current directory: %w

What it means

installCommand calls os.Getwd() to determine the directory whose .tool-versions should drive installation. If the current working directory cannot be determined (e.g. it was deleted or lacks permissions), the error is wrapped as "unable to fetch current directory".

Source

Thrown at internal/cli/cli.go:1096

	if err != nil {
		logger.Printf("failed to update %s due to error: %s\n", pluginName, err)

		return
	}

	logger.Printf("updated %s to ref %s\n", pluginName, updatedToRef)
}

func installCommand(logger *log.Logger, toolName, version string, keepDownload bool) error {
	conf, err := config.LoadConfig()
	if err != nil {
		logger.Printf("error loading config: %s", err)
		return err
	}

	dir, err := os.Getwd()
	if err != nil {
		return fmt.Errorf("unable to fetch current directory: %w", err)
	}

	if toolName == "" {
		// Install all versions
		errs := versions.InstallAll(conf, dir, os.Stdout, os.Stderr)
		if len(errs) > 0 {
			for _, err := range errs {
				// Don't print error if no version set, this just means the current
				// dir doesn't use a particular plugin that is installed.
				if _, ok := err.(versions.NoVersionSetError); ok {
					continue
				}

				if _, ok := err.(versions.UninstallableVersionError); ok {
					msg := fmt.Sprintf("skipping %s\n", err.Error())
					os.Stderr.Write([]byte(msg))
					continue
				}

View on GitHub (pinned to 074a1722ca)

Solutions

  1. `cd` to a valid existing directory (e.g. `cd $(pwd -P)` or cd out and back in) and retry.
  2. Recreate the deleted directory or restore its mount.
  3. Check filesystem permissions on the current directory.
  4. Use `asdf install <plugin> <version>` with explicit tool/version from a valid directory.

Example fix

# before (cwd deleted)
asdf install
# after
cd /path/to/project && asdf install
Defensive patterns

Strategy: validation

Validate before calling

if [ ! -d "$(pwd)" ]; then echo "cwd invalid"; exit 1; fi
asdf install

Try / catch

if ! asdf install 2>&1 | grep -q 'unable to fetch current directory'; then :; else cd "$PROJECT_DIR" && asdf install; fi

Prevention

When it happens

Trigger: Running `asdf install` (or `asdf install <tool> <version>`) from a directory that has been deleted while the shell still sits in it, or a directory the user cannot stat.

Common situations: Another terminal/process removed the working directory (common after checking out/cleaning build dirs); running inside a container where the mount disappeared; permission churn on the cwd.

Related errors


AI-assisted analysis of asdf-vm/asdf@074a1722ca (2026-08-30). Data as JSON: /api/errors/7b68bf2769c1fcbe. Report an issue: GitHub.