An autonomous multi-agent software development system: agents work Linear issues and GitHub PRs unattended on a dedicated machine per project, built on herdr as the terminal and agent-state substrate, with Claude Code and Codex as the agent harnesses.
Foregent is not itself a harness. It provides solutions for:
- Multi-agent orchestration and worktree isolation, and
- Delivery of webhook notifications from Linear and GitHub to workers.
docs/ARCHITECTURE.md describes the system — read it first. Planned work
lives in the Linear project Foregent.
foregent serve runs a small FastAPI service — the bridge. You give it a
Linear issue key and a directory; it claims the issue in Linear, opens a herdr
workspace on that directory, starts an agent in it, and briefs it with the
foregent-worker skill. The agent owns the issue end to end. Which harness it
runs is yours to name — --provider claude or --provider codex, Claude Code
by default — and so is the model it runs, --model, which the harness chooses
for itself when you name none. Nothing else about the dispatch changes with
either.
Linear pushes what happens next. A comment or a field change on an agent's own
issue arrives at POST /webhooks/linear, is authenticated against the
workspace's signing secret, and is delivered to that agent as a prompt —
whether it is working or parked on a blocker. Deliveries are queued, so the
route answers Linear at once instead of waiting on a busy agent. GitHub pushes
the other half: a review or a review comment on an agent's pull request arrives
at POST /webhooks/github and reaches the same agent, matched by the issue its
branch names. The agent reports back through the MCP tools the bridge serves:
report_blocked, complete_task, and queue_sub_issues, which hands its
own sub-issues to the queue to be worked by agents of their own.
The bridge keeps no database. Its issue → agent map is in memory and is rebuilt from the live herdr agents at startup.
Install these on the machine that runs the agents:
- uv — Python 3.13+ toolchain and runner.
curl -LsSf https://astral.sh/uv/install.sh | sh - herdr — terminal and agent-state server.
curl -fsSL https://herdr.dev/install.sh | sh - An agent harness, one or both. Each binary must be on
PATH, becauseforegent setupcalls it, and each must be signed in — an unauthenticated harness opens a login screen that herdr reads as a stuck agent.- Claude Code — the default.
- Codex —
codex login.
- Jujutsu (
jj) — the version control the worker skill tells agents to use. Colocated with git. - cloudflared — the public HTTPS front for the webhook endpoint. The bridge listens on localhost and Linear will not deliver to it directly.
- A Linear API key and, for Pull Request mode, a GitHub token.
From a checkout, for development:
uv sync
uv run foregent --versionOr install the CLI on the box:
uv tool install .The rest of this document writes foregent; from a checkout, prefix it with
uv run.
export LINEAR_API_KEY=lin_api_... # bridge and agents
export GITHUB_TOKEN=ghp_... # agents, Pull Request modeThe Linear key identifies foregent itself: the bridge assigns claimed issues to that account, and ignores events written by it, so agents never wake on their own comments. Create one in Linear under Settings → API.
These belong in the environment of the herdr server, because every pane herdr opens inherits it. A herdr server started before the variables were exported gives its agents nothing.
foregent setupFor every harness foregent can run agents on, this copies the skills foregent
ships into that harness's own skill directory — ~/.claude/skills/ and
~/.codex/skills/, which read the same SKILL.md — and adds the Linear and
GitHub MCP servers to its machine-level config, where agents and your own
sessions both read them. Both configs store the name of the variable holding
each token, never the token itself.
Every harness is provisioned whether or not you will queue it: the files are small, and one provisioned first-use-first is one whose first dispatch is where you find out it was not.
Run it once per machine, and again after every foregent upgrade. The bridge also rewrites the packaged skills before every launch, so an agent is always briefed from the version foregent ships — a hand-edited skill in a harness's skill directory does not survive a dispatch.
setup warns when a credential is unset. Fix that before dispatching: an
unauthenticated agent discovers the problem only once it is working an issue.
herdr integration install claude
herdr integration install codexThis lets each harness report its session identity back to herdr.
Both harnesses ask whether they may work in a directory they have not seen, and
answer nothing until told. herdr reads that dialog as blocked, so dispatch
into an untrusted directory fails.
Every agent runs in a fresh per-issue workspace, so for Claude Code trust the
directory those are built under — once, and every workspace under it is
covered, in ~/.claude.json:
{ "projects": { "/home/you/.foregent/workspaces": { "hasTrustDialogAccepted": true } } }Foregent falls back to writing the entry for each workspace it creates if it
finds one untrusted, so a box that skips this still dispatches. Doing it here
is better: ~/.claude.json is rewritten by every running Claude Code session,
and the entry above means foregent never has to touch it.
Codex inherits nothing from a parent directory — it resolves trust to a git
repository's root, and a jj workspace has no .git — and its
--dangerously-bypass-approvals-and-sandbox does not skip the dialog either.
So foregent appends an entry per workspace to ~/.codex/config.toml:
[projects."/home/you/.foregent/workspaces/JIM-42"]
trust_level = "trusted"There is nothing to pre-accept for Codex, and that file grows one entry per issue.
Linear and GitHub deliver to a public HTTPS URL, and the bridge listens on
localhost, so something has to front it. cloudflared does, and a quick tunnel needs no
account and no domain:
cloudflared tunnel --url http://127.0.0.1:8577It prints a https://<random>.trycloudflare.com URL. That URL changes every
time the process restarts, which is fine while you are trying this out and no
good for a box that stays up — for that, create a
named tunnel
against a domain you own, and run it as a service.
Then, in Linear, open Settings → Administration → API → New webhook (admin
permission required) and point it at <tunnel URL>/webhooks/linear. Subscribe
it to issues and comments. Copy the signing secret Linear shows you into the
bridge's environment, next to the other credentials:
export LINEAR_WEBHOOK_SECRET=lin_wh_...Restart the bridge and comment on a tracked issue. The bridge answers 401 for a delivery whose signature does not match, and 503 when it holds no secret to check one against. See Linear's webhook documentation for the payload shapes and the retry schedule — a delivery is retried three times, after one minute, one hour, and six hours, so a bridge that is down for a working day loses the event.
An authenticated delivery about an issue no agent here is working — which is most of them — is answered 200 and dropped, so Linear is never told a delivery failed for being none of foregent's business. The bridge logs the deliveries it queues for an agent and stays quiet about the rest, so to confirm the webhook is wired up, comment on an issue an agent is actually working.
In Pull Request mode, the same tunnel carries what GitHub says about the pull
requests agents open. Create an
organization webhook
— one hook covers every repository foregent works — pointed at
<tunnel URL>/webhooks/github, with content type application/json;
foregent does not read the form-encoded delivery and answers 400 for one.
Subscribe it to pull requests, pull request reviews, pull request review
comments, pull request review threads, issue comments, pushes, and workflow
runs. Put the secret GitHub asks you to invent in the bridge's environment:
export GITHUB_WEBHOOK_SECRET=...The same answers as the Linear endpoint: 401 for a signature that does not
match, 503 when the bridge holds no secret to check one against, and 200 for
everything it accepts. GitHub keeps every attempt and the code it got back
under Recent Deliveries on the hook's own page, so the ping it sends on
creating the hook is the quickest confirmation the endpoint is reachable.
Agents run inside a herdr session. Start or attach to the one foregent should use:
herdr --session foregentThen run the bridge in a pane of that session — herdr injects
HERDR_SOCKET_PATH into every pane it owns, so the bridge finds its own
session:
foregent serve # add --dev to restart on source changesOutside a pane (a systemd unit, a plain SSH shell), name the session explicitly, or the bridge lands in herdr's default session:
FOREGENT_HERDR_SESSION=foregent foregent serveStartup logs the session and socket it resolved to, and a warning for any MCP server or credential the machine is missing.
Do not start the herdr server from inside a Claude Code session. Every pane inherits
CLAUDECODE=1, which silently disables transcript saving in the agents and breaks resume.
foregent queue JIM-42 -d ~/src/myrepo # queue an issue against a repo
foregent queue JIM-42 -d ~/src/myrepo --provider codex # …on Codex instead
foregent queue JIM-42 -d ~/src/myrepo --model claude-opus-5 # …on a named model
foregent status # what is tracked, and its statestatus heads its table with when Linear last delivered. Agents are woken by
webhook and nothing else, so a hook that has stopped looks exactly like a
quiet morning; a timestamp hours old is what tells the two apart.
queue records the issue and dispatches it if there is capacity. How many
agents run at once is the box's, not the project's: up to
FOREGENT_MAX_AGENTS (default 5) live — each in its own workspace — and up to
FOREGENT_MAX_ACTIVE (default 3, independent of FOREGENT_MAX_AGENTS) worked
at once, since a parked agent gives back the run slot it is not using. That
holds in bootstrap mode too: agents there branch from the same main, and the
bridge only ever advances it forward, so the second to finish is refused,
rebases onto the main it can now see, and completes again. A sub-issue is
the exception: an agent that queues its own sub-issues is about to park on
them, holding a live slot the whole time, so its children need only a free run
slot and FOREGENT_MAX_AGENTS binds what an operator queues rather than what
a worker delegates. Dispatch assigns the
issue to the foregent account in Linear and moves it to In Progress, and
completion moves it to Done unless the agent already closed or cancelled it,
so the team must have states with exactly those two names. A queued issue
waits its turn, in the order it was queued, and the queue survives a restart
of the bridge.
The bridge keeps what it is tracking in one file,
~/.local/state/foregent/state.json (FOREGENT_STATE_FILE), rewritten on
every change. A restart reads it back and checks it against the agents herdr
still has: an issue whose agent is gone shows as Orphaned, one whose agent
is still running keeps its record, and the queue is dispatched. Delete the
file to start clean; the bridge then adopts every running agent off its name
and forgets the queue.
-d is the repository, not the agent's working directory. Dispatch builds
the agent a jj workspace of its own from it — ~/.foregent/workspaces/JIM-42
by default, FOREGENT_WORKSPACE_ROOT elsewhere — created fresh on main, so
no agent inherits the last one's dirty working copy. Completion removes it. A
directory that is not a jj repo is used as the agent's cwd as it stands.
Inside a workspace there is no .git, so raw git and gh do not work there;
jj does, and reaches the same repository.
A fresh workspace holds only what version control tracks, so an untracked
.env or local settings file is not in it. List those in a
.worktreeinclude file at the repository root and dispatch copies them
into every workspace it builds. The file is
Claude Code's convention
and uses .gitignore syntax; a path is copied when it matches the file and
is itself gitignored, so tracked files are never duplicated. A symlink is
recreated as a symlink to the file it originally named, not followed and
copied.
.env
.env.local
config/secrets.json
What the agent does next is the foregent-worker skill
(src/foregent/skills/foregent-worker/SKILL.md): read the issue, do the work,
keep Linear current, land the change in the mode foregent read off the repo's
git remotes and named in the brief — for foregent itself, as a pull request —
then call complete_task.
Completion tears the agent down and dispatches the next queued issue.
An issue with sub-issues is not worked by one agent. The agent creates them
in Linear, hands the keys to queue_sub_issues, and parks on them: each is
dispatched to an agent, a workspace and a pull request of its own, and the
parent is woken with one line per child that lands, so it can queue the next
wave or finish.
An agent that hits an external dependency calls report_blocked and stays
alive in its workspace with its context intact. It keeps holding its live
slot, so FOREGENT_MAX_AGENTS is in practice how many pull requests may be
open and waiting for review at once — but it gives back its run slot, so a
fresh agent can be launched to use the box while it waits, and
FOREGENT_MAX_ACTIVE (default 3) is what bounds how many run at once
instead. Comment on the issue in Linear, or review the agent's pull request
on GitHub; either reaches the agent as a prompt, and
delivering it unblocks the issue — taking a run slot back to do it, ahead of
any fresh agent waiting on the same one. A review is matched to the agent by
the branch it is on, so nothing has to be told which pull request is whose.
Observe by attaching, from the box or from a laptop:
herdr --session foregent
herdr --remote <ssh-target> --session foregentAttaching is read-only by convention. Watch; do not type.
A managed repo can put a FOREGENT.md at its root. It is the first thing an
agent reads, it holds the project's own rules — what the issue labels mean, how
work is scoped — and it wins over the worker skill wherever the two differ.
This repo's own copy is a working example: it maps bug, feature,
refactor, design, and investigation onto what the agent should produce for
each.
A project with no FOREGENT.md has no project-specific rules, which is a valid
state.
| Variable | Purpose |
|---|---|
LINEAR_API_KEY |
The bridge claims issues with it; agents authenticate the Linear MCP with it. Required. |
GITHUB_TOKEN |
Agents authenticate the GitHub MCP with it. |
LINEAR_WEBHOOK_SECRET |
The signing secret of the Linear webhook, checked against every delivery. Required: without it POST /webhooks/linear answers 503. |
GITHUB_WEBHOOK_SECRET |
The secret of the GitHub webhook, checked against every delivery. Without it POST /webhooks/github answers 503. |
FOREGENT_HERDR_SESSION |
The herdr session to run agents in. Falls back to the session the bridge process runs in, then herdr's default. |
FOREGENT_API_URL |
Base URL of the bridge (default http://127.0.0.1:8577). serve binds the host and port from it; the CLI and the agents' MCP config both address it. |
FOREGENT_WORKSPACE_ROOT |
Where per-issue workspaces are built (default ~/.foregent/workspaces). |
FOREGENT_LOG_LEVEL |
What level serve logs at (default info), for uvicorn's loggers and foregent's own. --log-level overrides it. |
FOREGENT_MAX_AGENTS |
How many agents hold a live slot at once — in flight, working or parked, in either mode (default 5). Operator-queued issues only: a sub-issue a worker delegates answers to the run limit alone. |
FOREGENT_MAX_ACTIVE |
How many of those are actually worked at once (default 3, independent of FOREGENT_MAX_AGENTS). A parked agent gives back its run slot, so a fresh one can use it while others wait on review. |
FOREGENT_STATE_FILE |
Where the bridge keeps the issues it is tracking (default ~/.local/state/foregent/state.json). |
CLAUDE_CONFIG_DIR |
Relocates ~/.claude, honored by foregent setup. |
CODEX_HOME |
Relocates ~/.codex, the same. |
uv run python -m unittest discover -s tests -t . # 518 unit tests, ~9s
uv run ty check # type checkThe unit tests touch no network and no herdr. Two integration suites are skipped unless you opt in:
FOREGENT_HERDR_AGENT_TESTS=1 uv run python -m unittest tests.test_herdr_integrationruns real Claude Code agents in the herdr session your shell is in — slow, and it costs tokens.
LINEAR_API_KEY=... LINEAR_TEST_ISSUE_ID=JIM-1 uv run python -m unittest tests.test_linear_integrationtalks to the real Linear API and mutates that issue (assignee and state). Use a scratch issue.
Foregent is developed by itself: issues in the Linear project Foregent are
worked by foregent-launched agents inside a devbox. Keep
docs/ARCHITECTURE.md correct in the same commit as any change that makes
it wrong.