A3S Docs
A3S CodeExamples

Git Worktree

Parallel workspace isolation with the git builtin tool — create, list, remove, and status

Git Worktree

The git builtin tool provides Git operations including parallel workspace isolation via Git worktrees. Create feature branches in separate directories, work on them independently, and clean up when done — all without switching branches. Git auto-installs if not available.

The git tool requires the session workspace to be inside a Git repository with at least one commit.

Direct Tool Calls

import { Agent } from '@a3s-lab/code';

const agent = await Agent.create('~/.a3s/config.hcl');
const session = agent.session('/my-git-repo');

// Check repository status
let r = await session.tool('git', { command: 'status' });
console.log(r.output);

// Create a worktree for a feature branch
r = await session.tool('git', {
  command: 'worktree',
  subcommand: 'create',
  name: 'feature-auth',
  path: '/my-git-repo/wt-feature-auth',
});
assert(r.exitCode === 0);

// List all worktrees
r = await session.tool('git', { command: 'worktree', subcommand: 'list' });
console.log(r.output); // Shows main + feature-auth

// Remove the worktree
r = await session.tool('git', {
  command: 'worktree',
  subcommand: 'remove',
  path: '/my-git-repo/wt-feature-auth',
});
assert(r.exitCode === 0);

Run: node examples/test_git_worktree.ts Source: sdk/node/examples/test_git_worktree.ts

from a3s_code import Agent

agent = Agent.create("~/.a3s/config.hcl")
session = agent.session("/my-git-repo")

# Check repository status
r = session.tool("git", {"command": "status"})
print(r.output)

# Create a worktree for a feature branch
r = session.tool("git", {
    "command": "worktree",
    "subcommand": "create",
    "name": "feature-auth",
    "path": "/my-git-repo/wt-feature-auth",
})
assert r.exit_code == 0

# List all worktrees
r = session.tool("git", {"command": "worktree", "subcommand": "list"})
print(r.output)  # Shows main + feature-auth

# Remove the worktree
r = session.tool("git", {
    "command": "worktree",
    "subcommand": "remove",
    path: "/my-git-repo/wt-feature-auth",
})
assert r.exit_code == 0

Run: python examples/test_git_worktree.py Source: sdk/python/examples/test_git_worktree.py

LLM-Driven Usage

The agent can use git worktree autonomously when asked to work on parallel features:

Subcommands

Prop

Type

API Reference

git input schema (worktree commands)

Prop

Type

On this page