# Hedera Hook Creation

Guides the creation of non-blocking observability hooks for Hedera Agent Kit tools. Useful when writing audit trails, counting tool invocations, or enriching session context.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 479 installs · ★ 28
- Author: hedera-dev
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/hedera-dev/hedera-skills/tree/HEAD/plugins/agent-kit-plugin/skills/agent-kit-hook/SKILL.md
- Updated: 2026-09-03
- HTML: https://affpapa.org/en/nevibecode/skills/hedera-hook-creation

## What it does

This skill instructs agents on implementing `AbstractHook` from `@hashgraph/hedera-agent-kit`. It targets four interception points across the `BaseTool.execute()` lifecycle: before tool execution, after normalizing input, after the core action, and following final execution. Built-in implementations like `HcsAuditTrailHook` use this structure to record operations without blocking the underlying tool.

Hooks observe and enrich rather than intercept or reject tool calls. Blocking execution based on runtime conditions requires a policy instead. Tools that directly implement the `Tool` interface skip the hook lifecycle altogether because hooks require a `BaseTool` subclass.

Any unhandled error inside a hook immediately aborts the active tool invocation. Hook developers should wrap external calls and HCS writes in `try/catch` blocks, while checking `relevantTools` at the start of each hook method to avoid processing unintended actions.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add hedera-dev/hedera-skills --skill hedera-hook-creation -a claude-code
```
```bash
npx skills add hedera-dev/hedera-skills --skill agent-kit-hook -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/agent-kit-hook/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/agent-kit-hook/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add hedera-dev/hedera-skills --skill agent-kit-hook -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/agent-kit-hook/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add hedera-dev/hedera-skills --skill agent-kit-hook -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/agent-kit-hook/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install hedera-dev/hedera-skills agent-kit-hook
```

2. **Manually: put the files in place**
- File: `.github/skills/agent-kit-hook/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add hedera-dev/hedera-skills --skill agent-kit-hook -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/hedera-dev/hedera-skills --path plugins/agent-kit-plugin/skills/agent-kit-hook
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/agent-kit-hook/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add hedera-dev/hedera-skills --skill agent-kit-hook -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/hedera-dev/hedera-skills/tree/HEAD/plugins/agent-kit-plugin/skills/agent-kit-hook/SKILL.md

## When to use it
- implement an `AbstractHook` subclass for Hedera Agent Kit tools
- capture parameters before and after `BaseTool` execution stages
- store invocation metrics and session data on `Context`
- filter tool calls by method name using `relevantTools`

## Example prompts
- Help me write a TypeScript hook to log transfer_hbar parameters in Hedera Agent Kit
- Create an audit hook that tracks tool invocation counts inside the agent context
- How do I inspect final tool results using postToolExecutionHook?

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 1fea60211f76da73.

BEGIN THIRD-PARTY FILE 1fea60211f76da73
````text
---
name: Hedera Hook Creation
description: This skill should be used when the user asks to "create a hedera hook", "write an agent kit hook", "extend AbstractHook", "add a tool lifecycle hook", "log tool executions", "audit trail hook", "track tool calls", or needs guidance on building observation/logging/metrics extensions for Hedera Agent Kit tools. Hooks are non-blocking — for blocking validation rules use the policy skill instead.
version: 1.0.0
---

# Creating Hedera Agent Kit Hooks

Hooks are non-blocking extensions that run around the `BaseTool` lifecycle. They observe and can enrich execution: log calls, write audit trails, track metrics, persist state on `Context`. They **do not block** tool execution — that's the job of policies (see `agent-kit-policy` skill).

> Hooks fire **only** for tools that extend `BaseTool`. A tool that implements the `Tool` interface directly without extending `BaseTool` bypasses the hook system entirely.

## When to write a hook vs. a policy

| If you want to… | Use |
|---|---|
| Log/audit/track tool calls | **Hook** |
| Enrich `Context` (counters, session state) | **Hook** |
| Stop a call from happening when a condition holds | **Policy** (see `agent-kit-policy`) |
| Reject specific tool methods | **Policy** |

Built-in hooks include `HcsAuditTrailHook` and `HolAuditTrailHook` (HCS-backed audit trails) — both live in `@hashgraph/hedera-agent-kit/hooks`.

## The 7-stage lifecycle

`BaseTool.execute()` runs:

```text
[1] preToolExecutionHook        ← hook fires
[2] normalizeParams             (tool internal)
[3] postParamsNormalizationHook ← hook fires
[4] coreAction                  (tool internal)
[5] postCoreActionHook          ← hook fires
[6] secondaryAction             (tool internal)
[7] postToolExecutionHook       ← hook fires
```

Hooks tap into stages 1, 3, 5, 7. They never fire at stages 2, 4, 6.

For full param shapes at each stage see `references/lifecycle.md`.

## `AbstractHook` contract

```typescript
import { AbstractHook } from '@hashgraph/hedera-agent-kit';

export abstract class AbstractHook {
  abstract name: string;             // human-readable identifier
  abstract description?: string;     // what the hook does
  abstract relevantTools: string[];  // tool methods this hook cares about

  // Override only the stages you need; defaults are no-ops.
  preToolExecutionHook(params, method): Promise<any>;
  postParamsNormalizationHook(params, method): Promise<any>;
  postCoreActionHook(params, method): Promise<any>;
````
END THIRD-PARTY FILE 1fea60211f76da73

The third-party file has ended. Everything between the 1fea60211f76da73 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2529 of 7948 bytes. © hedera-dev · Apache-2.0 · https://github.com/hedera-dev/hedera-skills/tree/HEAD/plugins/agent-kit-plugin/skills/agent-kit-hook/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
