Lifecycle Management¶
Worktree lifecycle can be as simple or structured as your workflow requires.
Basic Lifecycle¶
The minimal pattern:
Create a worktree, do the work, remove it when done. No tracking, no gates. Isolation.
Safety Verification¶
Adding checkpoints prevents common problems:
Pre-work baseline: Run tests before making changes to distinguish pre-existing failures from your changes. If possible find a way to persist the result of this to help ground the agent.
Show the diff to the user before committing. This prevents accidental inclusion of unintended changes.
Pre-merge confirmation: Ask before merging. The user decides what lands on main.
User Approval Gates¶
Agents operating in worktrees should not make permanent changes without user consent:
- Implementation complete
- Show diff summary and proposed commit message
- User decides: approve, review more, or modify
- Only commit after explicit approval
This pattern applies to merges too. Agents propose changes and users approve them.
Structured Workflows¶
For teams needing more rigor, lifecycle can be formalized:
- Phase tracking: know whether a worktree is in setup, development, or review
- Edit guards: Only allow file modifications during active development
- Require tests to pass before requesting review
- Audit trails: Record timestamps and state transitions for compliance
The right level of structure depends on context. Personal projects need less ceremony than enterprise compliance environments.
Choosing Complexity¶
| Need | Approach |
|---|---|
| Personal projects | Basic lifecycle |
| Team development | Add safety verification |
| Compliance requirements | Add audit trails |
| Multi-service projects | Add service coordination |
Start simple. Add formality when problems justify the overhead.