Help Center/ CodeArts Agent/ FAQs/ MCP Service/ How Do I Resolve the Issue That uv Directories Occupy Too Much Disk Space?
Updated on 2026-07-29 GMT+08:00

How Do I Resolve the Issue That uv Directories Occupy Too Much Disk Space?

Symptom

The system disk space is insufficient. Troubleshooting reveals that the uv or uvx-related directories occupy a large amount of storage space, and their size continues to grow over time.

Cause Analysis

An MCP server that uses uv or uvx for startup is installed. uv is a high-performance Python package management tool commonly used to run MCP servers. The disk space is primarily consumed by the following two parts:

  • uv installation files: This part usually occupies a small amount of space and can be ignored.
  • uv global cache directory: The mechanism of the uv tool is the main cause for high disk space usage. uv uses a global cache policy. When you install or run Python packages using uv, the downloaded dependencies, compilation cache, and virtual environments are cached locally. By default, uv does not automatically clear historical cache. As the number of MCP servers you use increases or versions are updated, cache files of earlier versions accumulate, causing disk space usage to gradually increase.

Solution

To resolve the issue of uv cache occupying drive C, you can either periodically clear the cache or configure environment variables to migrate the cache directory to another drive.

Periodically Clearing the uv Cache

Clearing the uv cache is relatively simple. You only need to run one of the following commands on any CLI:

  • uv cache prune

    This command only deletes unnecessary cache content and does not affect caches currently in use. It is completely safe and highly recommended as your first option.

  • uv cache clean

    This command clears all caches. Use this command only if you find that the space released by the prune command is insufficient.

If an exception occurs during command execution (for example, file deletion fails due to excessive cache size), you can manually clear the cache directory by deleting the contents of the %USERPROFILE%/AppData/Local/uv/cache folder.

Deleting the uv cache will not cause Python exceptions, but the next run (for example, when reconnecting to MCP) may be slightly slower. You are advised to use uv cache prune to delete only unnecessary content. If the message "Cache is currently in-use, waiting for other uv processes to finish (use --force to override)" is displayed during the cleanup, you can exit CodeArts Agent or use the task manager to locate and stop other running uv processes. After the processes are stopped, the cleanup will automatically continue.

Configuring Environment Variables to Prevent the uv Cache from Occupying Drive C

The default cache path of uv is %USERPROFILE%/AppData/Local/uv/cache, which may occupy a large amount of space on drive C. You can set the environment variable UV_CACHE_DIR to customize the cache storage location. The following are two recommended configuration methods:

  • Method 1: Configuring System-Level Environment Variables
    1. Open the System Properties dialog box and click Environment Variables on the Advanced tab.
    2. In the system variables area, click New to create a system variable named UV_CACHE_DIR.
    3. Click OK to return to the Environment Variables page, and then click OK to complete the configuration.

      This method routes all uv cache data across the system to the specified location, preventing the data from occupying space on drive C. However, it still occupies the space of the specified directory. Therefore, you are still advised to periodically clear the data.

  • Method 2: Specifying Environment Variables in the MCP Configuration

    If you do not want to modify the system-level uv cache directory, you can configure a separate cache path for MCP. The configuration procedure is as follows:

    Find the corresponding MCP service in the mcp_settings.json file and add the "UV_CACHE_DIR": "./.uv-cache" environment variable under the environment node. (If the environment node does not exist, create it manually.) ./.uv-cache indicates that a cache folder is created in the current project directory. This relative path isolates the cache within the project, but the cache cannot be shared between projects. You can also change it to an absolute path as required.

    {
        "mcp": {
            "Demo-Mcp-Server": {
                "enabled": true,
                "timeout": 5000,
                "command": ["uvx", "--default-index", "https://mirrors.tools.huawei.com/pypi/simple", "--allow-insecure-host", "mirrors.tools.huawei.com", "--from", "https://cmc.centralrepo.rnd.huawei.com/xxx_demo.tar.gz", "mcp-server-demo"],
                "environment": {
                    "UV_CACHE_DIR": "./.uv-cache"
                },
                "type": "local"
            }
        }
    }