working-directory-resolution
What it does
This skill shows the AI agent how to avoid file errors caused by running commands in the wrong folder. It is for people whose files exist but the agent reports they cannot be found.
When to use it
- ✓When a file read fails with not found or no such file errors for a file that exists.
- ✓When a sandbox cannot find files referenced in the task.
- ✓When a shell command reports a missing file that should be there.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/working-directory-resolution/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“The agent says my config.json does not exist, but I can see it in the workspace. Fix the folder problem and read the file.”
5 new skills a week. 1 minute to read.
How it works
The agent prefixes each shell command with a cd to the target folder, so every command runs in the correct place. This removes the mismatch between the working folder and the location of the files.
Technical content (original SKILL.md)
Original text by the author, straight from 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.
FAQ
Why does this fix missing-file errors?
Most of those errors happen because the command runs from a different folder than the files are in.
Can I run several commands in one folder?
Yes, the skill shows chaining commands after a single cd so they all run in that folder.
What if the folder does not exist?
The skill shows a conditional form that prints a message when the folder cannot be found.
Details
Original description by the author
Resolve file access failures by changing to the correct working directory before command execution
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #13030
- License
- MIT
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
agentpilot
7.8kHelps your agent improve a project step by step by preparing a task and running the AgentPilot loop that proposes, tests and scores changes.
openspace
7.8kHelps your agent set up OpenSpace, a tool that stores and fetches agent skills, and connect it to your AI app through MCP.
rsi-arena
7.8kHelps your agent set up and run standard AI benchmark tests, such as AIME and Terminal-Bench, to compare different improvement methods.
experiment-guide
7.8kHelps your agent plan small experiments, read their results and record findings while it investigates how to improve a program.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.