Repository navigation
How AI Tasks Work
New Task makes one worktree per agent from the repository's default branch, gets each one ready to run and starts its agent with a first prompt; Finish Task removes a worktree and its branch. The user side is AI Tasks; the panel around it is How the AI Panel Works.
Agents work best in parallel: every task in its own git worktree, often several agents racing on the same task. Our New Worktree dialog could already make a worktree, but a task needed four fields, a fresh checkout lacked .env and node_modules, and cleaning up took two steps.
sequenceDiagram
participant D as NewTaskDialog
participant T as aiTasks.createTask
participant R as Rust
participant S as sessions.startAgent
D->>R: worktree_default_base (origin/HEAD, else current branch)
D->>D: taskSlug, taskWorktrees (free names)
D->>T: plan: base, worktrees, agents, prompt
loop each worktree
T->>R: add_worktree (new branch from base)
T->>R: prepare_worktree (copy .worktreeinclude, link folders)
end
T->>S: start each agent with the prompt
taskModel.ts: taskSlug turns the task into a branch name (accents dropped, anything else a hyphen, at most 60 characters). taskWorktrees gives each raced agent slug, slug-2... with a folder next to the main checkout (defaultWorktreePath), skipping names a local branch or worktree already uses. The dialog therefore only checks the branch name's form; a taken name moves on to the next free one, and the dialog says so.
worktree_default_base (git/worktree_prepare.rs) reads refs/remotes/origin/HEAD; when its target exists, the task starts from it (origin/main). Otherwise from the current branch, else HEAD.
prepare_worktree(mainRoot, worktreePath, linkDirs):
- reads
.worktreeincludein the main checkout and copies each literal path (files and folders, links kept as links); - links each of
linkDirs(aiWorktreeLinks, defaultnode_modules) as a symlink to the main checkout's folder; - touches only paths git ignores (
is_path_ignored, also with a trailing slash for folders), never overwrites, and refuses patterns, absolute paths and..; - adds
/<folder>for each link to the shared.git/info/exclude, because git sees a link as a file and anode_modules/rule does not match it.
It returns copied, linked and skipped paths with reasons; prepareSummary turns them into the toast.
promptArguments (agents.ts) knows how each agent takes a prompt: Claude Code, Codex and Cursor take it as their last argument, OpenCode after --prompt, Gemini after --prompt-interactive, Copilot after -i. Aider, Amp and Qwen Code get it typed: the agent tab stores it as pendingPrompt, and TerminalView.typeWhenQuiet types it once the agent's start-up output has been quiet for 0.9 s (at most 20 s), then Enter.
finishTask closes the worktree's agent tabs, removes the worktree (forced only when the user agreed to lose changes; when git still finds untracked files it asks before forcing) and deletes the branch with -d. When git answers "not fully merged", it asks before -D.
| File | What it does |
|---|---|
src/lib/ai/NewTaskDialog.svelte |
The dialog |
src/lib/ai/taskModel.ts |
Branch names and worktree folders |
src/lib/ai/aiTasks.ts |
createTask, finishTask, prepareSummary
|
src-tauri/src/git/worktree_prepare.rs |
default_base, prepare
|
src-tauri/src/commands/worktree.rs |
worktree_default_base, prepare_worktree
|
Worktrees one after another. Creating them in turn keeps git's lock files out of each other's way, and a failure names the worktree it stopped at; the ones made before it stay.
Links, not copies, for big folders. node_modules can be gigabytes; a link costs nothing. Copies are for small files a task may change, like .env.
Only ignored paths. Anything git tracks is already in the checkout; copying it would hide real changes.
-
taskModel.test.ts: names, taken names, the race limit. -
agents.test.ts: prompt arguments per agent;aiTasks.test.ts: the summary. - Rust
worktree_preparetests: the default base with and without a remote, copying, linking, skipping (tracked, missing, patterns, outside), never overwriting, and a linked folder that leaves the worktree clean and removable without touching the main checkout's folder. - Checked end to end in the app: a race of two from
main,.envcopied,node_moduleslinked, the prompt passed, then Finish Task removing a worktree and its branch.
- A new agent needs its prompt mode in
agents.ts. - Retake
ai-new-task.pngwhen the dialog changes.
These pages are generated from docs/wiki. To correct something, open a pull request against the source file; edits made here are overwritten.
Using Nibtree
- Getting Started
- Welcome Screen
- Workspaces
- Files Panel
- File Operations
- File Icons
- Rounded Panels
- Editor and Tabs
- Pin Reorder and Wrap Tabs
- Single Tab Title
- Split Editor
- New File and Unsaved Changes
- Unload Hidden Tabs
- Editing Code
- Code Appearance
- Markdown Editor
- Image and PDF Preview
- Search Everywhere
- Recent Files
- Navigation Bar
- Find and Replace
- Changes and Commits
- Sign In Prompts
- Commit Box Layout
- Repository Actions
- Commit Options
- Ignoring Files
- Diffs
- Inline Diffs
- Staging View
- Revert a Change
- Resolving Conflicts
- Merge Tool
- Blame
- History and Log
- Merge Commits
- Branches and Tags
- Branches Popup
- Remotes
- Stashes
- Shelf
- Git Menu
- Git Dialogs
- Interactive Rebase
- Worktrees
- AI Agents
- AI Tasks
- AI Usage
- Keep Computer Awake
- Submodules
- Git LFS
- GitHub
- Git Console
- Terminal
- Terminal Features
- Scripts
- Navigation
- Menus
- Settings
- Settings Search
- Color Themes
- Settings Terminal and Automation
- Settings Files
- Updates
- Status Bar and Help
- Notifications
- Memory Use
- Clear Cache
- MCP and CLI
- Git Mergetool
- Keyboard Shortcuts
- Keyboard Shortcuts Editor
- Troubleshooting
- Troubleshooting Git
Developers
- Developer Guide
- Architecture
- Project Layout
- Backend
- How Folder Watching Works
- Folder Watching Bugs We Fixed
- How Workspace Files Work
- How the Preview Scheme Works
- Backend Services
- How Terminal Features Work
- Terminal Bugs We Fixed
- Frontend
- How the Rich Markdown Editor Works
- Rich Markdown Bugs We Fixed
- Git Menu Links
- Menu Keys and Routing
- Frontend Modules
- Blame Bugs We Fixed
- Project Color And Title Bar
- One Diff View
- Diff Bugs We Fixed
- Merge Tool Layouts
- Merge Tool Bugs We Fixed
- Color Theme Bugs We Fixed
- How the Connected Diff Works
- Rounded Panels Bugs We Fixed
- Update Bugs We Fixed
- Status Bar Bugs We Fixed
- MCP and CLI Bugs We Fixed
- Repository Actions Bugs We Fixed
- How the Changes Tab Works
- CodeMirror Patterns
- How the Cursor Works
- How Editor Features Work
- How the Path Bar Works
- Commands and Events
- Settings Reference
- Commands Workspace and Changes
- Commands Branches and Remotes
- Commands History and Extras
- Commands App and Tools
- Testing
- Test Suites
- Debugging
- Debugging with MCP
- Measuring Setting Memory
- How Terminal Memory Is Measured
- How Markdown Diagrams Work
- Releases and CI
- Publishing the Wiki
- Versioning and Changelog
- Browser Version Packages
- Browser Release Checks
- Docker Image
- Platforms and Signing
- Windows Support
- Windows Bugs We Fixed
- Windows MCP and CLI
- Docs and Screenshots
- UI Library
- UI Library MCP
- UI Library Bugs
- UI Library Migration
- Contributing
How features work
- Welcome screen
- Workspaces and folders
- Files panel
- File operations
- File icons
- Editor and tabs
- Pin, reorder and wrap tabs
- Single tab title
- Split editor
- New File and unsaved changes
- Unload hidden tabs
- Editing code
- Code appearance
- Markdown editor
- Image and PDF preview
- Search Everywhere
- Recent Files
- Navigation Bar
- Find and replace
- Changes and commits
- Sign-in prompts
- Commit box layout
- Repository actions
- Commit options
- Ignoring files
- Diffs
- Inline diffs
- Staging view
- Revert a change
- Resolving conflicts
- Merge tool
- Blame
- History and log
- Merge commits
- Commit tabs
- Branches and tags
- Branches popup
- Remotes
- Stashes
- Shelf
- Git menu
- Git dialogs
- Interactive rebase
- Worktrees
- AI agents
- AI usage
- Keep computer awake
- AI tasks
- Submodules
- Git LFS
- GitHub account
- Git Console
- Back and Forward
- Integrated terminal
- Scripts tool window
- Menu bar
- Settings
- Search in Settings
- Color themes
- Rounded panels
- Updates and release channels
- Status bar and help links
- Notifications
- Memory readout and memory log
- Clear Cache
- MCP server and command line tool
- git mergetool mode