Skip to content

How it works

MCP server as state backend

Exarchos ships as a single binary with an mcp subcommand. Claude Code spawns it as a stdio MCP server. No network listeners, no database, no external dependencies.

Four composite tools cover the entire API surface:

ToolPurpose
exarchos_workflowWorkflow lifecycle: init, get, set, cancel, cleanup, reconcile
exarchos_eventAppend-only event store: append, query, batch
exarchos_orchestrateTeam coordination: task dispatch, review triage, script execution, runbooks
exarchos_viewCQRS projections: pipeline status, task boards, convergence, stack health

Every tool input is a Zod-validated discriminated union keyed on action. The same dispatch function backs both the MCP transport and the CLI, so exarchos workflow get --featureId my-feature from a terminal returns the same result the agent gets through MCP.

Event-sourced append-only log

Every action produces events stored in JSONL files on the local filesystem. State is a projection of events, not a mutable record.

When you call exarchos_workflow({ action: "get", featureId: "my-feature" }), the server replays events and returns the computed current state. CQRS view projections (pipeline, tasks, convergence) work the same way: fold events into a view, return the result.

If the state file gets corrupted or deleted, reconcile rebuilds it by replaying the event log. The events are the source of truth. Everything else is derived.

State machine enforcing phase transitions

The workflow state machine defines valid transitions for each workflow type. Feature workflows can move from ideate to plan, but not from ideate to review. Debug workflows branch into hotfix and thorough tracks. Refactor workflows branch into polish and overhaul tracks. Oneshot workflows (v2.6.0+) have a four-phase lightweight lifecycle with a choice state at the end of implementing that forks to either completed (direct-commit) or synthesize → completed (PR), evaluated against a pure event-sourced guard at finalize time.

Guards check preconditions before each transition: does a plan document exist? Have all tasks completed? Did convergence gates pass? If a guard fails, the transition is rejected with a message explaining what's missing.

text
ideate → plan → plan-review → delegate → review → synthesize → completed

The agent can query valid transitions for any state with exarchos_workflow({ action: "transitions" }) and get back the phases it can move to.

Lazy schema registration

At startup, each tool registers with a slim description and an enum of available actions. Total cost: under 500 tokens across all four tools. No parameter schemas are loaded yet.

When the agent needs to call a specific action, it calls describe to get the full parameter schema on demand. A typical session uses 5-6 actions out of the 30+ available. Lazy loading avoids spending tokens on the rest.

Field projection

State queries accept an optional fields parameter that specifies which parts of the state to return. Instead of fetching the full workflow state object (which can run to several hundred tokens), the agent requests just the fields it needs.

json
{
  "action": "get",
  "featureId": "my-feature",
  "fields": ["phase", "tasks"]
}

This reduces token consumption by roughly 90% for common queries like "what phase am I in?" or "which tasks are still pending?"

Lifecycle hooks

Eight hooks automate verification at specific moments in the session lifecycle:

HookTriggerWhat it does
PreCompactBefore context compactionCheckpoints the active workflow so it can be rehydrated
SessionStartSession start or resumeDetects active workflows and restores context
PreToolUseBefore any Exarchos MCP callGuards invalid operations based on phase and role
TaskCompletedAfter a task finishesRuns convergence gates against the completed work
TeammateIdleWhen a subagent goes idleVerifies teammate work quality
SubagentStartWhen a subagent startsInjects workflow context into the subagent
SubagentStopWhen an implementer or fixer stopsProcesses subagent completion results
SessionEndSession endsPersists final state

Hooks run as fast-path CLI subcommands that skip heavy initialization. The PreCompact hook snapshots state in under 30 seconds. The PreToolUse guard runs in under 5 seconds.

Without hooks, the agent could skip quality gates by not calling them. With hooks, verification runs automatically whether the agent remembers or not.

Released under the Apache-2.0 License.