Latest reference

Hitch Documentation

Hitch is the universal event and observability layer for Codex, Claude Code, Hermes, Pi, OMP, OpenCode, and Antigravity. It gives developers and teams one portable handler protocol for guardrails, audit logs, policy checks, context injection, result transformation, centralized lifecycle routing, and agent activity inspection.

Quickstart

Install from latest source, start the local server, check health, then preview and install supported hooks.

curl -fsSL https://raw.githubusercontent.com/sagebynature/hitch/main/scripts/install.sh | sh
hitch serve --config ~/.config/hitch/config.toml
hitch status --json
hitch doctor --json
hitch-client install --only codex --dry-run --json
hitch-client install --only claudecode --dry-run --json
hitch-client install --only opencode --yes --json

The default server listens on 127.0.0.1:8799 and stores SQLite audit and observability records at ~/.local/share/hitch/events.sqlite. SQLite is the current verified backend; additional storage and observability backends are planned.

Installation

The source installer checks for git and go, builds ./cmd/hitch and ./cmd/hitch-client, installs both binaries into $HITCH_INSTALL_DIR or ~/.local/bin, verifies hitch --version and hitch-client --version, seeds ~/.config/hitch/config.toml with hitch config init, prompts for a Hitch server URL through /dev/tty even when installed with curl ... | sh, and offers hook setup when a terminal is available.

Build locally

make build
./bin/hitch --version
./bin/hitch-client --version
./bin/hitch serve --config internal/config/default.config.toml

Container image

docker build -t hitch .
docker run --rm -p 8799:8799 hitch
make docker-run
HITCH_CONFIG_DIR="$PWD/.hitch-docker" make docker-run
docker run --rm -p 8799:8799 \
  -v "$HOME/.config/hitch:/var/lib/hitch/.config/hitch" \
  hitch

The image listens on 0.0.0.0:8799 and uses the same logical Hitch config root as local runs: ~/.config/hitch. make docker-run creates ~/.config/hitch/config.toml, extensions/, and backups/ when missing, then mounts that directory at /var/lib/hitch/.config/hitch in the container. Override HITCH_CONFIG_DIR when you want a different host source. The runtime image includes Node.js for JavaScript/TypeScript extension adapters, and Compose sets HITCH_FACE_URL=http://host.docker.internal:8888/event so containerized handlers can call desktop services on the host.

Hook install commands

hitch-client install --dry-run --json
hitch-client install --all --dry-run --json
hitch-client install --only codex --yes --json
hitch-client install --only claudecode --yes --json
hitch-client install --only hermes --yes --json
hitch-client install --only hermes --url http://127.0.0.1:8797 --yes --json
hitch-client install --only pi --yes --json
hitch-client install --only pi --url http://127.0.0.1:8797 --yes --json
hitch-client install --only omp --yes --json
hitch-client install --only omp --url http://127.0.0.1:8797 --yes --json
hitch-client install --only opencode --yes --json
hitch-client install --only opencode --url http://127.0.0.1:8797 --yes --json
hitch-client uninstall --only codex --yes --json
hitch-client uninstall --only claudecode --yes --json
hitch-client uninstall --only hermes --yes --json
hitch-client uninstall --only pi --yes --json
hitch-client uninstall --only omp --yes --json
hitch-client uninstall --only opencode --yes --json

The source installer seeds ~/.config/hitch/config.toml when missing, adds missing managed default sections to existing valid config, prompts for a Hitch server URL through /dev/tty, and can persist HITCH_URL for remote servers. hitch-client install installs managed Codex, Claude Code, Hermes, Pi, OMP, OpenCode, and Antigravity adapters. Generated command hooks omit -url by default and resolve the Hitch API URL at runtime. Generated Pi and OMP extensions post observer callbacks with mode:"async" and return-capable control callbacks with mode:"sync" to /v1/events, promote adapter metadata into Hitch envelope fields, and fail open if Hitch is unavailable.

Configuration

Hitch reads user configuration from ~/.config/hitch/config.toml by default. Repository checkout examples pass --config internal/config/default.config.toml explicitly when they should use the development config.

hitch config init
SectionPurpose
[server]Local API bind address and request size limit.
[log]Operational logging. Native payloads are not included by default.
[audit]Event journal and observability persistence. SQLite is the verified backend today; additional backends are planned.
[handlers.<name>]External command handlers, event filters, mode, timeout, and error policy.
[harness.<name>]Per-harness enable flags and source-event mappings.

Strict validation rejects unknown config keys and invalid server ports, request sizes, log values, audit backends, handler event names, handler kinds, handler error or timeout policies, and harness event-map values. Optional handler working_dir values run commands from a stable directory; relative values resolve from the config file directory. The default config enables harness event maps and audit storage, but no handlers; add [handlers.<name>] entries explicitly before Hitch executes subprocesses.

Handler protocol

A handler is any executable command configured in Hitch. Hitch writes one normalized event envelope JSON object to handler stdin. The handler may write one JSON result object to stdout.

{
  "status": "ok",
  "decision": {
    "behavior": "none"
  }
}
  • Allowed statuses: ok, error, timeout.
  • Allowed decisions: none, allow, deny, block, continue, stop, transform, replace_result, inject_context, handled.
  • If decision is omitted, Hitch treats it as {"behavior":"none"}.
  • Hitch sets HITCH_CHILD=1 on child handler processes for recursion guards.

Verified behavior includes stdout JSON parsing, invalid stdout persistence as error, timeout persistence as timeout, separate stderr capture, decision precedence by lexicographic handler-name order, ordered context injection concatenation, and rejection of multiple transforms unless transform chaining is explicitly configured.

Handler development

Build handlers as small commands that read the Hitch envelope from stdin and write one handler result to stdout. Send logs to stderr so stdout remains valid JSON.

Step-by-step

  1. Choose async observer mode for passive work, or sync control mode when the harness needs a decision.
  2. Pick normalized event names such as tool.requested, llm.requested, turn.user_prompt, or tool.completed. Use the Hitch event mapping below to connect source harness events to normalized names.
  3. Add a [handlers.<name>] config entry with command, events, mode, timeout_ms, and fail-open or fail-closed policy.
  4. Read hitch_event_type first. Inspect harness and source_event_type only when a harness-specific field is needed.
  5. Return a decision behavior: none, allow, deny, block, continue, stop, transform, replace_result, inject_context, or handled.
  6. Test policy decisions with python3 examples/test_drive.py, or test payload logging across all harnesses with python3 examples/test_payload_logger.py.
[handlers.example_policy]
command = ["python3", "examples/handlers/policy_handler.py"]
working_dir = "."
events = ["turn.user_prompt", "tool.requested", "tool.completed", "turn.completed"]
kind = "control"
timeout_ms = 1000
on_error = "fail_closed"
on_timeout = "fail_closed"

turn.assistant_completed is the consistent assistant-output-complete audit signal. Hitch stores it for Codex and Claude Code Stop, Hermes transform_llm_output, Pi/OMP turn_end, and OpenCode final-answer message.part.updated text parts that the managed plugin forwards as message.part.text. Secondary audit rows are not used for sync native-response translation or live handler dispatch.

Payload logger for every harness

examples/handlers/payload_logger.py appends each event payload to a JSONL log and returns behavior:"none". Configure one sync handler and one async handler with events = ["*"] to observe Codex, Claude Code, Hermes, Pi, OMP, OpenCode, and Antigravity without changing control flow.

Async handlers also run after a sync dispatch for the same normalized event, so passive observers can subscribe with kind = "observer" without affecting the harness-native sync response.

[handlers.payload_logger_sync]
command = ["python3", "examples/handlers/payload_logger.py", "--log", "tmp/hitch-payload-logger/payloads.jsonl"]
working_dir = ".."
events = ["*"]
kind = "control"
timeout_ms = 1000
on_error = "fail_open"
on_timeout = "fail_open"

[handlers.payload_logger_async]
command = ["python3", "examples/handlers/payload_logger.py", "--log", "tmp/hitch-payload-logger/payloads.jsonl"]
working_dir = ".."
events = ["*"]
kind = "observer"
timeout_ms = 1000
on_error = "fail_open"
on_timeout = "fail_open"

Run python3 examples/test_payload_logger.py from the repository root. The script starts Hitch on 127.0.0.1:8797, sends events through the example-configured harness mappers, sends one async observer event, and verifies tmp/hitch-payload-logger/payloads.jsonl. If port 8797 is already in use, run with HITCH_PAYLOAD_LOGGER_PORT=8796 python3 examples/test_payload_logger.py. If you install real Hermes hooks against this example server, use hitch-client install --only hermes --url http://127.0.0.1:8797 --yes --json. Handler config changes affect hitch serve; the hook shim only reads stdin, resolves the API URL, and dispatches to the local Hitch API.

Matching handlers run in lexicographic handler-name order. Higher-precedence decisions win; blocking decisions outrank transforms, context injection, and allow decisions. Multiple context injections concatenate, but multiple transform or replace-result decisions are rejected.

Hitch events

Hitch normalizes Codex, Claude Code, Hermes, Pi, OMP, OpenCode, and Antigravity source events into one stable event envelope while retaining source_payload as the harness escape hatch. The handler-facing payload is keyed by hitch_event_type; common roots include tool, turn, and llm, with llm.completed carrying token and cost metrics when a harness source exposes them.

Per-harness [harness.<name>.event_map] config entries are the source of truth for source-event to Hitch-event mapping. Values may be a single Hitch event or an ordered list. The first event is primary for sync dispatch/native responses; additional events are secondary audit rows. The default config intentionally omits duplicate or high-volume observer events; the catalog below marks those as opt-in so operators can add them when needed.

Normalized event types

Hitch eventMeaning
session.startedA harness session or top-level agent lifecycle starts.
session.resumedA switch, fork, or resume-like session transition is about to occur.
session.endedA session or agent lifecycle ends.
session.compactedContext compaction starts, completes, or is about to run.
turn.startedA model or agent turn begins.
turn.user_promptUser input or gateway dispatch is submitted.
turn.assistant_startedAssistant output starts; retained for compatibility with earlier configs.
turn.assistant_completedAssistant output is available. Hitch may persist this as a secondary audit row in addition to the primary source-event mapping.
turn.completedA model or agent turn completes. This is distinct from assistant-output completion when a harness exposes both boundaries.
llm.requestedA provider/LLM request is about to be sent. High-volume provider payloads are opt-in for Pi/OMP/OpenCode defaults.
llm.completedA provider/LLM response or transformed model output is available.
tool.requestedA tool command, shell command, or tool call is requested before execution.
tool.permission_requestedA harness-specific permission decision is requested.
tool.completedA final tool result, terminal output, or transformed tool result is available.
tool.progressIncremental tool output is available before final completion.
retry.startedA harness retry cycle starts.
retry.completedA harness retry cycle completes.
subagent.startedA subagent starts.
subagent.completedA subagent completes or stops.
error.reportedA normalized harness error or credential failure is reported.

Secondary normalized events

Most source events produce one primary normalized event from [harness.<name>.event_map]. When a source event maps to an ordered list, Hitch also persists secondary audit rows for the remaining configured events. Defaults use this for Codex and Claude Code Stop, Claude Code failure events, Hermes pre_llm_call, Hermes transform_llm_output, and Pi/OMP turn_end. Secondary rows are parsed for their target Hitch event type, share the same inbound event, and are for audit/query consistency; they are not dispatched to live handlers or used for sync native-response translation.

Codex event mapping

Native eventHitch eventTranslated response
SessionStartsession.startedinject_context adds additionalContext; block or deny returns decision:"block".
SubagentStartsubagent.startedinject_context adds additionalContext; block or deny returns decision:"block".
UserPromptSubmitturn.user_promptinject_context adds additionalContext; block or deny returns decision:"block".
PreToolUsetool.requesteddeny, block, or stop returns permissionDecision:"deny"; allow or transform returns permissionDecision:"allow", with optional updatedInput.
PermissionRequesttool.permission_requesteddeny, block, or stop returns hookSpecificOutput.decision.behavior:"deny"; allow returns "allow".
PostToolUsetool.completedinject_context adds additionalContext; block or deny returns decision:"block".
PreCompactsession.compactedstop or block returns decision:"stop".
PostCompactsession.compactedstop or block returns decision:"stop".
SubagentStopsubagent.completedcontinue returns continue:true.
Stopturn.completed, turn.assistant_completedPrimary turn.completed handles stop or block as decision:"stop"; secondary turn.assistant_completed is audit-only.

Claude Code event mapping

Claude Code command hooks use hitch-client -harness claudecode and the same handler-result contract as other command-hook harnesses. Default mappings cover session, prompt, tool, permission, stop, subagent, compaction, and failure events; reactive/product telemetry is opt-in.

Hermes event mapping

Native eventHitch eventTranslated response
pre_tool_calltool.requested (default)block, deny, or stop returns action:"block" and message.
post_tool_calltool.completed (opt-in)Observer-only duplicate of transform_tool_result in observed runs; no special translation.
pre_llm_callllm.requested, turn.user_prompt (default)Primary llm.requested handles inject_context as context; secondary turn.user_prompt is audit-only.
post_llm_callllm.completed (opt-in)Observer-only and potentially large; no special translation.
on_session_startsession.started (default)No special translation.
on_session_endsession.ended (default)No special translation.
subagent_stopsubagent.completed (default)No special translation.
transform_tool_resulttool.completed (default)replace_result or transform returns result from updated_output.
transform_terminal_outputtool.completed (default)replace_result or transform returns result from updated_output.
transform_llm_outputllm.completed, turn.assistant_completed (default)Primary llm.completed handles replace_result or transform; secondary turn.assistant_completed is audit-only.
pre_gateway_dispatchturn.user_prompt (default)handled returns action:"skip"; transform returns action:"rewrite"; allow returns action:"allow".

Pi event mapping

Pi uses adapter_action responses: noop, return, or mutate_and_return.

Native eventHitch eventAdapter response
inputturn.user_prompt (default)transform returns a transformed input action; handled returns handled; continue or allow returns continue.
before_agent_startturn.started (opt-in)Large prompt/system-prompt snapshot; no special default translation.
agent_startturn.started (opt-in)Observer-only lifecycle marker.
turn_startturn.started (default)noop.
contextturn.started (opt-in)Large context snapshot; transform returns updated_input.
before_provider_requestllm.requested (opt-in)Large provider request snapshot; transform returns updated_input.
tool_calltool.requested (default)block, deny, or stop returns a block object; transform mutates source path input.
tool_resulttool.completed (default)replace_result or transform returns updated_output.
turn_endturn.completed, turn.assistant_completed, llm.completed (default)Extracts final assistant text and usage/cost when present; secondary completion rows are audit-only.
agent_endturn.completed (opt-in)Large final message snapshot.
session_startsession.started (default)noop.
session_shutdownsession.ended (default)noop.
session_before_switch, session_before_forksession.resumed (default)block or stop returns {cancel:true}.
session_before_compact, session_compactsession.compacted (default)session_before_compact can return {cancel:true}; session_compact is noop.
user_bashtool.requested (default)noop.

OMP event mapping

OMP reuses the Pi adapter response contract for translated native responses.

Native eventHitch eventAdapter response
inputturn.user_prompt (default)Same translation as Pi input.
before_agent_startturn.started (opt-in)Large prompt/system-prompt snapshot.
agent_startturn.started (opt-in)Observer-only lifecycle marker.
agent_endturn.completed (opt-in)Large final message snapshot.
turn_startturn.started (default)noop.
turn_endturn.completed, turn.assistant_completed, llm.completed (default)Extracts final assistant text and usage/cost when present; secondary completion rows are audit-only.
contextturn.started (opt-in)Large context snapshot; transform returns updated_input.
before_provider_requestllm.requested (opt-in)Large provider request snapshot; transform returns updated_input.
after_provider_responsellm.completed (opt-in)Provider response observer.
message_start, message_updateturn.assistant_started (opt-in)Assistant-message start/update events; message_update is high-volume.
message_endturn.assistant_completed (default)noop.
tool_calltool.requested (default)Uses Pi block/transform translation.
tool_execution_starttool.requested (opt-in)Observer-only execution start.
tool_resulttool.completed (default)Uses Pi result replacement translation.
tool_execution_updatetool.progress (opt-in)Incremental tool output.
tool_execution_endtool.completed (opt-in)Observer-only duplicate of tool_result in observed runs.
session_startsession.started (default)noop.
session_before_switch, session_switch, session_before_branch, session_branch, session_before_tree, session_treesession.resumed (default)Cancelable pre-events return {cancel:true} for block or stop.
session_before_compact, session.compacting, session_compact, auto_compaction_start, auto_compaction_endsession.compacted (default)session_before_compact can return {cancel:true}; compaction customization uses native_response.
session_shutdownsession.ended (default)noop.
auto_retry_startretry.started (opt-in)Retry lifecycle marker.
auto_retry_endretry.completed (opt-in)Retry lifecycle marker.
ttsr_triggered, todo_reminder, goal_updatedturn.started (opt-in)Product-specific observer events.
credential_disablederror.reported (default)noop.
user_bash, user_pythontool.requested (default)Observational unless native_response is supplied.

For every harness, decision.native_response bypasses Hitch's translator and returns harness-native JSON unchanged. See the markdown event reference for the complete envelope table and response details.

Local HTTP API

Hitch exposes a local API for health checks, event ingestion, synchronous dispatch, event inspection, and replay-driven workflows.

EndpointUse
GET /v1/healthReturn server health status.
POST /v1/eventsIngest async observer events.
GET /v1/events/<id>Inspect stored inbound, normalized, handler, and native response records.
curl -sS -X POST http://127.0.0.1:8799/v1/events \
  -H 'content-type: application/json' \
  -d '{
    "harness": "codex",
    "source_event_type": "PreToolUse",
    "source_payload": {
      "hook_event_name": "PreToolUse",
      "tool_name": "Bash",
      "tool_input": {"command": "pwd"}
    },
    "hitch_client_version": "manual-curl"
  }'

Harness contracts

Hitch supports two dispatch modes: all events use POST /v1/events; request mode selects async observer ingestion or sync control dispatch.

HarnessCurrent contract
CodexMaps native command hook payloads and translates decisions to Codex stdout JSON. The verified path covers every supported Codex lifecycle event and PreToolUse deny translation.
Claude CodeMaps native command hook payloads and translates decisions to Claude Code stdout JSON through ~/.claude/settings.json command hooks. Coverage includes supported lifecycle events, permission decisions, result replacement, and stop/failure secondary audit rows.
HermesMaps shell hook payloads and translates decisions to Hermes stdout JSON. The verified pre_tool_call block response is {"action":"block","message":"..."}.
Pi / OMPMaps extension callback events in Go and installs managed TypeScript extensions that post observer callbacks plus extension ctx metadata to /v1/events, post return-capable control callbacks to /v1/events, apply adapter-response return values or mutations only for sync responses, and fail open when Hitch is unavailable.
OpenCodeInstalls a managed TypeScript plugin, posts typed control hooks and selected SDK events to /v1/events, and translates normalized decisions into plugin-owned adapter actions.
AntigravityInstalls managed hooks into ~/.gemini/config/hooks.json and translates normalized decisions to Antigravity stdout JSON.

Async adapter calls print nothing and ignore Hitch network failure. Sync adapter calls emit a harness-native no-op response when Hitch is unreachable or returns no native response.

Replay and inspect

Use inspect-event to inspect the persisted audit view for a normalized event. Use replay to re-run configured sync handlers against stored normalized events.

hitch inspect-event --config internal/config/default.config.toml norm_...
hitch replay --config internal/config/default.config.toml --dry-run norm_...
hitch replay --config internal/config/default.config.toml norm_...

Dry-run replay returns the stored event envelope without writing records. Replay without --dry-run persists new handler invocation records linked by replay_source_id to the source normalized event id.

Schemas

The repository includes JSON schemas for the normalized envelope and handler-facing responses.

Source references

These source markdown files remain the implementation-level references for contributors.