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
| Section | Purpose |
|---|---|
[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
decisionis omitted, Hitch treats it as{"behavior":"none"}. - Hitch sets
HITCH_CHILD=1on 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
- Choose async observer mode for passive work, or sync control mode when the harness needs a decision.
- Pick normalized event names such as
tool.requested,llm.requested,turn.user_prompt, ortool.completed. Use the Hitch event mapping below to connect source harness events to normalized names. - Add a
[handlers.<name>]config entry withcommand,events,mode,timeout_ms, and fail-open or fail-closed policy. - Read
hitch_event_typefirst. Inspectharnessandsource_event_typeonly when a harness-specific field is needed. - Return a decision behavior:
none,allow,deny,block,continue,stop,transform,replace_result,inject_context, orhandled. - Test policy decisions with
python3 examples/test_drive.py, or test payload logging across all harnesses withpython3 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 event | Meaning |
|---|---|
session.started | A harness session or top-level agent lifecycle starts. |
session.resumed | A switch, fork, or resume-like session transition is about to occur. |
session.ended | A session or agent lifecycle ends. |
session.compacted | Context compaction starts, completes, or is about to run. |
turn.started | A model or agent turn begins. |
turn.user_prompt | User input or gateway dispatch is submitted. |
turn.assistant_started | Assistant output starts; retained for compatibility with earlier configs. |
turn.assistant_completed | Assistant output is available. Hitch may persist this as a secondary audit row in addition to the primary source-event mapping. |
turn.completed | A model or agent turn completes. This is distinct from assistant-output completion when a harness exposes both boundaries. |
llm.requested | A provider/LLM request is about to be sent. High-volume provider payloads are opt-in for Pi/OMP/OpenCode defaults. |
llm.completed | A provider/LLM response or transformed model output is available. |
tool.requested | A tool command, shell command, or tool call is requested before execution. |
tool.permission_requested | A harness-specific permission decision is requested. |
tool.completed | A final tool result, terminal output, or transformed tool result is available. |
tool.progress | Incremental tool output is available before final completion. |
retry.started | A harness retry cycle starts. |
retry.completed | A harness retry cycle completes. |
subagent.started | A subagent starts. |
subagent.completed | A subagent completes or stops. |
error.reported | A 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 event | Hitch event | Translated response |
|---|---|---|
SessionStart | session.started | inject_context adds additionalContext; block or deny returns decision:"block". |
SubagentStart | subagent.started | inject_context adds additionalContext; block or deny returns decision:"block". |
UserPromptSubmit | turn.user_prompt | inject_context adds additionalContext; block or deny returns decision:"block". |
PreToolUse | tool.requested | deny, block, or stop returns permissionDecision:"deny"; allow or transform returns permissionDecision:"allow", with optional updatedInput. |
PermissionRequest | tool.permission_requested | deny, block, or stop returns hookSpecificOutput.decision.behavior:"deny"; allow returns "allow". |
PostToolUse | tool.completed | inject_context adds additionalContext; block or deny returns decision:"block". |
PreCompact | session.compacted | stop or block returns decision:"stop". |
PostCompact | session.compacted | stop or block returns decision:"stop". |
SubagentStop | subagent.completed | continue returns continue:true. |
Stop | turn.completed, turn.assistant_completed | Primary 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 event | Hitch event | Translated response |
|---|---|---|
pre_tool_call | tool.requested (default) | block, deny, or stop returns action:"block" and message. |
post_tool_call | tool.completed (opt-in) | Observer-only duplicate of transform_tool_result in observed runs; no special translation. |
pre_llm_call | llm.requested, turn.user_prompt (default) | Primary llm.requested handles inject_context as context; secondary turn.user_prompt is audit-only. |
post_llm_call | llm.completed (opt-in) | Observer-only and potentially large; no special translation. |
on_session_start | session.started (default) | No special translation. |
on_session_end | session.ended (default) | No special translation. |
subagent_stop | subagent.completed (default) | No special translation. |
transform_tool_result | tool.completed (default) | replace_result or transform returns result from updated_output. |
transform_terminal_output | tool.completed (default) | replace_result or transform returns result from updated_output. |
transform_llm_output | llm.completed, turn.assistant_completed (default) | Primary llm.completed handles replace_result or transform; secondary turn.assistant_completed is audit-only. |
pre_gateway_dispatch | turn.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 event | Hitch event | Adapter response |
|---|---|---|
input | turn.user_prompt (default) | transform returns a transformed input action; handled returns handled; continue or allow returns continue. |
before_agent_start | turn.started (opt-in) | Large prompt/system-prompt snapshot; no special default translation. |
agent_start | turn.started (opt-in) | Observer-only lifecycle marker. |
turn_start | turn.started (default) | noop. |
context | turn.started (opt-in) | Large context snapshot; transform returns updated_input. |
before_provider_request | llm.requested (opt-in) | Large provider request snapshot; transform returns updated_input. |
tool_call | tool.requested (default) | block, deny, or stop returns a block object; transform mutates source path input. |
tool_result | tool.completed (default) | replace_result or transform returns updated_output. |
turn_end | turn.completed, turn.assistant_completed, llm.completed (default) | Extracts final assistant text and usage/cost when present; secondary completion rows are audit-only. |
agent_end | turn.completed (opt-in) | Large final message snapshot. |
session_start | session.started (default) | noop. |
session_shutdown | session.ended (default) | noop. |
session_before_switch, session_before_fork | session.resumed (default) | block or stop returns {cancel:true}. |
session_before_compact, session_compact | session.compacted (default) | session_before_compact can return {cancel:true}; session_compact is noop. |
user_bash | tool.requested (default) | noop. |
OMP event mapping
OMP reuses the Pi adapter response contract for translated native responses.
| Native event | Hitch event | Adapter response |
|---|---|---|
input | turn.user_prompt (default) | Same translation as Pi input. |
before_agent_start | turn.started (opt-in) | Large prompt/system-prompt snapshot. |
agent_start | turn.started (opt-in) | Observer-only lifecycle marker. |
agent_end | turn.completed (opt-in) | Large final message snapshot. |
turn_start | turn.started (default) | noop. |
turn_end | turn.completed, turn.assistant_completed, llm.completed (default) | Extracts final assistant text and usage/cost when present; secondary completion rows are audit-only. |
context | turn.started (opt-in) | Large context snapshot; transform returns updated_input. |
before_provider_request | llm.requested (opt-in) | Large provider request snapshot; transform returns updated_input. |
after_provider_response | llm.completed (opt-in) | Provider response observer. |
message_start, message_update | turn.assistant_started (opt-in) | Assistant-message start/update events; message_update is high-volume. |
message_end | turn.assistant_completed (default) | noop. |
tool_call | tool.requested (default) | Uses Pi block/transform translation. |
tool_execution_start | tool.requested (opt-in) | Observer-only execution start. |
tool_result | tool.completed (default) | Uses Pi result replacement translation. |
tool_execution_update | tool.progress (opt-in) | Incremental tool output. |
tool_execution_end | tool.completed (opt-in) | Observer-only duplicate of tool_result in observed runs. |
session_start | session.started (default) | noop. |
session_before_switch, session_switch, session_before_branch, session_branch, session_before_tree, session_tree | session.resumed (default) | Cancelable pre-events return {cancel:true} for block or stop. |
session_before_compact, session.compacting, session_compact, auto_compaction_start, auto_compaction_end | session.compacted (default) | session_before_compact can return {cancel:true}; compaction customization uses native_response. |
session_shutdown | session.ended (default) | noop. |
auto_retry_start | retry.started (opt-in) | Retry lifecycle marker. |
auto_retry_end | retry.completed (opt-in) | Retry lifecycle marker. |
ttsr_triggered, todo_reminder, goal_updated | turn.started (opt-in) | Product-specific observer events. |
credential_disabled | error.reported (default) | noop. |
user_bash, user_python | tool.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.
| Endpoint | Use |
|---|---|
GET /v1/health | Return server health status. |
POST /v1/events | Ingest 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.
| Harness | Current contract |
|---|---|
| Codex | Maps 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 Code | Maps 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. |
| Hermes | Maps shell hook payloads and translates decisions to Hermes stdout JSON. The verified pre_tool_call block response is {"action":"block","message":"..."}. |
| Pi / OMP | Maps 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. |
| OpenCode | Installs a managed TypeScript plugin, posts typed control hooks and selected SDK events to /v1/events, and translates normalized decisions into plugin-owned adapter actions. |
| Antigravity | Installs 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.
Walkthrough
Fresh checkout to working Codex proof of concept.
GuideInstallation
Source install, hook setup, status, doctor, and uninstall behavior.
ReferenceConfiguration
Config sections and strict validation rules.
ReferenceHandler protocol
stdin/stdout contract and result aggregation rules.
GuideBuilding handlers
Step-by-step handler development, event mapping, decisions, examples, inspection, replay, and troubleshooting.
ReferenceHitch events
Normalized event taxonomy and source-event mappings for Codex, Claude Code, Hermes, Pi, OMP, OpenCode, and Antigravity.
ReferenceHarness contracts
Supported dispatch modes and adapter behavior.
ReferenceReplay
Event inspection and replay commands.