Bug Description
I have been observing this issue repeatedly and first thought it was due to the models used, because it does not happen in every session.
When launching Hermes with -w (worktree flag), file tools (read_file, write_file, patch) resolve relative paths using os.getcwd() or Path(path).resolve(), which points to the main repository root — not the worktree. This causes the agent to accidentally modify files in the main repository instead of the isolated worktree, even though TERMINAL_CWD is correctly set to the worktree path.
Steps to Reproduce
- Launch Hermes with
-w pointing to a new worktree branch: hermes -w feature-x
- Verify worktree exists:
git worktree list shows feature-x at .worktrees/feature-x/
- Ask the agent to read, write, or edit any file using a relative path
- File modifications can land in the main repository instead of the worktree
Expected Behavior
File operations should resolve relative paths against TERMINAL_CWD (the worktree directory), not os.getcwd() (the main repository).
Actual Behavior
os.getcwd() returns the main repo path. File tools use Path(path).resolve() which defaults to process CWD, ignoring TERMINAL_CWD.
Affected Component
Tools (terminal, file ops, web, code execution, etc.)
Messaging Platform (if gateway-related)
N/A (CLI only)
Debug Report
Operating System
Debian 13
Python Version
Python 3.13.5
Hermes Version
Hermes Agent v0.10.0 (2026.4.16)
Additional Logs / Traceback (optional)
Root Cause Analysis (optional)
In hermes-agent/tools/file_tools.py, path resolution uses Path(path).resolve() which defaults to the process CWD. Meanwhile TERMINAL_CWD is set correctly by cli.py's _setup_worktree but only respected by the terminal tool backend, not file tools.
Proposed Fix (optional)
In hermes-agent/tools/file_tools.py, path resolution uses Path(path).resolve() which defaults to the process CWD. Meanwhile TERMINAL_CWD is set correctly by cli.py's _setup_worktree but only respected by the terminal tool backend, not file tools.
Are you willing to submit a PR for this?
Bug Description
I have been observing this issue repeatedly and first thought it was due to the models used, because it does not happen in every session.
When launching Hermes with
-w(worktree flag), file tools (read_file,write_file,patch) resolve relative paths usingos.getcwd()orPath(path).resolve(), which points to the main repository root — not the worktree. This causes the agent to accidentally modify files in the main repository instead of the isolated worktree, even thoughTERMINAL_CWDis correctly set to the worktree path.Steps to Reproduce
-wpointing to a new worktree branch:hermes -w feature-xgit worktree listshowsfeature-xat.worktrees/feature-x/Expected Behavior
File operations should resolve relative paths against
TERMINAL_CWD(the worktree directory), notos.getcwd()(the main repository).Actual Behavior
os.getcwd()returns the main repo path. File tools usePath(path).resolve()which defaults to process CWD, ignoringTERMINAL_CWD.Affected Component
Tools (terminal, file ops, web, code execution, etc.)
Messaging Platform (if gateway-related)
N/A (CLI only)
Debug Report
Operating System
Debian 13
Python Version
Python 3.13.5
Hermes Version
Hermes Agent v0.10.0 (2026.4.16)
Additional Logs / Traceback (optional)
Root Cause Analysis (optional)
In
hermes-agent/tools/file_tools.py, path resolution usesPath(path).resolve()which defaults to the process CWD. MeanwhileTERMINAL_CWDis set correctly bycli.py's_setup_worktreebut only respected by the terminal tool backend, not file tools.Proposed Fix (optional)
In
hermes-agent/tools/file_tools.py, path resolution usesPath(path).resolve()which defaults to the process CWD. MeanwhileTERMINAL_CWDis set correctly bycli.py's_setup_worktreebut only respected by the terminal tool backend, not file tools.Are you willing to submit a PR for this?