A single conversation to manage all of your AI sessions - that keeps working while you're away.
Your main conversation thread is the closest digital mapping to your own internal thread of consciousness. Everything else flows into a unified inbox that surfaces only what needs your attention.
Inspired by You Are The Main Thread — you are the bottleneck, so spawn parallel AI sessions and let them handle the work while you stay in flow.
Mainloop is a single-owner system: one owner, their projects and their agents. The Go server and React app in this repository are what runs; the earlier Python and SvelteKit stack is gone.
Implemented (the code path exists and is tested, mostly against fakes; each spec says what has been proven live):
- Main thread. One conversation with a native Claude Code or Codex session: a live view of the running turn, steering, images and file attachments (chat, sessions).
- Projects and tasks. Each project has a standing supervisor that takes work from the main thread and hands it to workers in isolated workspaces. Tasks, reports and handoffs are durable (projects, project supervisor, tasks, delegation).
- Inbox. One Needs-you list of questions, plan reviews and approvals, answered in place, with push to the owner's phone through ntfy or Apple push (inbox, push notifications).
- Publishing. Agents hold no GitHub credential. They fetch and push through Mainloop's Git proxy, and open and merge pull requests through tools that apply the project's merge policy (git transport, push gate, pull requests, merge policy, CI checks).
- Wake-ups. Loops wake an agent on a task, pull request, quiet or time trigger, and scheduled runs start sessions on a cron line (loops, scheduled runs).
- Context. Project instructions and memory, owner memory, agent dotfiles and searchable transcripts (project context, owner memory, agent dotfiles, transcripts).
- Workspaces. Environments, previews, and a live dev loop on a staging target (workspaces, environments, dev loop).
- Privileged actions. Off by default. An agent asks for a credentialed action it cannot run itself, the owner approves that exact action, and Mainloop runs it once (privileged actions).
- iPhone app. The web app in a native shell that holds the device's keys (iOS app, devices).
Proposed, not built: goals with guardrails (goals) and durable project warm state (warm state). ROADMAP.md has the direction.
flowchart LR
you["You<br/>phone or laptop"] --> web["React app<br/>(browser or iPhone app)"]
web --> api
subgraph cp["Mainloop control plane (namespace mainloop)"]
api["Go server<br/>REST API, MCP tools,<br/>Git proxy, reconcilers"]
db[("PostgreSQL<br/>the ledger")]
api <--> db
end
api -->|"A2A turns,<br/>Session lifecycle"| kagent["kagent controller"]
subgraph sb["Substrate actors (one per Session)"]
main["Main thread<br/>Claude Code or Codex<br/>gVisor"]
ws["Workspace<br/>Claude Code or Codex<br/>+ git checkout<br/>microVM"]
end
kagent --> main
kagent --> ws
main -. "MCP tools" .-> api
ws -. "MCP tools, git fetch/push" .-> api
api -->|"GitHub App tokens"| gh["GitHub"]
Mainloop is the control plane: it records every message, delivery, task and approval in PostgreSQL, then hands each turn to kagent over A2A. kagent runs each native Claude Code or Codex session in its own Substrate actor, and the agents call back into Mainloop only through its MCP tools and Git proxy.
State lives in three places, and none of them is the actor's memory:
| What | Where |
|---|---|
| Conversations, deliveries, tasks, approvals, policy | Mainloop's PostgreSQL ledger |
| Native session history (the CLI's own transcript) | The kagent Session and its snapshots |
| Code | Git: the workspace checkout, then GitHub |
flowchart TB
agent["Agent<br/>(what Mainloop names)"]
tmpl["AgentTemplate<br/>instructions, model,<br/>tool bindings"]
harness["Harness<br/>runtime (Claude or Codex), image,<br/>CPU/memory, worker pool,<br/>env, idle TTL, git origins"]
model["ModelConfig<br/>provider, model,<br/>auth Secret"]
mcp["RemoteMCPServer<br/>a tool server URL"]
pool["WorkerPool<br/>sandbox class:<br/>gVisor or microVM"]
agent --> tmpl
agent --> harness
tmpl --> model
tmpl --> mcp
harness --> pool
An Agent is an AgentTemplate (what it does) plus a Harness (how it runs). kagent compiles the pair into an immutable revision; each Session pins one revision and runs as one Substrate actor.
The Agents Mainloop uses by default (the names are server settings; the resources, with their CPU and memory, belong to the deployment):
| Agent | Used for | Sandbox | Tools |
|---|---|---|---|
mainloop-main |
the Claude main thread | gVisor | mainloop |
mainloop-main-codex |
the Codex main thread | gVisor | mainloop |
claude-workspace |
code tasks, supervisors, owner workspaces | microVM, git | mainloop, mainloop-merge-approval |
codex-workspace |
the same, on Codex | microVM, git | mainloop, mainloop-merge-approval |
claude-subscription |
coordination children (no repository) | microVM | mainloop |
codex-subscription-https |
the same, on Codex | microVM | mainloop |
A deployment can run other kagent Agents that Mainloop does not start, such as infrastructure ops agents; see Agents and permissions.
flowchart LR
subgraph actor["Workspace actor (microVM)"]
cli["Claude Code<br/>permissions skipped"]
repo["/data/workspace<br/>checkout"]
end
cli -->|"ml_ bearer<br/>(no GitHub token)"| git["Mainloop Git proxy<br/>read: one repo<br/>push: own branch only"]
cli -->|"ml_ bearer"| tools["Mainloop MCP<br/>open PR, merge, report"]
cli -->|"allowlist"| reg["Package registries"]
git -->|"GitHub App token"| gh["GitHub"]
tools -->|"merge policy:<br/>auto or approval"| gh
A coding agent runs with Claude Code's permission prompts skipped (kagent's managed profile uses bypassPermissions), because the sandbox is the boundary. The actor holds no GitHub credential: it fetches and pushes through Mainloop's Git proxy, which lets it push only its own branch, and it opens and merges pull requests through MCP tools that apply the project's merge policy.
Anything that needs a credential the sandbox does not hold goes through a
privileged action: a typed request the owner approves on a
Needs-you card. A separate process, serve-executor, holds those credentials and runs the approved
action once. Privileged actions are off unless the deployment turns them on.
sequenceDiagram
actor You
participant API as Mainloop API
participant DB as PostgreSQL
participant DL as Delivery loop
participant K as kagent
participant S as Native session
You->>API: POST /sessions/{session_id}/message
API->>DB: message + delivery (recorded)
API-->>You: 200 ok
DL->>DB: claim (sending)
DL->>K: A2A send (messageId = delivery id)
K->>S: wake the actor if asleep, run the turn
S-->>K: tool calls, text, status
K-->>DL: task events
DL->>DB: reply, delivery completed
Note over You,S: The live view streams the same turn over a WebSocket
You->>API: message while the turn runs (steer: true)
API->>DB: delivery_steers row
API-->>You: 202 steered
DL->>K: A2A message on the running task
K->>S: joins the turn at its next tool boundary
You->>API: message while the turn runs (no steer)
API->>DB: delivery (queued)
API-->>You: 202 queued
Note over DB: promoted to recorded when the open turn ends
Every message becomes a ledger row before anything is sent, and a session has at most one open turn. A message sent mid-turn either joins it (a steer) or waits as queued for its own turn; a steer that the turn never consumed turns into the next queued message.
More diagrams (approvals, delegation, delivery to production) and the detail behind these are in Agents and permissions. Workspaces, previews and sleep are in Architecture.
The stack is a Go server (server/) and a React app (web/). You need a PostgreSQL 16
server and an AGENT_TOKEN_KEY for the API. The full local setup is in
CONTRIBUTING.md.
To run both in a local Kind cluster instead, with Docker, kind, kubectl and DevSpace
installed, run make dev from the repository root. The web app is then at
http://localhost:5173 and the API at http://localhost:8000. See
Kind in the development environment.
# API: owner API on http://localhost:8000
cd server && go run ./cmd/mainloop serve-api
# UI, in another terminal: http://127.0.0.1:5173 (forwards /api to the API)
pnpm install --frozen-lockfile --filter web...
pnpm --dir web devInstall a private GitHub App on the repositories Mainloop should manage. Set
GITHUB_APP_ID to its numeric App ID and GITHUB_APP_PRIVATE_KEY to single-line
base64 of its unencrypted RSA PEM (at least 2048 bits), in the server's environment
(in the cluster, the mainloop-secrets Secret). Leading and trailing ASCII whitespace is ignored for both values;
interior whitespace is rejected. Mainloop discovers installations and mints short-lived tokens for
one repository and the requested operation's permissions. There is no PAT
or anonymous fallback. App permissions and cache behavior are in
Pull requests and production deployment.
The get_issue, get_pull_request, list_dependabot_alerts and check_status read-only tools, create_issue and
comment_issue (the main thread and coordination tasks file issues and comments),
comment_pull_request (any task comments on or reviews a pull request; never approves), and
watch_checks (which waits for CI without holding the agent's turn and messages the session when
CI settles), reuse the same App credential; see
GitHub issue, pull request and Dependabot alert reads,
GitHub issue and pull request comments and CI checks.
The web_fetch MCP tool reads one public web page as text, from any public host. It is off for
every agent until the owner turns it on for a session (POST /sessions/{session_id}/web-fetch) or creates
a task with web_fetch. The server refuses private, loopback, link-local and metadata addresses
when it dials them, on every redirect. It records each fetch and limits each owner to
MAINLOOP_WEB_FETCH_PER_MINUTE fetches a minute (default 30). MAINLOOP_WEB_FETCH_DENY_CIDRS
adds ranges to refuse. See Web fetch.
The Helm chart deploys Mainloop. Supply environment-specific domains, credentials, and storage through your own values file, and apply production changes through your GitOps workflow (details).
The Publish images workflow builds and pushes production images
on every push to main. Each image is built natively for linux/amd64 and linux/arm64, and the
two builds are joined into one multi-arch index. It can also be started with workflow_dispatch
for a selected ref. The backend image is the Go server (server/Dockerfile, target prod,
context server/). The frontend image is the React app (web/Dockerfile, repository-root
context); it is built with VITE_API_URL=/api, so it calls the API on its own origin, where the
gateway routes /api to the backend.
Images are published to ghcr.io/oldsj/mainloop-backend and
ghcr.io/oldsj/mainloop-frontend, tagged with the first seven characters of the
source commit SHA (the per-architecture builds add -amd64 or -arm64). Each build's job summary
records the full source SHA, tag, digest, and copyable image@sha256:... reference. When both
indexes exist on main, the chart job publishes oci://ghcr.io/oldsj/charts/mainloop version
0.1.<run number> with both digests pinned. A deployment that tracks 0.1.* deploys each merge;
one that pins an exact chart version runs that version until the pin is bumped. Rolling back is
pinning the previous chart version
(details). GET /health reports
the revision the running server was built from.
The image jobs authenticate with GITHUB_TOKEN (contents: read,
packages: write) and use a separate GitHub Actions cache for each image and architecture.
Existing GHCR packages must grant this repository Actions write access. New pushes cancel
older runs for the same ref; a cancelled run may have published only some images and no chart, so
use a fully successful run for a pin update.
The other images (the workspace development and cache images, the command.exec toolbox and the
workspace environment images under images/) have their own workflows; see
GitHub automation.
mainloop/
├── api/ # OpenAPI contract shared by server/, web/ and ios/, and the MCP tool manifest
├── server/ # Go server: API, MCP, Git transport, executor and migrations (one binary)
├── web/ # React app and design system
├── ios/ # iPhone app (SwiftUI); its API client is generated from the contract
├── charts/ # Helm chart (charts/mainloop)
├── k8s/ # kagent integration example (integrations/kagent)
├── images/ # Workspace cache, toolbox and workspace environment images
├── examples/ # A sample workspace fixture (app, Postgres service, preview port)
├── docs/ # Specs, architecture and operations notes
└── scripts/ # Development and CI helpers
- Desktop: an activity bar of icons (main chat, Inbox, Board, the sidebar, search, orchestration health, Settings), a sidebar with the main thread pinned above the agents grouped by project, the page under a tab strip with one tab per agent of the current project, and a status bar with the connection and the Needs-you, working and problem counts.
- Mobile: one agent full screen, with the same tabs on top and a bottom bar (Chat / Inbox / Board / Agents / Search).
Chat is the main thread. Work starts there: there is no create button for tasks, agents or workspaces. A turn's tool calls fold into one line, and an agent's row opens its own conversation.
Inbox holds Needs you (questions, plan reviews and approvals, answered in place) and Activity. Every badge in the app shows the same Needs-you count.
Board shows every task as a card in one of four columns (Needs you, Working, Waiting, Done), read from the task's own state, with filters by project and a lane per project (board).
The command palette (⌘K, or Ctrl+K off a Mac) jumps to any task, session, workspace, project, schedule or page. Layout has the detail.
Specs (docs/specs/) are the source of truth for behavior. Each one states what is implemented, what is proven live and what is proposed. Status links the main ones; others worth knowing:
- Layout - Desktop and mobile shells, keys and the command palette
- Board - Every task in a column: Needs you, Working, Waiting, Done
- Authentication and credentials - Who may call the owner API, and what an agent holds
- Live updates and seen state - How the app stays current
- Task handoff and provider profiles - Moving work between Claude and Codex
- GitHub reads and issue and pull request comments - The GitHub tools beyond pull requests
- Web fetch, canary and orchestration health
- Ops agent, home tools and personal tools - Tool servers a deployment can bind to the main thread; they are deployment configuration, and the last two are proposed
- Approval gates - Proposed: tools behind an approval card are reached only through Mainloop, which forwards exactly approved calls with a bearer no Session holds
Guides:
- Roadmap - Proposed product and architecture direction
- Architecture - Workspaces, delivery, previews, and agent tools
- Agents and permissions - kagent Agents, sandboxes, approvals, delegation and delivery to prod
- Development environment - Make targets and the shared live dev instance
- Production rollout - The chart, site contract and GitOps boundary
- Production proofs - How each built-but-unproven capability is proven on production
- GitHub automation - CI and image workflows
- iOS app - Building the iPhone app
- Performance - Open performance items for the current stack
- Contributing - Local setup, development commands, and contribution guidance
This project is licensed under the Sustainable Use License v1.0 - a source-available license that allows free use for internal business, non-commercial, and personal purposes.