An orchestrator that governs, visualizes, and makes auditable the development and exploration work of AI agents (such as Claude Code) through external state machines.
state_gate treats agents not as "smart entities that remember processes," but as executors that generate and submit actions and artifacts required by the state machine. This enables:
- Explicit processes and auditability
- Consistency across multiple agents/teams
- Process diversity absorbed through state/transition/guard definitions rather than proliferating skills
- State-Driven: Agent behavior is determined by the state machine
- Evidence Submission Model: Agents submit evidence, not transition commands
- Guard Conditions: Control transitions through artifact requirements, machine verification, approvals, etc.
- Audit Logs: Record all events and decision results
- Optimistic Locking: Ensure consistency in concurrent execution through revision numbers
- Iterative processes including exploration, implementation, evaluation, and review
- Particularly designed for instant prototyping (short loops in exploration phase)
┌─────────────────────────────────────────────────────────────┐
│ Integration Layer │
│ ┌─────────────┐ ┌──────────────┐ ┌────────────────────┐ │
│ │ MCP Server │ │ Hook Adapter │ │ HTTP API / CLI │ │
│ │ (Dialog) │ │ (Execution) │ │ (Integration) │ │
│ └──────┬──────┘ └──────┬───────┘ └─────────┬──────────┘ │
└─────────┼────────────────┼───────────────────┼──────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ State Engine │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Process Definition → Event → Guard Eval → Transition │ │
│ └──────────────────────────────────────────────────────┘ │
└──────────────────────────┬──────────────────────────────────┘
│
┌────────────────┼────────────────┐
▼ ▼ ▼
┌────────────────┐ ┌──────────────┐ ┌──────────────────┐
│ Artifact Store │ │ Audit/Event │ │ Context/Run │
│ (Source) │ │ Log │ │ Management │
└────────────────┘ └──────────────┘ └──────────────────┘
- Architecture
- Core Concepts
- Process DSL Specification
- MCP Interface
- Hook Adapter
- Security
- MVP Requirements
- Examples
- Truth lives in state_gate - Don't rely on agent memory
- state_gate decides transitions - Agents focus on evidence submission
- Process differences are contained in DSL - Don't absorb them through skills proliferation
- Handle conflicts and retries in specification - revision / idempotency / audit
npm install
npm run build
npm linkmkdir -p .state_gate/processes
cp examples/exploration/exploration-process.yaml .state_gate/processes/exploration-process.yamlstate-gate create-run --process-id exploration-process
state-gate get-state --run-id <run_id>
state-gate list-events --run-id <run_id> --include-blocked trueAll CLI output is JSON format.
Define tool execution permissions in tool_permissions for each state (within process definition).
emit-event accumulates artifact_paths and saves them in the latest row.
See examples/exploration/README.md for detailed instructions.
state-gate serve --process=./path/to/process.yamlstate-gate-hook pre-tool-use --tool-name Edit --tool-input '{"path":"README.md"}'stdin input example:
echo '{"tool_name":"Edit","tool_input":{"path":"README.md"}}' | state-gate-hook pre-tool-useError behavior follows fail-open/fail-close settings in docs/hook-adapter.md.
state_gate is distributed as a Claude Code Plugin and can be installed easily.
# Add marketplace
/plugin marketplace add https://github.com/CAPHTECH/state_gate
# Install plugin
/plugin install state-gate/plugin install https://github.com/CAPHTECH/state_gate/tree/main/pluginWhen you install the plugin, the following become automatically available:
- Hooks: PreToolUse, PostToolUse, SessionStart hooks for state management
- PreToolUse Hook: Permission checks before tool execution (based on
tool_permissionsin process definition) - PostToolUse Hook: State display after event emission (automatically inserts new state prompt)
- SessionStart Hook: State display after compaction
The plugin provides hooks only. You need to configure the MCP server in each project's .mcp.json:
{
"mcpServers": {
"state-gate": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@caphtech/state-gate", "serve"],
"env": {
"STATE_GATE_PROJECT_ROOT": "/path/to/your/project"
}
}
}
}Important: Set STATE_GATE_PROJECT_ROOT to your project's absolute path. This ensures the MCP server uses the correct .state_gate/ directory.
The plugin uses npx -y @caphtech/state-gate internally, so you need to publish the npm package first:
npm publishAfter publication, users can use the plugin without any prior installation (npx automatically downloads and caches the package).
Create a Run in your project directory to automatically start state management:
# Create Run (saved in .state_gate/state-gate.json)
state-gate create-run --process-id exploration-process --write-config
# Check state (also available via MCP server)
state-gate get-stateSee examples/exploration/README.md and CLAUDE.md for details.
MIT
Issues and Pull Requests are welcome.