Skip to content

Add 'enter' command to open a subshell in an existing worktree#42

Open
Tsha0 wants to merge 2 commits into
kunchenguid:mainfrom
Tsha0:add-enter-command
Open

Add 'enter' command to open a subshell in an existing worktree#42
Tsha0 wants to merge 2 commits into
kunchenguid:mainfrom
Tsha0:add-enter-command

Conversation

@Tsha0

@Tsha0 Tsha0 commented Jun 26, 2026

Copy link
Copy Markdown

What

Adds treehouse enter <name>, which opens a subshell in an existing pool worktree identified by its name (the number shown by treehouse status), including worktrees that are already in use.

Why

get always hands out a free worktree and skips anything in-use/leased/dirty. There was no first-class way to re-attach to a specific existing worktree (e.g. to peek at what another agent is doing, or to hop back into a worktree you know by number). The workaround was cd-ing into the raw pool path by hand.

Behavior

  • Resolves the worktree by name via pool.List, then spawns a subshell in its directory (sets TREEHOUSE_DIR), mirroring how get enters.
  • Unlike get, enter is a guest: it does not acquire, reset, lease, or return the worktree, and writes no pool state. On exit it leaves everything exactly as it was.
  • Unknown names fail with a non-zero exit and list the available names.
$ treehouse enter 1
🌳 Entered worktree 1 at ~/.treehouse/myrepo-a1b2c3/1/myrepo. Type 'exit' to leave.
$ exit
🌳 Left worktree. Pool state unchanged.

Tests

Adds two e2e tests (TestEnterByNameOpensSubshellWithoutChangingPool, TestEnterUnknownNameFails). Full suite passes; gofmt/go vet clean. Reuses the cross-platform shell.Spawn, so no Windows-specific handling is needed.

Docs (README CLI reference, AGENTS.md command list) updated.

treehouse enter <name> drops into an existing pool worktree (identified
by the number shown in 'treehouse status'), including worktrees that are
already in use. Unlike 'get', it does not acquire, reset, or return the
worktree, leaving all pool state untouched on exit -- useful for
attaching to a worktree another agent is using.

Amp-Thread-ID: https://ampcode.com/threads/T-019f0476-3777-70a8-a117-f9b788fb6c98
Co-authored-by: Amp <amp@ampcode.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b78886138

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cmd/enter.go
func enterRunE(cmd *cobra.Command, args []string) error {
name := args[0]

repoRoot, err := git.FindRepoRoot()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the owning repo when resolving the pool

When enter is run from inside one of Treehouse's linked worktrees for a local-only repository, or for a repo that uses a relative root, git rev-parse --show-toplevel returns the linked worktree path rather than the original repository root. That makes config.ResolvePoolDir hash/resolve a different pool, so treehouse enter <name> reports an empty or wrong pool instead of finding sibling worktrees; this flow is likely when users are already inside a Treehouse shell and want to hop to another worktree. Resolve the main repo root here (as the return/destroy paths do) before loading config and computing the pool directory.

Useful? React with 👍 / 👎.

Add a --print-path flag to 'enter' that prints only the worktree's
absolute path to stdout (no subshell), so a shell function can change
its own directory: cd "$(treehouse enter --print-path 1)".

Amp-Thread-ID: https://ampcode.com/threads/T-019f0476-3777-70a8-a117-f9b788fb6c98
Co-authored-by: Amp <amp@ampcode.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant