charmbracelet/crush · error

path does not exist: %s

Error message

path does not exist: %s

What it means

ListDirectoryTree stats the searchPath before listing. If os.Stat reports the path does not exist, the tool returns 'path does not exist: <path>'. This is a preflight existence check distinct from read-permission or walk errors.

Source

Thrown at internal/agent/tools/ls.go:140

				}
			}

			output, metadata, err := ListDirectoryTree(searchPath, params, lsConfig)
			if err != nil {
				return fantasy.NewTextErrorResponse(err.Error()), nil
			}

			return fantasy.WithResponseMetadata(
				fantasy.NewTextResponse(output),
				metadata,
			), nil
		},
	)
}

func ListDirectoryTree(searchPath string, params LSParams, lsConfig config.ToolLs) (string, LSResponseMetadata, error) {
	if _, err := os.Stat(searchPath); os.IsNotExist(err) {
		return "", LSResponseMetadata{}, fmt.Errorf("path does not exist: %s", searchPath)
	}

	depth, limit := lsConfig.Limits()
	maxFiles := cmp.Or(limit, maxLSFiles)
	files, truncated, err := fsext.ListDirectory(
		searchPath,
		params.Ignore,
		cmp.Or(params.Depth, depth),
		maxFiles,
	)
	if err != nil {
		return "", LSResponseMetadata{}, fmt.Errorf("error listing directory: %w", err)
	}

	metadata := LSResponseMetadata{
		NumberOfFiles: len(files),
		Truncated:     truncated,
	}

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Verify the path exists with os.Stat before calling.
  2. Correct typos; use an absolute path derived from the working directory.
  3. If the path may race with deletion, retry after re-checking existence.

Example fix

// before
ListDirectoryTree("/proj/src", params, cfg) // src was renamed to source
// after
ListDirectoryTree("/proj/source", params, cfg)
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(searchPath); os.IsNotExist(err) {
    return fmt.Errorf("path missing: %s", searchPath)
}

Type guard

func pathExists(p string) bool { _, err := os.Stat(p); return !os.IsNotExist(err) }

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "path does not exist") { /* correct path and retry */ }
}

Prevention

When it happens

Trigger: Calling ListDirectoryTree (public API) with a typo'd path, a deleted directory, or a path that only exists after symlink resolution that fails.

Common situations: Stale paths after a branch switch or git clean, typos in absolute paths, or paths deleted concurrently between the model's decision and the tool call.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/97896bf1a28d87eb. Report an issue: GitHub.