Skip to content

fix(cli): restore session cwd on resume (-c) - #38256

Closed
MorAlekss wants to merge 1 commit into
NousResearch:mainfrom
MorAlekss:fix/cli-resume-restore-cwd
Closed

fix(cli): restore session cwd on resume (-c)#38256
MorAlekss wants to merge 1 commit into
NousResearch:mainfrom
MorAlekss:fix/cli-resume-restore-cwd

Conversation

@MorAlekss

Copy link
Copy Markdown
Contributor

Summary

Restores the session working directory when resuming a CLI session with -c.


Root cause

_init_agent() in cli.py loaded conversation history and reopened the session in the DB but never restored the working directory. The sessions table already has a cwd column and update_session_cwd() exists, but the CLI path never wrote to or read from it, only the TUI gateway did.


Behavioral change

Before: hermes -c / hermes --resume <id> restores conversation history but starts in the launch directory, ignoring any cd the agent performed during the previous session.

After: the working directory is restored to where the previous session left off.


What changed

tools/terminal_tool.py

  • Added get_live_terminal_cwd(task_id), a public getter for the terminal environment's live env.cwd. Symmetric with the existing register_task_env_overrides and clear_task_env_overrides pair.

run_agent.py

  • _ensure_db_session(): passes cwd=os.getcwd() to create_session() so the initial working directory is persisted on session creation.
  • _persist_session(): calls update_session_cwd() with the live terminal cwd after every turn so any cd performed during the session is persisted for the next resume.

cli.py

tests/cli/test_cli_resume_cwd.py

  • 3 new tests in TestResumeCwdRestore: canary test that fails without the fix, guard for NULL cwd in pre-fix session rows, guard for deleted directory that must not crash.

What is NOT changed


Implements the fix discussed in Discord (May 31) following a user report about the agent losing its working directory after resume. @teknium1 noted: "this is a good point. I'll see if I can make resume and -c reload with the last working dir it was in."

@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint tool/terminal Terminal execution and process management P2 Medium — degraded but workaround exists labels Jun 3, 2026
@MorAlekss MorAlekss closed this Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants