[FEATURE] Auto-Worktree Sandbox & Audit Trail Management for Multi-Branch Agentic Development

Status Open
Maintainer reply None cached
Activity 0 comments · opened Sep 1, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

When managing dual-track development (e.g., developing feat/new_feature while urgently addressing fix/dashboard_issue), AI agents suffer from severe context pollution if branch switching occurs in a single working directory. The agent's conversation memory conflicts with the newly checked-out code on the disk.

Additionally, when the agent generates temporary scripts (e.g., Python scripts for debugging, API testing, or data fetching), these are often placed in global directories like /tmp. This creates local environment clutter, lacks a traceable history for Code Reviewers, and poses a significant security risk in enterprise environments due to unmanaged, potentially sensitive execution logs.

Proposed Solution

Introduce an automated Git Worktree Sandbox Mode with integrated Audit Trail Management.

  1. Automated Isolation: When the agent is tasked with a new branch/feature, it detects the context shift and prompts the user to initialize a Git Worktree (git worktree add <path> <branch>) to act as an isolated sandbox, leaving the main workspace untouched.
  2. Audit Trail Directory (.agent_temp/): Automatically create an .agent_temp/ directory within the worktree and dynamically add it to .gitignore. All AI-generated test scripts, local databases, and logs are strictly executed and stored here.
  3. Lifecycle Teardown: Upon task completion, Claude summarizes the diff, asks if the user wants to push a PR, and then automatically executes git worktree remove to destroy the sandbox and safely wipe the temporary files.

Alternative Solutions

  • Manual Repository Cloning: Wastes disk space, breaks shared Git stashes, and requires duplicate dependency installations.
  • Manual Git Worktree Setup: Breaks the developer flow, requiring the user to manually manage paths, create the worktree, open a new window, and clean up afterward.
  • Single-Directory Branch Switching: Leads to high AI hallucination rates as the LLM context window retains memory of the previous branch's code structure.

Priority

High - Significant impact on productivity

Feature Category

File operations

Use Case Example

  1. I am actively working on feat/new_feature with Claude in my main editor window.
  2. An urgent production bug is reported. I ask Claude: "Create a fix for fix/dashboard_issue."
  3. Claude detects the context shift and prompts: "Would you like me to create an isolated Git Worktree for fix/dashboard_issue to prevent context pollution?"
  4. I approve. Claude spins up the worktree in the background, writes debugging logs to .agent_temp/, fixes the bug, and generates a PR.
  5. Claude asks: "Issue resolved. Should I clean up and remove this worktree?"
  6. I approve. The sandbox is safely destroyed, the .agent_temp/ execution logs are wiped, and my main workspace remains completely uninterrupted.

Additional Context

  • Security & Auditability: Retaining test scripts in .agent_temp/ allows human reviewers to see how the AI tested its own code before the PR was made. Tying this directory's destruction to the Worktree teardown ensures zero data leaks.
  • Technical Constraints (Dependencies): Creating a new worktree often requires reinstalling dependencies (e.g., node_modules). Future iterations of this feature could integrate hard-linking or global caching (like pnpm or uv) to make sandbox initialization instantaneous.

View original on GitHub ↗