hermes - ✅(Solved) Fix Cron --workdir not reflected in agent system prompt 'Current working directory' [1 pull requests, 1 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#24969Fetched 2026-05-14 03:50:13
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×3cross-referenced ×1

When a cron job is registered with --workdir <PATH>, Hermes correctly initializes the terminal tool with cwd=<PATH>, but the system prompt injected into the agent still reports Current working directory: <scheduler-cwd> (the directory from which the gateway was launched, typically ~/.hermes/hermes-agent).

The model trusts the system prompt over pwd, so its first action is often cd <wrong-dir>. The job then operates on the wrong filesystem location for the rest of the tick — silently producing no work, or worse, mutating the wrong repo.

Error Message

Relevant lines from a real run (cron_6c7295c5e077 on 2026-05-13 10:47):

2026-05-13 10:47:34,866 INFO cron.scheduler: Running job 'tdd-tick-tdd-sandbox-calc' (ID: 6c7295c5e077)
2026-05-13 10:47:34,866 INFO cron.scheduler: Job '6c7295c5e077': using workdir /tmp/tdd-sandbox-calc
2026-05-13 10:47:38,550 INFO ... tools.environments.base: Session snapshot created (session=504a4ccee07a, cwd=/tmp/tdd-sandbox-calc)
2026-05-13 10:47:44,902 INFO cron.scheduler: Job '6c7295c5e077': agent returned [SILENT] — skipping delivery

First tool_call the model issued (extracted from the saved session JSON):

{"function": {"name": "terminal", "arguments": {"command": "cd /home/nexus/.hermes/hermes-agent && pwd && ls -la .agent/ 2>&1 | head -20"}}}

The cd /home/nexus/.hermes/hermes-agent was added by the model on its own initiative based on the system prompt — not requested by the user prompt.

Root Cause

We hit this with tdd-coder, a skill that drives an autonomous TDD loop in a sandboxed git repo. The skill's step 1 says export WORKSPACE="$(pwd)" because the documented contract is "Hermes places the cron in the right cwd". The model, however, reads the system prompt and prepends cd /home/nexus/.hermes/hermes-agent to its first command — so it never reaches the workspace, never invokes the preflight script, and the tick produces zero work while still consuming tokens. The bug is silent: agent returns [SILENT] and the scheduler reports success.

Fix Action

Fix / Workaround

Workaround on our end: add a guard to step 1 that aborts the skill if pwd doesn't match a valid workspace, and explicitly tell the model in the skill NOT to trust the Current working directory field. This restores correctness for our case but doesn't help any other skill that assumes the documented contract.

PR fix notes

PR #24985: fix(cron): use TERMINAL_CWD for system prompt working directory

Description (problem / solution / changelog)

Summary

When a cron job is registered with --workdir <PATH>, the scheduler correctly sets TERMINAL_CWD so terminal/file tools run from the right directory. However, build_environment_hints() in agent/prompt_builder.py uses os.getcwd() unconditionally for the Current working directory line in the system prompt, which reports the scheduler's own cwd (typically ~/.hermes/hermes-agent) instead of the job's configured workdir.

Since the model trusts the system prompt over pwd, it often starts by cd-ing to the wrong directory, silently operating on the wrong filesystem location.

Root Cause

prompt_builder.py:775 calls os.getcwd() without checking the TERMINAL_CWD environment variable that the cron scheduler sets at scheduler.py:1265.

Fix

Check os.environ.get("TERMINAL_CWD") first, falling back to os.getcwd() — consistent with how the terminal tools already resolve working directory.

Testing

  • 121 prompt_builder/environment_hints tests pass (5 skipped)
  • Manual: TERMINAL_CWD=/tmp python -c "from agent.prompt_builder import build_environment_hints; print(build_environment_hints())" now shows /tmp

Closes #24969

Changed files

  • agent/prompt_builder.py (modified, +2/-1)

Code Example

mkdir -p /tmp/repro-cwd/.agent
cd /tmp/repro-cwd && git init -q && echo "agent/main" > .agent/branch
git add -A && git commit -qm "init"

---

hermes cron create "every 1 day" \
  "Run pwd and ls -la .agent/ — report which directory you are in." \
  --name repro-cwd \
  --workdir /tmp/repro-cwd

---

JOB_ID=$(hermes cron list | grep -oE '^\s+[a-f0-9]{12}' | head -1 | tr -d ' ')
hermes cron run --accept-hooks "$JOB_ID"

---

SESS=$(ls -t ~/.hermes/sessions/session_cron_*.json | head -1)
jq -r '.system_prompt | strings' "$SESS" | grep -E "Current working directory|workdir"

---

Current working directory: /tmp/repro-cwd

---

Current working directory: /home/nexus/.hermes/hermes-agent

---

INFO [cron_<id>_...] tools.environments.base: Session snapshot created (session=..., cwd=/tmp/repro-cwd)

---

2026-05-13 10:47:34,866 INFO cron.scheduler: Running job 'tdd-tick-tdd-sandbox-calc' (ID: 6c7295c5e077)
2026-05-13 10:47:34,866 INFO cron.scheduler: Job '6c7295c5e077': using workdir /tmp/tdd-sandbox-calc
2026-05-13 10:47:38,550 INFO ... tools.environments.base: Session snapshot created (session=504a4ccee07a, cwd=/tmp/tdd-sandbox-calc)
2026-05-13 10:47:44,902 INFO cron.scheduler: Job '6c7295c5e077': agent returned [SILENT] — skipping delivery

---

{"function": {"name": "terminal", "arguments": {"command": "cd /home/nexus/.hermes/hermes-agent && pwd && ls -la .agent/ 2>&1 | head -20"}}}
RAW_BUFFERClick to expand / collapse

Cron --workdir is not reflected in the agent's system prompt Current working directory field

Summary

When a cron job is registered with --workdir <PATH>, Hermes correctly initializes the terminal tool with cwd=<PATH>, but the system prompt injected into the agent still reports Current working directory: <scheduler-cwd> (the directory from which the gateway was launched, typically ~/.hermes/hermes-agent).

The model trusts the system prompt over pwd, so its first action is often cd <wrong-dir>. The job then operates on the wrong filesystem location for the rest of the tick — silently producing no work, or worse, mutating the wrong repo.

Environment

  • Hermes Agent v0.13.0 (2026.5.7), Python 3.11.13
  • Linux 6.8.0-111-generic
  • Model: claude-haiku-4-5 via custom:anthropic-direct provider
  • Cron registered via hermes cron create ... --workdir /tmp/tdd-sandbox-calc

Repro

  1. Create a sandbox dir with .agent/ (so it's a valid workspace for a skill that expects pwd to be the workspace):
mkdir -p /tmp/repro-cwd/.agent
cd /tmp/repro-cwd && git init -q && echo "agent/main" > .agent/branch
git add -A && git commit -qm "init"
  1. Register a cron with --workdir:
hermes cron create "every 1 day" \
  "Run pwd and ls -la .agent/ — report which directory you are in." \
  --name repro-cwd \
  --workdir /tmp/repro-cwd
  1. Trigger it:
JOB_ID=$(hermes cron list | grep -oE '^\s+[a-f0-9]{12}' | head -1 | tr -d ' ')
hermes cron run --accept-hooks "$JOB_ID"
  1. Inspect the session JSON in ~/.hermes/sessions/session_cron_<id>_*.json:
SESS=$(ls -t ~/.hermes/sessions/session_cron_*.json | head -1)
jq -r '.system_prompt | strings' "$SESS" | grep -E "Current working directory|workdir"

Expected

Current working directory: /tmp/repro-cwd

Actual

Current working directory: /home/nexus/.hermes/hermes-agent

(or wherever the gateway was started from)

Meanwhile, the terminal tool itself is correct — ~/.hermes/logs/agent.log shows:

INFO [cron_<id>_...] tools.environments.base: Session snapshot created (session=..., cwd=/tmp/repro-cwd)

So the workdir is being honored somewhere in the stack (terminal tool initialization), just not in the system prompt the model reads.

Real-world impact

We hit this with tdd-coder, a skill that drives an autonomous TDD loop in a sandboxed git repo. The skill's step 1 says export WORKSPACE="$(pwd)" because the documented contract is "Hermes places the cron in the right cwd". The model, however, reads the system prompt and prepends cd /home/nexus/.hermes/hermes-agent to its first command — so it never reaches the workspace, never invokes the preflight script, and the tick produces zero work while still consuming tokens. The bug is silent: agent returns [SILENT] and the scheduler reports success.

Workaround on our end: add a guard to step 1 that aborts the skill if pwd doesn't match a valid workspace, and explicitly tell the model in the skill NOT to trust the Current working directory field. This restores correctness for our case but doesn't help any other skill that assumes the documented contract.

Suggested fix

Wherever the system prompt template renders Current working directory:, source the value from the job's workdir (the same value used to construct the terminal tool's cwd), not from os.getcwd() of the scheduler process.

Likely locations to audit:

  • run_agent.py — where the cron task's system prompt is built
  • The function that exposes "host context" to the system prompt template

Logs

Relevant lines from a real run (cron_6c7295c5e077 on 2026-05-13 10:47):

2026-05-13 10:47:34,866 INFO cron.scheduler: Running job 'tdd-tick-tdd-sandbox-calc' (ID: 6c7295c5e077)
2026-05-13 10:47:34,866 INFO cron.scheduler: Job '6c7295c5e077': using workdir /tmp/tdd-sandbox-calc
2026-05-13 10:47:38,550 INFO ... tools.environments.base: Session snapshot created (session=504a4ccee07a, cwd=/tmp/tdd-sandbox-calc)
2026-05-13 10:47:44,902 INFO cron.scheduler: Job '6c7295c5e077': agent returned [SILENT] — skipping delivery

First tool_call the model issued (extracted from the saved session JSON):

{"function": {"name": "terminal", "arguments": {"command": "cd /home/nexus/.hermes/hermes-agent && pwd && ls -la .agent/ 2>&1 | head -20"}}}

The cd /home/nexus/.hermes/hermes-agent was added by the model on its own initiative based on the system prompt — not requested by the user prompt.

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

hermes - ✅(Solved) Fix Cron --workdir not reflected in agent system prompt 'Current working directory' [1 pull requests, 1 participants]