working-directory-resolution
它能做什么
这项技能展示智能体如何避免因在错误的文件夹中运行命令而导致的文件错误。适合文件实际存在,但智能体却报告找不到的人。
适用场景
- ✓当文件读取因找不到文件或没有此文件的错误而失败,而该文件其实存在的时候。
- ✓当沙箱找不到任务中提到的文件时。
- ✓当 shell 命令报告一个本应存在的文件缺失的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/working-directory-resolution/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“智能体说我的 config.json 不存在,但我能在工作区里看到它。请修复文件夹问题并读取该文件。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会在每条 shell 命令前加上 cd 到目标文件夹,使每条命令都在正确的位置运行。这样就消除了工作文件夹与文件所在位置之间的不匹配。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Working Directory Resolution Pattern
Many file operation failures occur because the tool's current working directory doesn't match where the target files are located. This skill provides a reliable pattern for resolving such issues.
Problem Symptoms
File operations fail with errors like:
- "File not found" or "No such file or directory"
- "Permission denied" (when path is actually relative)
- Tools returning empty results for files that should exist
These failures often occur even when files are present in the workspace—the working directory context is simply wrong.
Solution
Always explicitly set the working directory before file operations by prepending cd to your shell commands.
Implementation Pattern
Basic Syntax
cd /path/to/target/directory && your-command-here
With run_shell
run_shell(command="cd /workspace/project && cat config.json")
Multiple Operations in Same Directory
cd /workspace/project && ls -la && cat README.md && python script.py
Conditional Directory Change
cd /workspace/project 2>/dev/null && cat file.txt || echo "Directory not found"
When to Apply
Use this pattern when:
read_filefails to locate an existing fileexecute_code_sandboxcan't find referenced files- Shell commands report missing files that should exist
- File paths work in some contexts but not others
- You're unsure of the tool's current working directory
Best Practices
Use absolute paths when possible
cd /workspace/project/src && python main.pyCombine related operations to avoid repeated
cdcallscd /workspace/project && ./build.sh && ./test.shVerify directory exists before operations
[ -d /workspace/project ] && cd /workspace/project && lsFor scripts, set working directory at the start
#!/bin/bash cd "$(dirname "$0")" || exit 1 # Rest of script runs from script's directory
Common Pitfalls
| Issue | Wrong Approach | Correct Approach |
|---|---|---|
| Relative paths | cat config.json |
cd /workspace && cat config.json |
| Assumed cwd | python script.py |
cd /workspace && python script.py |
| Multiple dirs | cd dir1; cd dir2; cmd |
cd dir1/dir2 && cmd |
Fallback Strategy
If cd also fails:
- Use
pwdto check current directory - Use
findorls -Rto locate files - Verify the path structure with
ls -la /path/to/check
pwd && find /workspace -name "target_file.txt" 2>/dev/null
This pattern is especially valuable when tools like execute_code_sandbox or read_file fail but run_shell with explicit directory context succeeds.
常见问题
为什么这能修复找不到文件的错误?
这些错误大多是因为命令在与文件不同的文件夹中运行而造成的。
我可以在同一个文件夹中运行多条命令吗?
可以,技能展示了在一次 cd 之后连接多条命令,使它们都在该文件夹中运行。
如果文件夹不存在怎么办?
技能展示了一种条件写法,在找不到该文件夹时打印一条消息。
详情
作者的原始描述
Resolve file access failures by changing to the correct working directory before command execution
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #13030
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。