← Back to Skills Marketplace
sunliangzesmile

Cache Migration

by SunliangzeSmile · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
70
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install cache-migration
Description
本技能用于将 Windows 系统上常见开发工具(Yarn、VSCode)的缓存和插件目录迁移到非系统盘(如 E 盘),通过 NTFS Junction + 启动脚本修改实现对应用完全透明的重定向,无需修改任何应用配置。当用户请求"迁移缓存到 E 盘"、"将 VSCode/Yarn 缓存移到 D/E 盘"、"释放...
README (SKILL.md)

\r \r

Cache Migration\r

\r

Overview\r

\r 将 Yarn、VSCode 等开发工具的缓存和插件目录从系统盘(C 盘)迁移到数据盘(E/D 盘),释放 C 盘空间。\r \r 核心方案:NTFS Junction(目录联接)+ 启动脚本修改,对应用完全透明,无需任何配置改动。\r \r 迁移项目:\r

  • Yarn 全局缓存(AppData\Local\Yarn\Cache)\r
  • VSCode 缓存目录(Cache、CachedData、GPUCache 等 9 个)\r
  • VSCode 插件扩展(.vscode\extensions)\r \r

Workflow\r

\r

Step 0: 确认目标路径\r

\r 确认目标盘符存在且有足够空间:\r

ls "E:/AppData/Local" 2>/dev/null || echo "目录不存在"\r
du -sh "C:/Users/\x3C用户名>/AppData/Roaming/Code/"    # VSCode 缓存大小\r
du -sh "C:/Users/\x3C用户名>/.vscode/extensions/"     # VSCode 插件大小\r
du -sh "C:/Users/\x3C用户名>/AppData/Local/Yarn/Cache/v6"  # Yarn 缓存大小\r
```\r
\r
### Step 1: 创建目标根目录\r
\r
```bash\r
mkdir -p "E:/AppData/Local/VSCode"\r
mkdir -p "E:/AppData/Local/yarn-cache"   # Yarn 迁移用\r
```\r
\r
### Step 2: 迁移 Yarn 缓存\r
\r
**配置新路径**(执行一条命令即可):\r
```bash\r
yarn config set cache-folder "E:\\AppData\\Local\\yarn-cache"\r
```\r
\r
**验证**:\r
```bash\r
yarn cache dir\r
# 期望输出: E:\AppData\Local\yarn-cache\v6\r
```\r
\r
**迁移旧数据**(可选,避免重新下载):\r
```bash\r
cp -r "C:/Users/\x3C用户名>/AppData/Local/Yarn/Cache/v6/"* "E:/AppData/Local/yarn-cache/v6/"\r
```\r
\r
### Step 3: 迁移 VSCode 缓存(Junction 方案)\r
\r
VSCode 缓存目录无法通过配置项修改,必须使用 NTFS Junction。\r
\r
#### 3.1 复制缓存数据到 E 盘\r
\r
```powershell\r
$dstBase = "E:\AppData\Local\VSCode"\r
$cacheDirs = @(\r
    "Cache",\r
    "CachedData",\r
    "CachedExtensionVSIXs",\r
    "Code Cache",\r
    "GPUCache",\r
    "DawnGraphiteCache",\r
    "DawnWebGPUCache",\r
    "CachedProfilesData",\r
    "CachedConfigurations"\r
)\r
\r
foreach ($dir in $cacheDirs) {\r
    $src = "C:\Users\\x3C用户名>\AppData\Roaming\Code\$dir"\r
    $dst = "E:\AppData\Local\VSCode\$dir"\r
    if (Test-Path $src) {\r
        Copy-Item -Path $src -Destination $dst -Recurse -Force\r
        Write-Host "已复制: $dir"\r
    }\r
}\r
```\r
\r
#### 3.2 删除原目录并创建 Junction\r
\r
**⚠️ 必须先确认数据已复制完成再执行删除操作**\r
\r
```powershell\r
foreach ($dir in $cacheDirs) {\r
    $srcPath = "C:\Users\\x3C用户名>\AppData\Roaming\Code\$dir"\r
    $dstPath = "E:\AppData\Local\VSCode\$dir"\r
\r
    if (Test-Path $srcPath) {\r
        Remove-Item -Path $srcPath -Recurse -Force\r
        cmd /c "mklink /J `"$srcPath`" `"$dstPath`""\r
        Write-Host "Junction OK: $dir"\r
    }\r
}\r
```\r
\r
#### 3.3 验证 Junction\r
\r
```powershell\r
foreach ($dir in $cacheDirs) {\r
    $item = Get-Item "C:\Users\\x3C用户名>\AppData\Roaming\Code\$dir" -Force\r
    if ($item.Attributes -band [System.IO.FileAttributes]::ReparsePoint) {\r
        Write-Host "Junction OK: $dir"\r
    } else {\r
        Write-Host "FAIL: $dir"\r
    }\r
}\r
```\r
\r
### Step 4: 迁移 VSCode 插件(Junction 方案)\r
\r
#### 4.1 复制插件数据\r
\r
```bash\r
mkdir -p "E:/AppData/Local/VSCode/extensions"\r
cp -r "C:/Users/\x3C用户名>/.vscode/extensions/"* "E:/AppData/Local/VSCode/extensions/"\r
```\r
\r
#### 4.2 删除原目录并创建 Junction\r
\r
```powershell\r
$srcPath = "C:\Users\\x3C用户名>\.vscode\extensions"\r
$dstPath = "E:\AppData\Local\VSCode\extensions"\r
\r
Remove-Item -Path $srcPath -Recurse -Force\r
cmd /c "mklink /J `"$srcPath`" `"$dstPath`""\r
Write-Host "Junction OK: extensions"\r
```\r
\r
### Step 5: 修改 VSCode 启动脚本(显式配置)\r
\r
即使有 Junction,显式配置 `--extensions-dir` 参数可以双重保障。\r
\r
#### 5.1 查找 VSCode 安装位置\r
\r
```bash\r
which code\r
# 通常位于: D:\Programs\Microsoft VS Code\bin\code.cmd\r
```\r
\r
#### 5.2 修改 code.cmd(Windows CMD 启动)\r
\r
```batch\r
# 查找 code.cmd 内容(示例路径)\r
# D:\Programs\Microsoft VS Code\bin\code.cmd\r
\r
# 在调用 Code.exe 的行末尾添加 --extensions-dir 参数:\r
"%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" --extensions-dir "E:\AppData\Local\VSCode\extensions" %*\r
```\r
\r
如果文件被 VSCode 进程锁定(EBUSY),使用 PowerShell 强制写入:\r
```powershell\r
$src = "D:\Programs\Microsoft VS Code\bin\code.cmd"\r
$newContent = '@echo off\r
setlocal\r
set VSCODE_DEV=\r
set ELECTRON_RUN_AS_NODE=1\r
"%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" --extensions-dir "E:\AppData\Local\VSCode\extensions" %*\r
IF %ERRORLEVEL% NEQ 0 EXIT /b %ERRORLEVEL%\r
endlocal\r
'\r
[System.IO.File]::WriteAllText($src, $newContent, [System.Text.Encoding]::UTF8)\r
```\r
\r
#### 5.3 修改 code(Git Bash / WSL 启动)\r
\r
```sh\r
# 在 Electron 调用行末尾添加 --extensions-dir:\r
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --extensions-dir "E:\AppData\Local\VSCode\extensions" "$@"\r
```\r
\r
### Step 6: 修改 VSCode settings.json(可选,双重保障)\r
\r
在用户设置中添加:\r
```json\r
"extensionsPath": "E:/AppData/Local/VSCode/extensions"\r
```\r
\r
### Step 7: 全面验证\r
\r
```powershell\r
Write-Host "=== 1. Yarn 缓存 ==="\r
yarn cache dir\r
\r
Write-Host ""\r
Write-Host "=== 2. VSCode 缓存 Junction ==="\r
$cacheDirs = @("Cache","CachedData","CachedExtensionVSIXs","Code Cache","GPUCache","DawnGraphiteCache","DawnWebGPUCache","CachedProfilesData","CachedConfigurations")\r
foreach ($dir in $cacheDirs) {\r
    $item = Get-Item "C:\Users\\x3C用户名>\AppData\Roaming\Code\$dir" -Force\r
    if ($item.Attributes -band [System.IO.FileAttributes]::ReparsePoint) {\r
        Write-Host "Junction OK: $dir"\r
    } else {\r
        Write-Host "FAIL: $dir"\r
    }\r
}\r
\r
Write-Host ""\r
Write-Host "=== 3. VSCode 插件 Junction ==="\r
$item = Get-Item "C:\Users\\x3C用户名>\.vscode\extensions" -Force\r
if ($item.Attributes -band [System.IO.FileAttributes]::ReparsePoint) { "OK" } else { "FAIL" }\r
\r
Write-Host ""\r
Write-Host "=== 4. code.cmd 修改 ==="\r
if ((Get-Content "D:\Programs\Microsoft VS Code\bin\code.cmd" -Raw) -match "extensions-dir") { "OK" } else { "FAIL" }\r
\r
Write-Host ""\r
Write-Host "=== 5. E 盘数据量 ==="\r
(Get-ChildItem "E:\AppData\Local\VSCode" -Recurse -Force | Measure-Object -Property Length -Sum).Sum / 1MB\r
```\r
\r
### Step 8: 清理 C 盘残留\r
\r
**Yarn**:执行 `yarn config set` 后旧缓存目录通常自动清空,若仍存在可手动删除:\r
```bash\r
rd /s /q "C:\Users\\x3C用户名>\AppData\Local\Yarn\Cache"\r
```\r
\r
**VSCode**:Junction 方案中 C 盘原目录已全部替换为链接,无实体残留,无需额外清理。\r
\r
## Resources\r
\r
### scripts/\r
\r
- `migrate-vscode-cache.ps1` — VSCode 缓存目录批量 Junction 迁移脚本(输入源路径和目标路径即可执行)\r
- `migrate-vscode-ext.ps1` — VSCode 插件目录 Junction 迁移脚本\r
- `verify-migration.ps1` — 全面验证脚本,检查所有 Junction 和配置文件\r
Usage Guidance
Review the scripts carefully before running them. Update the username and drive paths, close VSCode, back up the original VSCode extension/cache folders and launcher files, confirm the copy succeeded, and make sure you know how to remove the junctions and restore the original folders if anything fails.
Capability Assessment
Purpose & Capability
The described capability matches the stated goal of moving VSCode and Yarn cache/extension directories to another drive, but this necessarily involves high-impact local file operations.
Instruction Scope
The included scripts perform recursive forced deletion after copy steps that suppress copy errors, without an interactive confirmation, backup, checksum, or rollback path.
Install Mechanism
There is no install spec and no external dependency installation, but the metadata under-declares the Windows/PowerShell/cmd/Yarn environment assumptions and the bundled executable scripts.
Credentials
The workflow uses hard-coded Windows profile and drive paths, defaults to the Administrator profile in scripts, and can modify VSCode launcher files, which may affect the wrong profile or break the local development environment if used as-is.
Persistence & Privilege
The skill creates persistent NTFS junctions and documents persistent VSCode launcher changes, but does not provide a clear undo or restoration procedure.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install cache-migration
  3. After installation, invoke the skill by name or use /cache-migration
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Initial release of cache-migration: - Provides a workflow to migrate Yarn and VSCode caches and extensions from the system drive (C:) to a data drive (E:/D:), freeing up space. - Uses NTFS Junctions and startup script modification for transparent directory redirection without requiring application configuration changes. - Supports migration for Yarn global cache, multiple VSCode cache directories, and VSCode extensions. - Includes detailed steps for verifying successful migration and cleaning up residual data. - Supplies example migration and verification scripts in the resources section.
Metadata
Slug cache-migration
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is Cache Migration?

本技能用于将 Windows 系统上常见开发工具(Yarn、VSCode)的缓存和插件目录迁移到非系统盘(如 E 盘),通过 NTFS Junction + 启动脚本修改实现对应用完全透明的重定向,无需修改任何应用配置。当用户请求"迁移缓存到 E 盘"、"将 VSCode/Yarn 缓存移到 D/E 盘"、"释放... It is an AI Agent Skill for Claude Code / OpenClaw, with 70 downloads so far.

How do I install Cache Migration?

Run "/install cache-migration" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Cache Migration free?

Yes, Cache Migration is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Cache Migration support?

Cache Migration is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Cache Migration?

It is built and maintained by SunliangzeSmile (@sunliangzesmile); the current version is v1.0.0.

💬 Comments