codeherd

A CLI for managing parallel agentic coding sessions. It organizes projects and git worktrees, configures per-agent environments with deterministic port allocation, and orchestrates tmux sessions where AI coding agents run independently.
It is like a shepherd, but for coding agents.
Why
Running multiple AI coding agents in parallel requires isolated workspaces, separate environments, and session management. codeherd handles the infrastructure -- git worktrees for isolation, tmux sessions for persistence, deterministic ports to avoid conflicts -- so each agent gets a clean, independent workspace without manual setup.
How It Works
codeherd manages a lifecycle that takes a project from configuration to a running agent session:
Clone -> Worktree -> File Copy -> Template Processing -> Session Start
Each step has pre/post hooks for custom automation (install dependencies, start services, notify external systems). See docs/hooks.md for the full hook lifecycle reference.
Configuration
All configuration lives in ~/.config/codeherd/config.toml. Here is a full example:
[defaults]
projects_dir = "~/projects" # base directory for clones and worktrees
agent = "claude" # default agent for new sessions
# ── Agents ──────────────────────────────────────────────────────────────────
[agents.claude]
cmd = "claude"
args = ["--dangerously-skip-permissions"]
[agents.claude.env]
CLAUDE_CONFIG_DIR = "/home/user/.config/claude"
[agents.aider]
cmd = "aider"
args = ["--model", "opus"]
[agents.codex]
cmd = "codex"
args = ["--approval-mode", "full-auto"]
# ── Projects ────────────────────────────────────────────────────────────────
[projects.myapp]
repo = "[email protected]:user/myapp.git"
default_branch = "main"
# Files copied into every new worktree (see File Copy section)
files = [
"CLAUDE.md", # same path in worktree
".cursorrules", # same path in worktree
"~/.config/codeherd/prompts/safety.md:RULES.md", # absolute source, custom destination
]
# Hooks run at each lifecycle step (see Hooks section)
[projects.myapp.hooks]
post-clone = "make deps"
post-worktree = "npm install"
pre-session = "docker compose up -d"
post-session = "curl -s https://hooks.example.com/started"
[projects.api]
repo = "[email protected]:user/api.git"
default_branch = "develop"
files = [".envrc"]
[projects.api.hooks]
post-worktree = "bundle install"
Projects
Each project points to a git repository and a default branch. Clone paths mirror the repo URL under projects_dir:
~/projects/
github.com/user/
myapp/ # main clone
myapp__worktrees/
feature/ # worktree for "feature" branch
fix-123/ # worktree for "fix-123" branch
api/ # another project
Agents
Agents are CLI tools configured once and selected at session start. Any command-line tool works -- Claude Code, Aider, Codex, or a custom script. Each agent defines a command, optional arguments, and optional environment variables.
Run an agent in the current shell with ch run <agent>. Arguments after -- are forwarded to the agent's command verbatim, appended after its configured args -- for example ch run claude -- --model opus.
Profiles
Profiles let one machine carry several independent codeherd configs — e.g. a
personal and a work set of projects and agents. Enable them in the main
config and keep each profile as its own TOML file under profiles_dir:
[defaults]
profiles_enabled = true
profiles_dir = "~/.config/codeherd/profiles" # default: <config dir>/profiles
main_profile = "personal" # used when nothing else selects one
Each <profiles_dir>/<name>.toml is a full config (its own projects, agents,
projects_dir). When profiles_enabled = true, projects/agents/projects_dir
in the main config are ignored (with a warning).
The active profile is resolved by precedence, lowest to highest:
defaults.main_profile in the main config
- the
CODEHERD_PROFILE environment variable
- the
--profile / -p flag
codeherd stamps CODEHERD_PROFILE into every profile-mode session, so a nested
ch call inside a session (for example ch run <agent>) defaults to that
session's profile without needing --profile.
Sessions
Sessions are tmux sessions anchored to a project and branch. They run independently and persist across disconnects:
tmux sessions:
codeherd # TUI dashboard
myapp-feature # Claude Code working on feature
myapp-fix-123 # Aider fixing a bug
api-experiment # another agent exploring an idea
Session environment