When you need to complete the following types of complex coding tasks, use the exec tool to invoke the Claude Code CLI:
Applicable Scenarios
- Multi-file code refactoring
- Complex bug debugging
- Writing new training/evaluation/data processing scripts
- Large-scale code modifications (more than 50 lines)
- Tasks requiring deep code understanding
How to Invoke
claude --print --dangerously-skip-permissions \
--model claude-opus-4-6 \
-p "<详细任务描述,包含上下文、文件路径、预期结果>" \
--cwd {baseDir}
Best Practices
- Provide as detailed a task description as possible, including relevant file paths
- Specify the expected results and validation criteria
- For experimental code modifications, first explain the current code logic before describing the modification goal
- Claude Code will automatically read CLAUDE.md in the project to obtain context
Example
# 优化数据加载器性能
claude --print --dangerously-skip-permissions \
-p "优化 src/data/loader.py 中的 DataLoader 类,当前加载 10GB 数据集需要 5 分钟,目标是减少到 1 分钟以内。可以考虑使用 memory mapping、多进程预加载、或更高效的序列化格式。" \
--cwd {baseDir}