hermes - ✅(Solved) Fix [Bug]: `terminal.cwd` not correctly injected into system prompt [2 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#24882Fetched 2026-05-14 03:50:59
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
0
Author
Participants
Timeline (top)
labeled ×5cross-referenced ×2commented ×1

Error Message

Additional Logs / Traceback (optional)

Root Cause

Root Cause Analysis (optional)

Fix Action

Fixed

PR fix notes

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

Description (problem / solution / changelog)

Summary

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.

Fix

Check TERMINAL_CWD env var first; fall back to os.getcwd() when unset or empty. This is consistent with how _probe_remote_backend() already reads TERMINAL_CWD (line 663) for cache key generation.

Regression Coverage

  • test_build_environment_hints_prefers_terminal_cwd — verifies TERMINAL_CWD value appears in the system prompt
  • test_build_environment_hints_falls_back_to_getcwd — verifies os.getcwd() is used when TERMINAL_CWD is unset

Testing

All 10 TestEnvironmentHints tests pass (including 8 pre-existing).

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

Changed files

  • agent/prompt_builder.py (modified, +7/-1)
  • tests/agent/test_prompt_builder.py (modified, +24/-0)

PR #24957: fix(prompt_builder): use TERMINAL_CWD over os.getcwd() in environment hints

Description (problem / solution / changelog)

Summary

Fixes #24882

The system prompt's "Current working directory" line used os.getcwd() directly, ignoring the TERMINAL_CWD environment variable that the gateway bridges from config.yaml's terminal.cwd setting.

Problem

On macOS launchd-launched gateways, os.getcwd() returns the launchd WorkingDirectory (e.g. ~/.hermes/hermes-agent/) instead of the user's configured terminal.cwd path. This causes the agent to use the wrong working directory when instructed to "clone to the current directory" or perform other path-relative operations.

Root Cause

In agent/prompt_builder.py, the build_environment_hints() function's local-backend path used:

host_lines.append(f"Current working directory: {os.getcwd()}")

The gateway already bridges terminal.cwd from config to TERMINAL_CWD env var at startup (see gateway/run.py:444), but build_environment_hints() never checked it.

Fix

Prefer os.getenv("TERMINAL_CWD") over os.getcwd(), falling back to os.getcwd() when the env var is not set (CLI mode, where the process cwd is correct).

effective_cwd = os.getenv("TERMINAL_CWD") or os.getcwd()
host_lines.append(f"Current working directory: {effective_cwd}")

Testing

Added 2 new regression tests in TestEnvironmentHints:

  • test_build_environment_hints_prefers_terminal_cwd — verifies TERMINAL_CWD takes precedence
  • test_build_environment_hints_falls_back_to_getcwd — verifies os.getcwd() fallback when no env var

All 10 tests in TestEnvironmentHints pass (8 existing + 2 new), confirming no regression.

Files Changed

  • agent/prompt_builder.py — 1-line fix (+1 line for the variable)
  • tests/agent/test_prompt_builder.py — 2 new test methods

Changed files

  • agent/prompt_builder.py (modified, +2/-1)
  • tests/agent/test_prompt_builder.py (modified, +33/-0)

Code Example

Conversation started: Wednesday, May 13, 2026 10:01 AM
Model: gpt-5.4
Provider: custom

Host: macOS (26.4.1)
User home directory: /Users/perqin-moego
Current working directory: /Users/perqin-moego/.hermes/hermes-agent

You are in a Discord server or group chat communicating with your user. You can send media files natively: include MEDIA:/absolute/path/to/file in your response. Images (.png, .jpg, .webp) are sent as photo attachments, audio as file attachments. You can also include image URLs in markdown format ![alt](url) and they will be sent as attachments.

---

Report       https://paste.rs/RgjYm
agent.log    https://paste.rs/5cogQ
gateway.log  https://paste.rs/jIp89

---
RAW_BUFFERClick to expand / collapse

Bug Description

terminal.cwd not correctly injected into system prompt, which sometimes leads to unexpected behavior. For example, when I ask it to "clone the repo to the current working directory", it clones the repo into the directory injected into the system prompt, instead of terminal tool's cwd.

Steps to Reproduce

  1. Set terminal.cwd in config.yaml to some path e.g. /Users/perqin-moego/Workspaces/hermes-workspace;
  2. Restart hermes gateway: hermes gateway restart;
  3. Talk to the agent via discord and inspect the session json.

Expected Behavior

The current working directory in system prompt should be the same as that configured in config.yaml.

Actual Behavior

The current working directory in system prompt is set to the WorkingDirectory directive of macOS launchd profile. The trailing lines of system_prompt in the session json file:

Conversation started: Wednesday, May 13, 2026 10:01 AM
Model: gpt-5.4
Provider: custom

Host: macOS (26.4.1)
User home directory: /Users/perqin-moego
Current working directory: /Users/perqin-moego/.hermes/hermes-agent

You are in a Discord server or group chat communicating with your user. You can send media files natively: include MEDIA:/absolute/path/to/file in your response. Images (.png, .jpg, .webp) are sent as photo attachments, audio as file attachments. You can also include image URLs in markdown format ![alt](url) and they will be sent as attachments.

Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp)

Messaging Platform (if gateway-related)

Discord

Debug Report

Report       https://paste.rs/RgjYm
agent.log    https://paste.rs/5cogQ
gateway.log  https://paste.rs/jIp89

Operating System

macOS 26.4.1

Python Version

3.11.15

Hermes Version

0.13.0

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

No response

Proposed Fix (optional)

No response

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING