Summary
After creating a worktree with gtr new we get output like this:
[OK] Worktree created: /Users/ed/dev/core-worktrees/<branch>
Next steps:
git gtr editor <branch> # Open in editor
git gtr ai <branch> # Start AI tool
cd "$(git gtr go <branch>)" # Navigate to worktree
But when using the suggested command gtr ai <branch> to launch an AI coding agent in a worktree, the postCd hook defined in .gtrconfig is not executed. This means environment variables set by the hook are not available to the AI process.
Context
Our monorepo uses a postCd hook to source environment setup when navigating to a worktree:
[hooks]
postCd = source ./vars.sh
This sets environment variables that tools and test frameworks depend on to locate resources relative to the worktree.
When using gtr cd <branch>, the hook runs and everything works. But gtr ai <branch> launches the AI process directly without running the hook, so it inherits the parent shell's environment which still points at the main checkout.
Suggestion
Have gtr ai execute the postCd hook before spawning the AI process, similar to how gtr cd does for interactive shells. This would ensure the AI agent has the same environment as a developer who gtr cd-ed into the worktree.
Summary
After creating a worktree with
gtr newwe get output like this:But when using the suggested command
gtr ai <branch>to launch an AI coding agent in a worktree, thepostCdhook defined in.gtrconfigis not executed. This means environment variables set by the hook are not available to the AI process.Context
Our monorepo uses a
postCdhook to source environment setup when navigating to a worktree:This sets environment variables that tools and test frameworks depend on to locate resources relative to the worktree.
When using
gtr cd <branch>, the hook runs and everything works. Butgtr ai <branch>launches the AI process directly without running the hook, so it inherits the parent shell's environment which still points at the main checkout.Suggestion
Have
gtr aiexecute thepostCdhook before spawning the AI process, similar to howgtr cddoes for interactive shells. This would ensure the AI agent has the same environment as a developer whogtr cd-ed into the worktree.