[FEATURE] Auto-Worktree Sandbox & Audit Trail Management for Multi-Branch Agentic Development
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.
- 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. - 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. - Lifecycle Teardown: Upon task completion, Claude summarizes the diff, asks if the user wants to push a PR, and then automatically executes
git worktree removeto 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
- I am actively working on
feat/new_featurewith Claude in my main editor window. - An urgent production bug is reported. I ask Claude: "Create a fix for
fix/dashboard_issue." - Claude detects the context shift and prompts: "Would you like me to create an isolated Git Worktree for
fix/dashboard_issueto prevent context pollution?" - I approve. Claude spins up the worktree in the background, writes debugging logs to
.agent_temp/, fixes the bug, and generates a PR. - Claude asks: "Issue resolved. Should I clean up and remove this worktree?"
- 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 (likepnpmoruv) to make sandbox initialization instantaneous.