Documentation Index
Fetch the complete documentation index at: https://mintlify.com/21st-dev/1code/llms.txt
Use this file to discover all available pages before exploring further.
What are Worktrees?
Git worktrees let you check out multiple branches simultaneously in separate directories. In 1Code, each chat session can run in its own worktree, giving you:- Isolation: Multiple agents work in parallel without conflicts
- Safety: Your main branch stays clean and untouched
- Speed: No need to stash or commit WIP when switching contexts
- Convenience: Compare branches side-by-side in your editor
How 1Code Uses Worktrees
When you create a chat in Worktree mode:Worktree creation
1Code creates a new worktree directory at:Each worktree gets:
- A unique branch name (e.g.,
clever-fox-a1b2c3) - Its own working directory
- Shared git history with your main repo
Branch initialization
The new branch starts from your chosen base branch (usually
main or master).Behind the scenes:Automatic setup
1Code runs common setup commands in the background:
npm installoryarn installfor Node.js projectspip install -r requirements.txtfor Python projects- Project-specific commands from
.1code/setup.shif present
Setup runs asynchronously - you can start chatting immediately while dependencies install.
Managing Your Worktrees
Viewing Active Worktrees
All active worktrees appear in the chat sidebar. Each chat card shows:- Branch name: The auto-generated or custom branch name
- Base branch: Which branch the worktree is based on
- Status indicators: Uncommitted changes, unpushed commits, or PR status
Switching Between Worktrees
You can work with multiple worktrees simultaneously:- In 1Code: Click any chat in the sidebar to switch to that worktree
- In your editor: Open the worktree directory directly:
- In terminal: Navigate to the worktree path shown in chat details
Comparing Worktrees
To see differences between worktrees:- Open both worktree directories in your editor
- Use your editor’s compare feature (e.g., VS Code’s “Compare Folders”)
- Or use git commands:
Worktree Lifecycle
Starting Work
When you create a new chat:- Worktree is created immediately
- Branch is pushed to remote with
-uflag - You can start sending prompts right away
During Development
As the agent works:- Changes are made in the worktree directory
- Commits are created automatically or via git panel
- Pushes keep the remote branch in sync
Finishing Work
When you’re done with a worktree:- Merge to Main
- Abandon Changes
- Keep for Later
From the chat’s git panel:
- Click Create PR to open a pull request
- Review the changes on GitHub
- Merge the PR when ready
- Delete the chat to clean up the worktree
Advanced Worktree Usage
Custom Setup Commands
Create a.1code/setup.sh script in your repository root:
.1code/setup.sh
Shared Files Between Worktrees
Some files are shared across all worktrees:.git/directory (git objects, refs, config)- Git LFS objects (if LFS is enabled)
- Git hooks
- Working directory files
.git/index(staging area)- Untracked files
- Build artifacts
Manual Worktree Commands
You can also manage worktrees using git directly:Best Practices
One Task per Worktree
Keep each worktree focused on a single feature or bug fix. This makes reviews easier and reduces conflicts.
Commit Frequently
Make small, frequent commits rather than large, infrequent ones. This makes it easier to roll back if needed.
Push Regularly
Push to remote often to back up your work and enable collaboration.
Clean Up Old Worktrees
Delete worktrees when you’re done to free up disk space and keep your workspace organized.
Naming Conventions
1Code generates branch names likeclever-fox-a1b2c3, but you can rename them:
- Click the branch name in the git panel
- Enter a descriptive name like
feature/user-auth - The branch is renamed locally and on remote
feature/add-payment-processingfix/memory-leak-in-cacherefactor/simplify-auth-flow
Troubleshooting
Worktree creation failed - repository locked
Worktree creation failed - repository locked
Cause: Another git operation is in progress or crashed.Solution:
- Wait for any running git operations to complete
- If stuck, manually remove lock files:
- Retry worktree creation
Git LFS errors in worktrees
Git LFS errors in worktrees
Cause: Repository uses Git LFS but Then recreate the worktree.
git-lfs is not installed.Solution:Cannot switch branches - uncommitted changes
Cannot switch branches - uncommitted changes
Cause: You have uncommitted changes in the worktree.Solution:
- Commit your changes via the git panel
- Or stash them:
git stash push -m "WIP" - Then switch branches
- Later:
git stash popto restore changes
Worktree still exists after deleting chat
Worktree still exists after deleting chat
Cause: Chat deletion doesn’t always remove the worktree directory immediately.Solution:
Disk space filling up with worktrees
Disk space filling up with worktrees
Cause: Multiple worktrees with large node_modules or build artifacts.Solution:
- Delete unused chats from the sidebar
- Manually clean up old worktrees:
- Add cleanup script to project:
Worktree vs Branch vs Local Mode
| Feature | Worktree | Branch | Local |
|---|---|---|---|
| Isolation | Separate directory | Same directory | Same directory |
| Main branch safety | ✅ Protected | ⚠️ Depends on workflow | ❌ Unprotected |
| Multiple agents | ✅ Yes | ❌ No | ❌ No |
| Disk usage | Higher (separate copies) | Lower (shared directory) | Lowest |
| Setup time | Moderate (copy + install) | Fast (no copy) | Fastest |
| Git required | ✅ Yes | ✅ Yes | ❌ No |
| Recommended for | Most work | Quick fixes | Experiments |
Next Steps
Git Integration
Master the built-in git client for managing branches, commits, and PRs.
Background Agents
Learn how background agents use cloud worktrees to run independently.
Worktree Isolation
Deep dive into the technical details of how worktrees work.
Configuration
Customize worktree behavior and setup commands.