working-directory-resolution
できること
このスキルは、間違ったフォルダーでコマンドを実行したことによるファイルのエラーを避ける方法を、AIエージェントに示します。ファイルは存在するのに、エージェントが見つからないと報告する人向けです。
使う場面
- ✓存在するファイルの読み取りが、見つからない、またはそのようなファイルはないというエラーで失敗するとき。
- ✓サンドボックスが、タスクで参照されたファイルを見つけられないとき。
- ✓シェルコマンドが、あるはずのファイルが見つからないと報告するとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/working-directory-resolution/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“エージェントは、私のconfig.jsonが存在しないと言いますが、ワークスペースには見えています。フォルダーの問題を直して、ファイルを読み込んでください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、各シェルコマンドの前に対象フォルダーへの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.
よくある質問
なぜこれでファイルが見つからないエラーが直るのですか?
そのエラーの多くは、ファイルがある場所と違うフォルダーからコマンドを実行することで起きるためです。
同じフォルダーで複数のコマンドを実行できますか?
はい。スキルは、1回の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エージェントが、AIMEやTerminal-Benchなどの標準的なAIベンチマークテストをセットアップして実行し、異なる改善方法を比較できるよう支援します。
experiment-guide
7.8kエージェントが、プログラムを改善する方法を調べる間に、小さな実験を計画し、その結果を読み、発見を記録できるよう支援します。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。