Skip to main content
Glama

goal-engine

Run-until-done /goal loops for every major agentic CLI — Claude Code, Codex CLI, OpenCode, Cursor, and any MCP-compatible agent.

You state a completion condition ("all tests pass", "the PR is ready"); the agent keeps working across turns until an external evaluator confirms the condition is verifiably met — or until a loop guard or turn budget stops a runaway session.

Architecture: three composable layers

┌─────────────────────────────────────────────────────────┐
│  Layer 3 — npm package + installer CLI                  │
│  npx -y goal-engine · goal-engine install --all         │
├─────────────────────────────────────────────────────────┤
│  Layer 2 — MCP server (goal-engine)                     │
│  set_goal / check_goal / get_status / clear_goal        │
│  Evaluator via MCP sampling (no external API key)       │
│  SQLite state · loop guard · turn budget                │
├─────────────────────────────────────────────────────────┤
│  Layer 1 — portable SKILL.md                            │
│  Works standalone on any Agent Skills runtime           │
└─────────────────────────────────────────────────────────┘

Each layer works on its own. The skill alone gives you self-checked goal loops anywhere; adding the MCP server upgrades the self-check to an independent evaluator with persistent state.

Related MCP server: agent-runtime-mcp

Why an external evaluator?

A skill-only goal loop asks the model to grade its own work inside the same context window — a confused agent can convince itself the goal is met. The MCP spec's sampling primitive lets this server request a completion from the connected client's own model in a fresh context, with a strict evaluation prompt. No API key, no extra provider, CLI-agnostic.

Evaluator fallback chain (strongest available wins):

  1. MCP sampling — the client's model judges the transcript (zero config)

  2. Anthropic API — set ANTHROPIC_API_KEY (model: claude-opus-4-8, override with GOAL_ENGINE_EVAL_MODEL)

  3. OpenAI API — set OPENAI_API_KEY (model: gpt-4o, override with GOAL_ENGINE_OPENAI_MODEL)

  4. Self-check — the tool returns strict self-verification instructions and never auto-completes

A flaky evaluator can never end a goal early: every evaluator failure resolves to done: false.

Install

# Install the /goal skill into every detected agent CLI
npx -y goal-engine install --all

# Or a specific one
npx -y goal-engine install --to claude-code   # also: codex, opencode, cursor

Then connect the MCP server:

Claude Code

claude mcp add goal-engine -- npx -y goal-engine

Codex CLI (~/.codex/config.toml)

[mcp_servers.goal-engine]
command = "npx"
args = ["-y", "goal-engine"]

OpenCode (~/.config/opencode/config.json)

{ "mcp": { "goal-engine": { "type": "local", "command": ["npx", "-y", "goal-engine"] } } }

Bun users can substitute bunx goal-engine everywhere — the server auto-selects bun:sqlite, node:sqlite, or a JSON file for state.

Usage

/goal all unit tests pass and lint is clean

The agent then:

  1. calls set_goal with the condition verbatim,

  2. works toward it with all available tools,

  3. calls check_goal at the end of every turn with a concrete work summary,

  4. treats each done: false reason as its next instruction,

  5. stops only on done: true (or escalates on loop_detected / budget_exhausted).

MCP tools

Tool

Input

Output

set_goal

goal, session_id?, max_turns? (default 40)

session_id, goal, max_turns, created_at

check_goal

session_id, summary

done, reason?, evaluator, turns_used, max_turns

get_status

session_id? (defaults to latest active)

goal, status, turns_used, elapsed_ms, last_check

clear_goal

session_id, completed?

cleared, final_status

Safety rails built into check_goal:

  • Loop guard — 3 identical consecutive summaries return loop_detected and tell the agent to change approach or ask the user.

  • Turn budgetmax_turns (default 40, max 500) returns budget_exhausted with a partial-progress instruction.

  • Strict parsing — unparseable evaluator verdicts resolve to done: false.

Optional: Claude Code Stop hook

The MCP-tool flow relies on the agent calling check_goal. The Stop hook closes the gap: it fires whenever Claude tries to stop, and blocks the stop while a goal is active and unmet.

mkdir -p ~/.goal-engine
cp hooks/stop-goal-evaluator.sh ~/.goal-engine/
chmod +x ~/.goal-engine/stop-goal-evaluator.sh

~/.claude/settings.json:

{
  "hooks": {
    "Stop": [{ "hooks": [{ "type": "command", "command": "~/.goal-engine/stop-goal-evaluator.sh" }] }]
  }
}

Notes:

  • The hook honors stop_hook_active (no infinite recursion) and lets the agent stop once the turn budget is exhausted.

  • Claude Code caps consecutive Stop-hook blocks at 8 by default; set CLAUDE_CODE_STOP_HOOK_BLOCK_CAP=40 to match the default turn budget.

  • With ANTHROPIC_API_KEY set, the hook evaluates the transcript's last assistant message; without it, the block reason instructs the agent to self-verify and finish via clear_goal completed=true.

Environment

Variable

Default

Purpose

GOAL_ENGINE_DB

~/.goal-engine/goal-engine.sqlite

State file path

GOAL_ENGINE_HOME

~/.goal-engine

Data directory

ANTHROPIC_API_KEY

Evaluator fallback when MCP sampling is unavailable

GOAL_ENGINE_EVAL_MODEL

claude-opus-4-8

Anthropic evaluator model

OPENAI_API_KEY

Second evaluator fallback

GOAL_ENGINE_OPENAI_MODEL

gpt-4o

OpenAI evaluator model

Development

bun install
bun run typecheck   # tsc --noEmit
bun test            # unit + MCP integration tests (in-memory transport)
bun run build       # tsc → dist/
bun run smoke       # drives dist/index.js over stdio with raw JSON-RPC

Project layout:

SKILL.md                     Layer 1 — portable Agent Skill
src/index.ts                 CLI entry: serve (default) | install | check-hook
src/server.ts                MCP server: the four goal tools + sampling wiring
src/evaluator.ts             Evaluator chain: sampling → Anthropic → OpenAI → self-check
src/db.ts                    State: bun:sqlite | node:sqlite | JSON fallback
src/loop-guard.ts            Identical-turn loop detection
src/hook.ts                  Claude Code Stop hook logic
src/installer.ts             Cross-CLI skill installer
hooks/stop-goal-evaluator.sh Stop hook wrapper script
agents/openai.yaml           Codex plugin metadata

License

MIT

Available Tools

4 tools
check_goalCheck goalA

Evaluate whether the active goal is fully met. Call at the end of every turn with a concrete summary of the work just done. Returns done=true when finished, or done=false plus the specific gap to address next.

ParametersJSON Schema
NameRequiredDescriptionDefault
session_idYesSession identifier returned by set_goal.
summaryYesConcrete summary of this turn's work: commands run, files changed, test results.

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, description carries burden. It discloses return format (done=true or done=false plus gap) and expected input. Lacks details on side effects or auth, but for a non-destructive evaluation tool this is adequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences: first establishes purpose, second provides usage and return behavior. No wasted words, efficient and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite no output schema, description fully explains return values and when to call. Parameter explanations in schema complement description. Complete for this tool's needs.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema covers both parameters with descriptions (session_id and summary). The description reinforces usage ('concrete summary') but adds little beyond schema. Baseline 3 for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states 'Evaluate whether the active goal is fully met' with a specific verb and resource. Distinguishes from siblings (clear_goal, get_status, set_goal) by its unique evaluation purpose.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly advises 'Call at the end of every turn' and specifies what to include in summary. Does not explicitly mention alternatives, but context with siblings implies it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

clear_goalClear goalA

End a goal session. Pass completed=true when the goal was verifiably met (used by the self-check fallback); otherwise the session is abandoned.

ParametersJSON Schema
NameRequiredDescriptionDefault
session_idYesSession identifier returned by set_goal.
completedNoTrue when the goal condition was verifiably met.

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the tool ends the session, distinguishes between completed and abandoned states, and mentions 'self-check fallback' as context. Adequate for a simple termination action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, zero wasted words. Information is front-loaded with the primary action then parameter usage. Perfectly concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema exists, and the description does not mention what the tool returns (e.g., success indication, error cases). For a simple 'end session' tool, this is a minor gap; some agents may need to know if the action succeeded. Otherwise, the description covers the essentials for invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3. The description adds value beyond the schema by explaining the 'self-check fallback' context for completed=true and explicitly stating that omitting or passing false means abandoned. This enhances understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states 'End a goal session' as verb+resource. Distinct from sibling tools (check_goal, get_status, set_goal) which are about checking, retrieving, or starting goals. The description also specifies the two usage modes via the completed parameter.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides clear guidance on when to use completed=true (when goal verifiably met) vs other cases (abandoned). Does not explicitly contrast with sibling tools, but the distinction between ending vs checking/getting is implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_statusGet goal statusA

Inspect the current goal session: condition, turn count, elapsed time, and last evaluation.

ParametersJSON Schema
NameRequiredDescriptionDefault
session_idNoSession to inspect. Defaults to the most recent active session.

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden for behavioral disclosure. The verb 'inspect' suggests a read-only operation, and listing specific fields provides transparency about what is returned. However, it does not explicitly state that it has no side effects or require permissions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that front-loads the purpose and lists key details without unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, the description adequately informs the agent of the return fields (condition, turn count, elapsed time, last evaluation). The single optional parameter is clearly explained, making the tool usage unambiguous.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100% for session_id, and the description adds context that it defaults to the most recent active session, which goes beyond the schema alone.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'inspect' and the resource 'current goal session', listing specific fields such as condition, turn count, elapsed time, and last evaluation. It is specific enough to distinguish from sibling tools like check_goal, clear_goal, and set_goal.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for inspection of session status but does not provide explicit guidance on when to use this tool versus alternatives, nor does it mention when not to use it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

set_goalSet goalA

Start a run-until-done goal loop. Records the completion condition; the agent should then work toward it and call check_goal at the end of every turn until the goal is met.

ParametersJSON Schema
NameRequiredDescriptionDefault
goalYesThe completion condition, stated verbatim (max 4000 characters).
session_idNoOptional session identifier. Generated when omitted; reuse it on every check_goal call.
max_turnsNoHard turn budget before the loop stops and reports partial progress.

TDQS

A3.6/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must fully disclose behavioral traits. It states the tool 'records the completion condition' and starts a loop, but does not explain what happens if set_goal is called again while a goal is active (overwrite? error?), nor does it cover side effects or required permissions. The description is too brief on behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description consists of two succinct sentences. The first states the purpose, and the second provides a usage instruction. No redundant or extraneous information. Highly efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the presence of three parameters and no output schema or annotations, the description covers the core usage pattern but lacks details on edge cases (e.g., re-calling set_goal, what happens on max_turns reached, error handling). It is minimally adequate but not fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, but the description adds meaningful context beyond the schema: for session_id, it explains it's generated when omitted and should be reused; for max_turns, it clarifies it is a hard turn budget. This additional detail justifies a score above the baseline of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool starts a 'run-until-done goal loop' and records a completion condition. It mentions the follow-up tool check_goal, distinguishing set_goal as the starter. However, it does not explicitly contrast with clear_goal or get_status.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description specifies when to use the tool (to start a goal loop) and instructs the agent to work toward the goal and call check_goal each turn. It lacks explicit guidance on when not to use it (e.g., if a goal is already active) or other alternatives, but the provided instruction is clear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 4 tool updatesv0.1.0
    • First observedcheck_goal
    • First observedclear_goal
    • First observedget_status
    • First observedset_goal

TDQS

A4.2/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a distinct purpose: set_goal starts, check_goal evaluates, clear_goal ends, and get_status inspects. No overlap or confusion.

Naming Consistency5/5

All tools follow a consistent verb_noun pattern with underscores (set_goal, check_goal, clear_goal, get_status), making them predictable.

Tool Count5/5

Four tools are exactly right for a goal engine's core lifecycle: start, evaluate, end, and inspect. No unnecessary extras or missing essentials.

Completeness5/5

The set covers the full lifecycle of a goal session: set, check, clear (with success/failure), and status. No obvious gaps for the intended functionality.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers