AI Agents workflow

How I manage AI Agents to achieve coding tasks, using git worktrees

Principles

At the time of this writing I am using Claude. The Company I am working for provided me a subscription and I am gradually entering into agentic AI.

Claude models work pretty well right now, however I do not want to tie up myself to Anthropic. This is a general principle of mine

Be modular. Whenever possible, a “thing” should be like a lego block that you can remove and replace with another that is equivalent.

This “Modularity principle” can be found in many other situations, for example every sailor must know how to use a sextant. Even if nowadays cruises are highly automated, if you sail you must be able to figure out your position in the middle of the see, using analogic equipment.

So, I use a CLAUDE.md file, but I do not commit it. Instead I prefer to use a general AGENTS.md file.

Folder structure

Another shift in my current git workflow is using worktrees. Usually I had a single folder with a repository. Instead now for bigger projects I prefer to have a root folder that can contain for example

  • a .git file pointing to a git bare repo
  • the git bare repo
  • a .envrc file with Environment variables, handled by direnv
  • a folder for every git worktree
  • a CLAUDE.md file

Still I see many articles on the Internet that are not using git bare repositories.

To clone the repo use the --bare flag and create a .git file, for instance

git clone git@github.com:user/repo.git --bare .bare.git
echo 'gitdir: ./.bare.git' > .git

Then I have my global CLAUDE.md that uses my git-worktree skill to achieve tasks using git worktrees.

So to start a task, in a claude session:

/git-worktree task-name

or

/git-worktree task goal description bla bla

Git issues

Notice that there can be some git issues, for example if you do a git commit ammend and run git push --force-with-lease you can get rejected. One solution is to run this command after you clone the repo.

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

See also Git worktree like a boss article.