Skip to content

Should gtr ai execute postCd hooks before launching the AI process? #144

@echarrod

Description

@echarrod

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions