touch_file
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesetouch_file
touch_file
When a Write or Edit tool call fails while trying to create a new file, recover by using via the Bash tool to create the empty file first, then retry the Write.
touch当Write或Edit工具调用在尝试创建新文件失败时,通过Bash工具使用命令先创建空文件,然后重试Write操作来恢复。
touchWhy this matters
为什么这很重要
The Write tool can fail when creating new files — often because parent directories don't exist, or the filesystem needs the file to be created differently. Rather than giving up or trying workarounds, a quick + reliably sets up the file path so the Write tool succeeds on retry.
mkdir -ptouchWrite工具在创建新文件时可能会失败——通常是因为父目录不存在,或者文件系统需要以不同方式创建文件。与其放弃或尝试其他解决方法,快速执行 + 可以可靠地设置文件路径,使Write工具在重试时成功。
mkdir -ptouchRecovery steps
恢复步骤
When Write or Edit fails on a new file (not an existing one):
- Create parent directories — run via Bash to ensure the full directory path exists.
mkdir -p <parent-directory> - Create the empty file — run via Bash.
touch <filepath> - Retry the Write — use the Write tool again with the same content. It should succeed now.
You can combine steps 1 and 2:
bash
mkdir -p src/utils && touch src/utils/helpers.ts当Write或Edit在新文件(而非现有文件)上失败时:
- 创建父目录——通过Bash运行以确保完整的目录路径存在。
mkdir -p <父目录> - 创建空文件——通过Bash运行。
touch <文件路径> - 重试Write操作——再次使用Write工具并传入相同内容,现在应该会成功。
你可以将步骤1和2合并:
bash
mkdir -p src/utils && touch src/utils/helpers.tsWhen this applies
适用场景
- A Write tool call fails and the target file does not already exist
- The error mentions missing directories, file not found, or path issues
- You're trying to create a file in a nested directory structure
- Write工具调用失败,且目标文件尚未存在
- 错误提示提及缺少目录、文件未找到或路径问题
- 你尝试在嵌套目录结构中创建文件
Edge case: broken symlinks
边缘情况:损坏的符号链接
If fails because a broken symlink occupies a path component (error like even though should create it), the symlink is pointing to a nonexistent target and blocking directory creation. Do not remove it automatically — the symlink may be there intentionally. Instead, tell the user what you found and ask how they'd like to proceed (e.g., remove the symlink, fix its target, or choose a different path).
mkdir -pNo such file or directorymkdir -p如果因路径组件被损坏的符号链接占用而失败(例如错误提示“没有该文件或目录”,即使应该创建它),说明该符号链接指向不存在的目标并阻止了目录创建。请勿自动删除它——该符号链接可能是有意存在的。相反,告知用户你发现的问题并询问他们希望如何处理(例如删除符号链接、修复其目标,或选择其他路径)。
mkdir -pmkdir -pWhen this does NOT apply
不适用场景
- Edit or Write fails on a file that already exists — that's a different problem
- The error is unrelated to file creation (e.g., permission denied on an existing file, disk full)
- Edit或Write在已存在的文件上失败——这是另一个问题
- 错误与文件创建无关(例如现有文件权限被拒绝、磁盘已满)