更新 RTK 使用说明及 deploy.ps1 自动初始化 hook
- README: 修正 RTK 描述(token hook 而非 token 计数工具),补充 rtk gain/graph 用法 - deploy.ps1: 安装 RTK 后自动运行 rtk init -g --auto-patch,注册 Claude Code PreToolUse hook - deploy.ps1: cargo env 同时写入 ~/.bashrc 和 ~/.profile(修复 root login shell PATH) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -28,20 +28,10 @@ claude-dev-stack/
|
|||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
### ⚠️ 重要:首次 WSL2 用户初始化
|
### ℹ️ WSL2 默认用户
|
||||||
|
|
||||||
WSL2 Ubuntu **首次启动**会弹出提示创建用户:
|
本方案使用 **root** 作为 WSL2 默认用户(通过 `/etc/wsl.conf` 配置)。
|
||||||
|
WSL2 Ubuntu 首次启动若弹出用户创建提示,可直接跳过或按提示操作,deploy.ps1 会自动将默认用户切换为 root。
|
||||||
```
|
|
||||||
Provisioning the new WSL instance Ubuntu
|
|
||||||
Create a default Unix user account: <输入你的用户名,如 hornet>
|
|
||||||
New password: <输入密码>
|
|
||||||
Retype new password: <确认密码>
|
|
||||||
```
|
|
||||||
|
|
||||||
**必须先完成用户创建,再运行 `deploy.ps1`**,否则所有文件会安装到 `root` 用户下,部署后无法正常使用。
|
|
||||||
|
|
||||||
> 💡 如果已不小心在 OOBE 前运行了脚本,再次运行 `deploy.ps1` 即可自动用正确用户重新安装。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -361,21 +351,33 @@ claude-wsl
|
|||||||
|
|
||||||
### RTK (Rust Token Killer)
|
### RTK (Rust Token Killer)
|
||||||
|
|
||||||
|
RTK 作为 Claude Code 的 **PreToolUse hook** 运行,自动将 bash 命令重写为 `rtk` 等效命令,过滤噪音、压缩输出,减少 60–90% token 消耗。
|
||||||
|
|
||||||
|
`deploy.ps1` 会自动执行 `rtk init -g` 注册 hook,**重启 Claude Code 后即生效**。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 统计文件 token 数
|
# 验证 hook 安装状态
|
||||||
rtk myfile.txt
|
rtk init --show
|
||||||
|
|
||||||
# 从管道统计
|
# 查看 token 节省统计(需先在 Claude Code 中运行一些命令)
|
||||||
cat large_context.md | rtk
|
rtk gain
|
||||||
|
rtk gain --graph # ASCII 图表
|
||||||
|
rtk gain --history # 最近命令历史
|
||||||
|
|
||||||
# 分析代码文件
|
# 手动使用(无需 hook)
|
||||||
find . -name "*.cs" | xargs cat | rtk
|
rtk git status # 压缩 git status 输出
|
||||||
|
rtk cargo test # 只显示失败的测试
|
||||||
|
rtk grep "pattern" . # 分组搜索结果
|
||||||
```
|
```
|
||||||
|
|
||||||
### 故障排查 — rtk 安装失败
|
### 故障排查 — rtk 安装失败
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# 手动安装
|
||||||
cargo install --git https://github.com/rtk-ai/rtk
|
cargo install --git https://github.com/rtk-ai/rtk
|
||||||
|
|
||||||
|
# 手动初始化 hook
|
||||||
|
rtk init -g
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -675,6 +675,7 @@ rustc --version
|
|||||||
"@
|
"@
|
||||||
Invoke-WSL $installRustCmd
|
Invoke-WSL $installRustCmd
|
||||||
Invoke-WSL "grep -q 'cargo/env' ~/.bashrc || echo 'source ~/.cargo/env 2>/dev/null || true' >> ~/.bashrc" -IgnoreError | Out-Null
|
Invoke-WSL "grep -q 'cargo/env' ~/.bashrc || echo 'source ~/.cargo/env 2>/dev/null || true' >> ~/.bashrc" -IgnoreError | Out-Null
|
||||||
|
Invoke-WSL "grep -q 'cargo/env' ~/.profile || echo 'source ~/.cargo/env 2>/dev/null || true' >> ~/.profile" -IgnoreError | Out-Null
|
||||||
Write-OK "Rust 安装完成"
|
Write-OK "Rust 安装完成"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,6 +705,10 @@ CARGO_NET_GIT_FETCH_WITH_CLI=true cargo install --git https://github.com/rtk-ai/
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# rtk init -g:安装 Claude Code PreToolUse hook(幂等)
|
||||||
|
Invoke-WSL ". ~/.cargo/env 2>/dev/null; rtk init -g --auto-patch 2>/dev/null || true" -IgnoreError | Out-Null
|
||||||
|
Write-OK "rtk hook 已注册 (rtk init -g),重启 Claude Code 后生效"
|
||||||
|
|
||||||
# ══════════════════════════════════════════════════════════════
|
# ══════════════════════════════════════════════════════════════
|
||||||
# Step 8: PowerShell Profile 配置
|
# Step 8: PowerShell Profile 配置
|
||||||
# ══════════════════════════════════════════════════════════════
|
# ══════════════════════════════════════════════════════════════
|
||||||
|
|||||||
Reference in New Issue
Block a user