feat: git worktree isolation for parallel CLI sessions (--worktree / -w)#654
Merged
Conversation
Add a --worktree (-w) flag to the hermes CLI that creates an isolated git worktree for the session. This allows running multiple hermes-agent instances concurrently on the same repo without file collisions. How it works: - On startup with -w: detects git repo, creates .worktrees/<session>/ with its own branch (hermes/<session-id>), sets TERMINAL_CWD to it - Each agent works in complete isolation — independent HEAD, index, and working tree, shared git object store - On exit: auto-removes worktree and branch if clean, warns and keeps if there are uncommitted changes - .worktreeinclude file support: list gitignored files (.env, .venv/) to auto-copy/symlink into new worktrees - .worktrees/ is auto-added to .gitignore - Agent gets a system prompt note about the worktree context - Config support: set worktree: true in config.yaml to always enable Usage: hermes -w # Interactive mode in worktree hermes -w -q "Fix issue #123" # Single query in worktree # Or in config.yaml: worktree: true Includes 17 tests covering: repo detection, worktree creation, independence verification, cleanup (clean/dirty), .worktreeinclude, .gitignore management, and 10 concurrent worktrees. Closes #652
Critical fixes: - Add --worktree/-w to hermes_cli/main.py argparse (both chat subcommand and top-level parser) so 'hermes -w' works via the actual CLI entry point, not just 'python cli.py -w' - Pass worktree flag through cmd_chat() kwargs to cli_main() - Handle worktree attr in bare 'hermes' and --resume/--continue paths Bug fixes in cli.py: - Skip worktree creation for --list-tools/--list-toolsets (wasteful) - Wrap git worktree subprocess.run in try/except (crash on timeout) - Add stale worktree pruning on startup (_prune_stale_worktrees): removes clean worktrees older than 24h left by crashed/killed sessions Documentation updates: - AGENTS.md: add --worktree to CLI commands table - cli-config.yaml.example: add worktree config section - website/docs/reference/cli-commands.md: add to core commands - website/docs/user-guide/cli.md: add usage examples - website/docs/user-guide/configuration.md: add config docs Test improvements (17 → 31 tests): - Stale worktree pruning (prune old clean, keep recent, keep dirty) - Directory symlink via .worktreeinclude - Edge cases (no commits, not a repo, pre-existing .worktrees/) - CLI flag/config OR logic - TERMINAL_CWD integration - System prompt injection format
angelburgosrosado
pushed a commit
to angelburgosrosado/hermes-agent
that referenced
this pull request
Apr 27, 2026
…CLI sessions (--worktree / -w) Adds --worktree (-w) flag to hermes CLI for isolated git worktree sessions. Multiple agents can work on the same repo concurrently without collisions. Closes NousResearch#652
2 tasks
02356abc
pushed a commit
to 02356abc/hermes-agent
that referenced
this pull request
May 14, 2026
…CLI sessions (--worktree / -w) Adds --worktree (-w) flag to hermes CLI for isolated git worktree sessions. Multiple agents can work on the same repo concurrently without collisions. Closes NousResearch#652
olympus-terminal
pushed a commit
to olympus-terminal/hermes-agent
that referenced
this pull request
May 16, 2026
…CLI sessions (--worktree / -w) Adds --worktree (-w) flag to hermes CLI for isolated git worktree sessions. Multiple agents can work on the same repo concurrently without collisions. Closes NousResearch#652
Egavasyug
pushed a commit
to Egavasyug/hermes-agent
that referenced
this pull request
Jun 10, 2026
…CLI sessions (--worktree / -w) Adds --worktree (-w) flag to hermes CLI for isolated git worktree sessions. Multiple agents can work on the same repo concurrently without collisions. Closes NousResearch#652
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
--worktree(-w) flag to the hermes CLI that creates an isolated git worktree for the session. This allows running multiple hermes-agent instances concurrently on the same repo without file collisions, branch conflicts, or corrupted git state.Closes #652
How It Works
On startup with
-w:.worktrees/<hermes-uuid>/with its own branch (hermes/hermes-<uuid>)TERMINAL_CWDto the worktree path.worktreeinclude(gitignored files like.env,.venv/).worktrees/to.gitignoreOn exit:
Config support:
Usage
Changes
cli.py: Added--worktree/-wflag, worktree setup/cleanup functions, config integration, system prompt injection (~170 lines)tests/test_worktree.py: 17 tests covering repo detection, creation, independence, cleanup (clean/dirty),.worktreeinclude,.gitignoremanagement, and 10 concurrent worktreesTest Results