← 返回 Skills 市场
sunliangzesmile

Cache Migration

作者 SunliangzeSmile · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
70
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install cache-migration
功能描述
本技能用于将 Windows 系统上常见开发工具(Yarn、VSCode)的缓存和插件目录迁移到非系统盘(如 E 盘),通过 NTFS Junction + 启动脚本修改实现对应用完全透明的重定向,无需修改任何应用配置。当用户请求"迁移缓存到 E 盘"、"将 VSCode/Yarn 缓存移到 D/E 盘"、"释放...
使用说明 (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
安全使用建议
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.
能力评估
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.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install cache-migration
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /cache-migration 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
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.
元数据
Slug cache-migration
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Cache Migration 是什么?

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

如何安装 Cache Migration?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install cache-migration」即可一键安装,无需额外配置。

Cache Migration 是免费的吗?

是的,Cache Migration 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Cache Migration 支持哪些平台?

Cache Migration 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Cache Migration?

由 SunliangzeSmile(@sunliangzesmile)开发并维护,当前版本 v1.0.0。

💬 留言讨论