Skip to content

Replace temp-clone with git worktree for agent-agnostic session isolation #399

Description

@itdove

Summary

Replace DevAIFlow's temp directory cloning (temp_directory.py, ~560 lines) with native git worktree commands for investigation and ticket-creation session isolation. This is faster, uses less disk space, and works with all 8 agent backends.

Full proposal document: docs/proposals/git-worktree-isolation.md

Why git worktree, not Claude Code --worktree?

Claude Code has a --worktree flag, but DevAIFlow supports 8 agent backends (Claude, Cursor, Windsurf, Copilot, Aider, Continue, Crush, Ollama). Using git worktree add/remove directly keeps the feature agent-agnostic — no changes needed to AgentInterface.

Current state

  • devflow/utils/temp_directory.py (~560 lines) — full git clone to /tmp/, complex cleanup
  • Session creation: 2-10 seconds (full clone)
  • Disk usage: full duplicate of repository

Proposed state

  • devflow/utils/worktree.py (~100 lines) — git worktree add/remove wrappers
  • Session creation: ~100ms (worktree add)
  • Disk usage: shared .git directory, only working files duplicated
  • Worktrees stored in .daf/worktrees/<session-name>/

Changes required

New: devflow/utils/worktree.py (~100 lines)
Remove: devflow/utils/temp_directory.py (~560 lines)
Modify:

  • devflow/cli/commands/git_new_command.py — use worktree instead of temp-clone
  • devflow/cli/commands/open_command.py — restore session in existing worktree
  • devflow/cli/signal_handler.py — worktree cleanup on exit
  • devflow/session/models.py — add worktree_path field

Net: ~460 lines removed

Edge cases

  • Non-git repos: fall back to current temp-clone
  • Dirty worktree on exit: prompt user to keep or remove
  • Session reopen: check if worktree exists, recreate from branch if not
  • Env files: .dafworktreeinclude pattern copies gitignored files into worktree
  • git worktree add used instead of git clone for session isolation
  • Works with all 8 agent backends (agent-agnostic)
  • temp_directory.py removed
  • Worktrees stored in .daf/worktrees/ at repo root
  • .dafworktreeinclude copies env files into worktrees
  • Clean worktree removal on session exit
  • Non-git repos fall back gracefully
  • All existing tests pass

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions