Creating Custom Sensors
Sensors are shell scripts that run as Claude Code hooks. You can create custom sensors alongside catalog-provided ones.
How It Works
Section titled “How It Works”- Create a file in
agent/Sensors/(e.g.,agent/Sensors/my-sensor.sh) - Add YAML frontmatter with
description,event, and optionallymatcher - Run
bonsai update— it detects untracked files and offers to track them - Once tracked, custom sensors appear in CLAUDE.md,
.bonsai.yaml, and.claude/settings.json
Frontmatter Format
Section titled “Frontmatter Format”Sensors need extra fields compared to skills:
---description: Blocks risky operations on Fridaysdisplay_name: Friday Guardevent: PreToolUsematcher: Bash---
#!/usr/bin/env bash# Script content here...| Field | Required | Notes |
|---|---|---|
description | Yes | Shown in CLAUDE.md nav tables |
display_name | No | Human-readable name |
event | Yes | Hook event: SessionStart, PreToolUse, PostToolUse, Stop, UserPromptSubmit, SubagentStop |
matcher | No | Tool filter (e.g., Bash, Edit, Write, Edit|Write) |
Available Events
Section titled “Available Events”| Event | When it fires | Can block? |
|---|---|---|
SessionStart | Beginning of a conversation | No |
UserPromptSubmit | Before Claude processes a user message | Yes (exit code 2) |
PreToolUse | Before a tool executes | Yes (exit code 2) |
PostToolUse | After a tool executes | No |
Stop | After every Claude response | Yes (exit code 2) |
SubagentStop | When a dispatched subagent finishes | No |
File Naming
Section titled “File Naming”- Use kebab-case for filenames:
my-custom-sensor.sh, notMyCustomSensor.sh - The filename (minus extension) becomes the item’s machine name
- Use
.shextension
What bonsai update Does for Sensors
Section titled “What bonsai update Does for Sensors”When you run bonsai update with custom sensors:
- Detects untracked
.shfiles inagent/Sensors/ - Validates frontmatter — warns if
eventis missing - Tracks in
.bonsai.yamland.bonsai-lock.yaml - Syncs
.claude/settings.jsonhooks — adds hook entries for custom sensors - Refreshes CLAUDE.md nav tables