clawhip
repository·main·Indexed 21 days ago
https://github.com/yeachan-heo/clawhipA control plane and event-to-channel notification router for Discord and Slack. clawhip intercepts events from sources such as GitHub, tmux, and AI agents (Codex, Claude) to manage automation and approval workflows. It features a routing engine configured via TOML to deliver formatted notifications based on event types and filters, supports tmux session monitoring, and provides a bridge for provider-native hooks to track agent lifecycle events.
What's inside clawhip
- clawhip (also known as gajae-claw) is a control plane for agents. It acts as a routing engine that intercepts events from sources like GitHub, Discord, and tmux, and routes them to the appropriate human or agent. It is designed to record event history and distinguish between actions that can be automated and those that require explicit operator approval.
Understand the Filesystem-Offloaded Memory Architecture
mainClawhip recommends a layered memory pattern for filesystem-backed project memory. Instead of a single monolithic file, memory is split into a high-signal 'hot' layer and multiple detailed 'leaf' layers. This ensures that agents can quickly load the necessary context without being overwhelmed by massive files.
The Three-Layer Model:
- Layer 1:
MEMORY.md(Hot Pointer Layer): A small, high-value index that answers what is currently true, which files matter now, and where to write updates. It contains pointers, not long histories. - Layer 2: Subtree Indexes (Routing Layer): Files located under
memory/(e.g.,memory/projects/README.md) that act as routers, defining naming conventions and which shards are canonical for specific categories. - Layer 3: Leaf Memory Files (Detail Layer): The durable, detailed shards such as daily logs, project memory, channel memory, and topic-specific rules.
- Layer 1:
How the Question-Request Bridge works
mainclawhip normalizes specific tool-use events into a
question.requestedroute key. This occurs whenPreToolUseorPostToolUsepayloads contain atool_namethat matches one of the following identifiers:askask_userask_user_questionAskUserQuestionaskuserquestion
When matched, these are delivered using
session.blockedalert semantics. To ensure safety, clawhip only exposes boundedsummary,question, andquestion_summaryfields (derived fromquestion,prompt, ormessagekeys) and collapses control characters/newlines. The original full tool input/response is not retained in the normalized payload for these alerts.Structure delivery identity objects
mainFor explicit delivery contract types, it is recommended to use a documented delivery identity object. This object should encapsulate the following properties to define how an event is delivered:
canonical event kindsinktargetformatmentiontemplatedynamic-token policy
How the Filesystem-Offloaded Memory pattern works
mainThe offloaded memory pattern uses a two-layer approach to manage context: a fast pointer layer (
MEMORY.md) and a detailed leaf layer (memory/directory).The Operating Rule
Treat
MEMORY.mdas a high-signal map, not a place for accumulating detail.The workflow is:
- Read
MEMORY.mdfirst to find the current state and pointers. - Jump to the smallest relevant shard (leaf file) for specific details.
- Write detailed information into the leaf files.
- Update root pointers in
MEMORY.mdonly when the map or current beliefs change.
Data Routing
If the update is about... Write to... what happened today memory/daily/YYYY-MM-DD.mdone Discord/Slack/channel lane memory/channels/<channel>.mdone project/repo memory/projects/<project>.mdone agent/operator profile memory/agents/<agent>.mdreusable lessons memory/topics/lessons.mddurable policies/rules memory/topics/rules.mdone handoff memory/handoffs/YYYY-MM-DD-<slug>.mdolder inactive history memory/archive/...- Read
Use provider-native hooks for Codex and Claude
mainclawhip integrates with Codex and Claude via provider-native hooks. Instead of using clawhip as a launch wrapper, Codex and Claude own the session launch and hook registration. clawhip serves as the routing and delivery layer for shared v1 hook events:
SessionStartPreToolUsePostToolUseUserPromptSubmitStop
To manually verify payloads for these providers, use the
native hookcommand.clawhip native hook --provider codex --file payload.json clawhip native hook --provider claude --file payload.json cat payload.json | clawhip native hook --provider codexHow the additive question-request bridge works
mainThe question-request bridge maps specific tool identifiers used in
PreToolUseorPostToolUseevents to thequestion.requestedroute key (which canonicalizes tosession.blocked).Mapping Logic: The bridge uses an allowlist of tool identifiers:
askask_userask_user_questionAskUserQuestionaskuserquestion
Safety and Privacy: To ensure public safety, normalized question events are bounded. They expose only a
summaryorquestion_summary. Raw tool input and tool response bodies are omitted from the normalizedpayloadorevent_payloadcopies to prevent leaking sensitive data.Implement filesystem-offloaded memory
mainUse the filesystem-offloaded memory skill to implement a Claw OS-style memory system. Instead of maintaining a single monolithicMEMORY.mdfile, this pattern usesMEMORY.mdas a lightweight pointer/index/current-beliefs layer that points into a structuredmemory/directory tree. This prevents memory files from becoming too large to scan and allows agents to load only the relevant shards of information.Understand the Shared v1 Hook Surface
mainThe v1 hook contract intentionally supports only five specific events shared by both Codex and Claude. Provider-specific extra events are not part of the shared route surface until explicitly adopted by clawhip.
Supported events:
SessionStartPreToolUsePostToolUseUserPromptSubmitStop
Understand the Filesystem-offloaded memory pattern
mainWhen integrating
clawhipinto a broader Claw OS workflow, use the filesystem-offloaded memory pattern. This treats memory as an offloaded filesystem tree rather than just volatile state.Structure:
MEMORY.md: Acts as a small pointer, index, or layer for "current beliefs."memory/: A directory containing detailed project, channel, daily, and handoff memory.
Best Practice: Only update the root memory (
MEMORY.md) when the high-level map or the current summary changes. For detailed implementation, refer todocs/memory-offload-architecture.mdanddocs/memory-offload-guide.md.How the clawhip event pipeline works
mainclawhip v0.4.0 uses a daemon-first event pipeline designed for Discord delivery. The architecture follows a decoupled flow where event producers (sources) feed a central queue, which is then processed by a dispatcher that coordinates routing, rendering, and delivery.
High-level flow:
- Ingress: Events are captured from various inputs (CLI, webhooks, git, GitHub, tmux).
- Sources: Dedicated
Sourceimplementations poll or monitor for changes. - Queue: Events are placed into a shared Tokio
mpscqueue. - Dispatcher: The central coordinator consumes the queue, resolves routes, renders content, and hands it to a sink.
- Router: Resolves an event to zero or more (0..N) deliveries.
- Renderer: Formats the event body (e.g., into compact, alert, inline, or raw output).
- Sink: The final transport layer (e.g., Discord REST delivery).
[CLI / webhook / git / GitHub / tmux] -> [sources] -> [mpsc queue] -> [dispatcher] -> [router -> renderer -> discord sink] -> [Discord REST delivery]Understand clawhip delivery semantics
mainWhen operating clawhip v0.4.0, keep the following delivery behaviors in mind:
- Ordering: Events follow per-source FIFO (First-In, First-Out) through the shared queue.
- Reliability: The system uses best-effort multi-delivery. If one delivery fails (e.g., due to a routing error or sink issue), it does not stop other deliveries for the same event.
- Retries: There is no built-in retry queue; failed deliveries are not automatically retried.
- State: The dispatcher remains stateless. While
TmuxSourceuses windowing for keyword hits, the core dispatch pipeline does not maintain state between events.