Skip to content

Creating Custom Sensors

Sensors are shell scripts that run as Claude Code hooks. You can create custom sensors alongside catalog-provided ones.

  1. Create a file in agent/Sensors/ (e.g., agent/Sensors/my-sensor.sh)
  2. Add YAML frontmatter with description, event, and optionally matcher
  3. Run bonsai update — it detects untracked files and offers to track them
  4. Once tracked, custom sensors appear in CLAUDE.md, .bonsai.yaml, and .claude/settings.json

Sensors need extra fields compared to skills:

---
description: Blocks risky operations on Fridays
display_name: Friday Guard
event: PreToolUse
matcher: Bash
---
#!/usr/bin/env bash
# Script content here
...
FieldRequiredNotes
descriptionYesShown in CLAUDE.md nav tables
display_nameNoHuman-readable name
eventYesHook event: SessionStart, PreToolUse, PostToolUse, Stop, UserPromptSubmit, SubagentStop
matcherNoTool filter (e.g., Bash, Edit, Write, Edit|Write)
EventWhen it firesCan block?
SessionStartBeginning of a conversationNo
UserPromptSubmitBefore Claude processes a user messageYes (exit code 2)
PreToolUseBefore a tool executesYes (exit code 2)
PostToolUseAfter a tool executesNo
StopAfter every Claude responseYes (exit code 2)
SubagentStopWhen a dispatched subagent finishesNo
  • Use kebab-case for filenames: my-custom-sensor.sh, not MyCustomSensor.sh
  • The filename (minus extension) becomes the item’s machine name
  • Use .sh extension

When you run bonsai update with custom sensors:

  1. Detects untracked .sh files in agent/Sensors/
  2. Validates frontmatter — warns if event is missing
  3. Tracks in .bonsai.yaml and .bonsai-lock.yaml
  4. Syncs .claude/settings.json hooks — adds hook entries for custom sensors
  5. Refreshes CLAUDE.md nav tables