突破 Claude Code Pro 限制的优化技巧
工作流优化分享,展示如何充分利用 Pro 的功能和限制实现自动化处理
工作流优化分享,展示如何充分利用 Pro 的功能和限制实现自动化处理
一个 shell 脚本工具:当 Claude CLI 的使用限制解除后,自动恢复 Claude 任务;也可以等待指定时间后执行自定义 shell 命令。它能够检测 Claude 的使用限制,智能等待,并自动恢复任务执行。
该脚本执行 Claude 命令时会使用 --dangerously-skip-permissions 标志,并且可以执行任意 shell 命令。这意味着:
该脚本特别适合在以下开发场景中使用 Claude Code:
任务因使用限制而中断:Claude Code 显示 Claude usage limit reached.,但任务尚未全部完成
自动恢复任务:只需在项目根目录运行 claude-auto-resume;使用限制解除后,脚本会自动让 Claude Code 继续执行此前尚未完成的任务
执行自定义命令:等待使用限制解除后执行任意 shell 命令,适用于重启服务、运行构建或处理数据
🔄 自动检测 Claude CLI 使用限制
⏰ 智能等待并显示倒计时
🚀 自动恢复任务
🔧 等待结束后执行自定义命令
🛡️ 提供安全警告和取消选项
🔗 支持复杂命令,包括管道、重定向和操作符
🧪 内置测试模式,方便开发和验证
🖥️ 跨平台支持,包括 Linux、macOS 和 Windows PowerShell
📦 零外部依赖,只需要标准 Unix 工具
Linux/macOS 的安装步骤与原始上游仓库完全相同,以下内容保持不变。
wget -qO- https://raw.githubusercontent.com/terryso/claude-auto-resume/refs/heads/develop/claude-auto-resume.sh | sudo tee /usr/local/bin/claude-auto-resume >/dev/null && sudo chmod +x /usr/local/bin/claude-auto-resume
# Global installation
sudo make install
# Install to custom location
sudo make install PREFIX=/opt/local
# Uninstall
sudo make uninstall
# Copy to system path
sudo cp claude-auto-resume.sh /usr/local/bin/claude-auto-resume
sudo chmod +x /usr/local/bin/claude-auto-resume
# Or create symbolic link
sudo ln -s $(pwd)/claude-auto-resume.sh /usr/local/bin/claude-auto-resume
# Make script executable
chmod +x claude-auto-resume.sh
# Run directly
./claude-auto-resume.sh
以下 Windows 步骤是该 fork 特有的。Linux/macOS 用户应使用上面的方法。
# From the repo root
$dest = Join-Path $env:USERPROFILE "bin"
New-Item -ItemType Directory -Force -Path $dest | Out-Null
Copy-Item .\claude-auto-resume.ps1, .\claude-auto-resume.cmd $dest
确保目标文件夹已添加到当前用户的 PATH,然后运行:
claude-auto-resume --help
借助 .cmd 包装脚本,你可以直接从 PowerShell 或 CMD 运行 claude-auto-resume。
如果系统中有 pwsh,包装脚本会优先使用它;否则会回退到 Windows PowerShell。
Windows 使用与 Linux/macOS 相同的命令行选项和标志。
# Start new session with default prompt "continue"
claude-auto-resume
# Start new session with custom prompt
claude-auto-resume "implement user authentication"
# Start new session with custom prompt using flag
claude-auto-resume -p "write unit tests"
# Continue previous conversation with custom prompt
claude-auto-resume -c "please continue the previous task"
# Continue previous conversation with custom prompt using flag
claude-auto-resume -c -p "resume where we left off"
# Execute custom command after wait period
claude-auto-resume -e "npm run dev"
# Execute custom command with alias flag
claude-auto-resume --cmd "python app.py"
# Show help
claude-auto-resume --help
# Ensure script is executable
chmod +x claude-auto-resume.sh
# Start new session with default prompt
./claude-auto-resume.sh
# Start new session with custom prompt
./claude-auto-resume.sh "create login page"
# Continue previous conversation
./claude-auto-resume.sh -c "continue with the implementation"
# Execute custom command after wait period
./claude-auto-resume.sh -e "make build"
claude -p 'check' 命令Claude AI usage limit reached|<timestamp> 格式的消息claude --dangerously-skip-permissions -p "<custom-prompt>",启动新会话,默认行为claude -c --dangerously-skip-permissions -p "<custom-prompt>",使用 -c 标志继续会话-e、--execute 或 --cmd 标志执行自定义 shell 命令claude --dangerously-skip-permissions -p "<custom-prompt>":启动新会话,默认行为。
claude -c --dangerously-skip-permissions -p "<custom-prompt>":使用 -c 标志继续会话。
使用 -e、--execute 或 --cmd 标志执行自定义 shell 命令。
"continue" 启动新会话claude-auto-resume "implement feature"-p, --prompt:通过标志指定自定义 prompt,例如 claude-auto-resume -p "write tests"-c, --continue:继续上一次会话,会在 Claude 命令中添加 -c 标志-e, --execute:等待结束后执行自定义 shell 命令,例如 claude-auto-resume -e "npm run dev"--cmd:-e/--execute 的别名,例如 claude-auto-resume --cmd "python app.py"--test-mode:[DEV] 模拟使用限制,并通过秒数指定等待时间-h, --help:显示帮助信息和使用示例-v, --version:显示版本信息--check:显示系统检查信息使用不带 -c 的 claude 启动全新会话:
claude-auto-resume # New session with "continue"
claude-auto-resume "new feature" # New session with custom prompt
claude-auto-resume -p "write tests" # New session with flag
使用 claude -c 继续最近一次会话:
claude-auto-resume -c "keep going" # Continue with custom prompt
claude-auto-resume -c -p "resume work" # Continue with flag
等待结束后执行任意 shell 命令:
claude-auto-resume -e "npm run dev" # Start development server
claude-auto-resume --cmd "python app.py" # Run Python application
claude-auto-resume -e "make build && ./app" # Complex command with operators
claude-auto-resume -e "ls -la | grep '.js' | wc -l" # Pipeline commands
claude-auto-resume -e "echo 'Step 1'; echo 'Step 2'" # Multiple commands
使用内置测试模式进行开发和验证:
claude-auto-resume --test-mode 5 -e "echo 'Test command'" # Test with 5-second wait
claude-auto-resume --test-mode 10 --cmd "npm run test" # Test build process
PATH 访问grep、date、sleep、awk,通常已经预装该脚本使用 --dangerously-skip-permissions 来实现无人值守运行。这意味着:
"continue implementing the login function in src/auth.js"该脚本包含完善的错误处理:
1:Claude CLI 执行失败2:无法提取有效的恢复时间戳4:恢复命令执行失败# Syntax check
make test
# Or use bash directly
bash -n claude-auto-resume.sh
claude-auto-resume/
├── claude-auto-resume.sh # Main script
├── claude-auto-resume.ps1 # Windows PowerShell script
├── claude-auto-resume.cmd # Windows wrapper
├── Makefile # Installation/uninstallation script
├── docs/ # Project documentation
│ ├── architecture.md # Architecture documentation
│ ├── prd.md # Product requirements document
│ └── stories/ # User stories
├── CLAUDE.md # Claude Code guide
├── README.md # Project description (English)
└── README.zh.md # Project description (中文)
请查看开发路线图,了解计划中的功能和改进,包括:
创建功能分支:git checkout -b feature/AmazingFeature
提交你的修改:git commit -m 'Add some AmazingFeature'
将分支推送到远程:git push origin feature/AmazingFeature
创建 Pull Request。
在贡献新功能之前,请先查看项目路线图,确保你的改动与项目目标一致。
本项目采用 MIT License。详情请参阅 LICENSE 文件。
原始项目及 Bash 实现由 terryso 开发:https://github.com/terryso/claude-auto-resume
该 fork 新增了 Windows PowerShell 移植版本和 Windows 安装说明。
如果你遇到问题或有任何建议:
注意:该工具依赖 Claude CLI 的输出格式。如果 Claude CLI 更新后改变了输出格式,可能需要相应更新脚本。