Skip to content

fix(prompt_builder): use TERMINAL_CWD in system prompt when configured#24888

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/issue-24882-terminal-cwd-system-prompt
Closed

fix(prompt_builder): use TERMINAL_CWD in system prompt when configured#24888
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/issue-24882-terminal-cwd-system-prompt

Conversation

@liuhao1024

@liuhao1024 liuhao1024 commented May 13, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

build_environment_hints() always uses os.getcwd() for the "Current working directory" line in the system prompt, ignoring the terminal.cwd config setting. When Hermes runs as a daemon (e.g. via launchd), os.getcwd() reflects the daemon's launch directory rather than the user's configured workspace.

Root Cause

In agent/prompt_builder.py, build_environment_hints() calls os.getcwd() directly (line 775) without checking the TERMINAL_CWD environment variable, which the gateway sets from terminal.cwd in config.yaml.

Related Issue

Fixes #24882

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • See commit messages for detailed changes

How to Test

  1. Run pytest tests/ -q — all tests should pass
  2. Verify the specific scenario described above is resolved

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 26.4.1

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture and workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A

Code Intelligence

  • Blast radius: LOW — single function (build_environment_hints) in hermes_cli/prompt_builder.py
  • Scope: Only affects the "Current working directory" line in the system prompt
  • Risk: None — reads from config instead of os.getcwd(), falls back to os.getcwd() if config is unset
  • Tests: Existing tests cover build_environment_hints() output

When terminal.cwd is set in config.yaml, the gateway bridges it to the
TERMINAL_CWD environment variable. However, build_environment_hints()
ignored this and always used os.getcwd(), which reflects the daemon's
launch directory (e.g. from launchd WorkingDirectory) rather than the
user's configured workspace path.

Now checks TERMINAL_CWD first and falls back to os.getcwd() when unset.

Fixes NousResearch#24882
@perqin

perqin commented May 22, 2026

Copy link
Copy Markdown

What's the status of this PR? When will this be merged? The wrong working directory in system prompt is really annoying...

@lincannm

Copy link
Copy Markdown

When can this pull request be merged?

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Hi @perqin @lincannm — sorry for the delay. The fix is ready and passing CI. I've updated the PR body with the Code Intelligence section per the contributing guide.

The change is minimal (1 file, 2 lines) and scoped to build_environment_hints() only — it reads terminal.cwd from config instead of os.getcwd(). This affects the system prompt's "Current working directory" line when Hermes runs as a daemon or in a different directory than the user's workspace.

@maintainers — could you take a look when you have a chance?

@teknium1

Copy link
Copy Markdown
Contributor

This has been implemented on main. Thanks for the focused bug fix and for the follow-up discussion from @perqin and @lincannm confirming the user-visible impact.

Automated hermes-sweeper review evidence:

  • agent/prompt_builder.py:844 now emits Current working directory: via resolve_agent_cwd() instead of calling os.getcwd() directly.
  • agent/runtime_cwd.py:39 defines resolve_agent_cwd(), which prefers a session cwd override, then TERMINAL_CWD, and only falls back to os.getcwd() when no configured cwd is available.
  • tests/agent/test_prompt_builder.py:966 includes the regression test for this exact daemon/configured-workspace case.
  • The implementation landed in 16047655b5260acf40e2a9e932d0569f2520f389 (fix(prompt): show configured working directory in system prompt) and is contained in v2026.6.5.

@teknium1 teknium1 closed this Jun 11, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: terminal.cwd not correctly injected into system prompt

5 participants