Skip to content

Markdown Handlers

Define event handlers using pure markdown — no code required. Handler content flows into agent context when events fire, influencing agent behavior through contextual instructions.

Handlers let you write guidance that activates on specific events. Instead of writing code, you write the content that should enter the agent’s context.

---
type: handlers
---
## [Event:: tool:before]
### edit_file
When editing files:
- Preserve existing code style
- Add tests for changed functions
- Update related documentation

When edit_file is about to execute, this guidance joins the agent’s working context.

Handler documents declare their type in frontmatter:

---
type: handlers
---

Mark a heading as an event handler with [Event:: <event-type>]:

## [Event:: tool:before]

Case-insensitive — [event:: tool:before] and [EVENT:: TOOL:BEFORE] are equivalent. UX may normalize display.

Child headings narrow the event pattern using glob-style matching:

## [Event:: tool:before]
### edit_file
Content for edit_file...
### create_file
Content for create_file...
### *.rs
Content for any Rust file operation...

Patterns can also be inline with slashes:

## [Event:: tool:before/edit_file/*.rs]
Rust-specific file editing guidance...

Both forms are equivalent — use nesting for organization, inline for simple cases.

Everything under the deepest matching heading (excluding child headings) is the handler content:

## [Event:: tool:before]
This paragraph is skipped (explanation only).
### edit_file
This content IS injected when edit_file fires.
More paragraphs here also injected.
#### Subsection
This is part of edit_file content too.
### create_file
Different content for create_file.

Paragraphs between the event heading and first pattern heading are explanations — not injected.

EventFiresUse Case
tool:beforeBefore tool executesInject guidance, constraints
tool:afterAfter tool completesPost-processing hints
tool:errorWhen tool failsError handling guidance
EventFiresUse Case
note:parsedAfter note is parsedContent-aware processing
note:createdWhen note is createdTemplate injection
note:modifiedWhen note changesChange-aware guidance
EventFiresUse Case
agent:before_llmBefore LLM callSystem prompt additions

Patterns use glob-style matching:

PatternMatches
edit_fileExact match
edit_*Starts with edit_
*_fileEnds with _file
*.rsAny .rs file
**/*.rsRust files in any subdirectory
*Everything
---
type: handlers
---
## [Event:: tool:before]
### edit_file
### create_file
Follow the project style guide:
- 2-space indentation
- Single quotes for strings
- Trailing commas in multi-line structures
### edit_file/*.test.*
For test files:
- Use descriptive test names
- One assertion per test when possible
- Mock external dependencies
---
type: handlers
---
## [Event:: tool:before]
### *delete*
Before deleting anything:
- Confirm the file is not in use
- Check for dependent files
- Consider moving to archive instead
### bash
Shell commands must:
- Avoid `rm -rf` without confirmation
- Use explicit paths, not globs
- Check exit codes
---
type: handlers
---
## [Event:: tool:before/edit_file]
### *.rs
Rust conventions:
- Run `cargo fmt` style
- Add doc comments to public items
- Use `Result` over panics
### *.py
Python conventions:
- Follow PEP 8
- Add type hints
- Use f-strings over format()
### *.ts
TypeScript conventions:
- Strict mode always
- Explicit return types on exports
- Prefer interfaces over type aliases
  1. Event fires (e.g., tool:before for edit_file)
  2. System finds handler documents (type: handlers)
  3. Matches event type and pattern against handler headings
  4. Collects content from all matching handlers
  5. Injects into agent context before processing

Multiple handlers can match — all matching content is combined.

Editors can enhance handler documents with:

  • Virtual text: Show resolved discriminant (tool:before/edit_file/*.rs)
  • Folding: Collapse [Event::] headings to event type
  • Highlighting: Distinguish patterns from content
  • Validation: Warn on invalid event types or patterns