Agent skill

Frappe Syntax Hooks Events

by Impertio-Studio in Impertio-Studio/Frappe_Claude_Skill_Package

A skill your agent uses when implementing document lifecycle hooks via docevents in hooks.py, understanding event execution order, or extending/overriding document behavior from another app.

MITAuto-check passed

Install Frappe Syntax Hooks Events

skills CLI
$ npx skills add Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-syntax-hooks-events -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install Impertio-Studio/Frappe_Claude_Skill_Package frappe-syntax-hooks-events --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/source/syntax/frappe-syntax-hooks-events .claude/skills/frappe-syntax-hooks-events && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
frappe-syntax-hooks-events
GitHub stars
189
Token cost
~3.1k tokens
SKILL.md length
1,013 words
Files
5 (incl. references)
Skills in repo
61
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses when implementing document lifecycle hooks via docevents in hooks.py, understanding event execution order, or extending/overriding document behavior from another app.

  • Works in 3 steps: Controller method runs first (def… → doc_events handlers run in app… → Wildcard "*" handlers run after specific…
  • Implementing document lifecycle hooks via docevents in hooks.py
  • SKILL.md covers Quick Reference: Event…, doc_events in hooks.py: Syntax, Decision Tree: Which Event to… and doc_events vs Controller Events, plus 1 more section
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Frappe Syntax Hooks Events is an agent skill from Impertio-Studio/Frappe_Claude_Skill_Package. Use when implementing document lifecycle hooks via docevents in hooks.py, understanding event execution order, or extending/overriding document behavior from another app. Prevents silent hook failures from wrong event names, incorrect execution order assumptions, and broken override chains. Covers docevents hook syntax, all document events (beforeinsert, validate, onsubmit, etc.), event execution order, extend vs override behavior, cross-app docevents. Keywords: docevents, hooks.py, beforeinsert, validate…

Its SKILL.md is about 3.1k tokens, which your agent loads only when the skill is triggered. The skill folder holds 5 other files, including reference files (for example `references/anti-patterns.md`, `references/event-order.md` and `references/examples.md`). Compatibility notes: Claude Code, Claude.ai Projects, Claude API. Frappe v14-v16.

The repository describes itself as: 60 deterministic Claude AI skills for Frappe Framework & ERPNext v14-v16 development and operations. The licence is MIT.

When your agent uses it

  • Implementing document lifecycle hooks via docevents in hooks.py
  • Understanding event execution order
  • Extending/overriding document behavior from another app

Example prompts

  • “/frappe-syntax-hooks-events”

Requirements

  • Python 3
  • Compatibility (from SKILL.md): Claude Code, Claude.ai Projects, Claude API. Frappe v14-v16.

Workflow steps

3 steps, taken from the first numbered list in SKILL.md.

  1. Controller method runs first (def validate(self))
  2. doc_events handlers run in app installation order
  3. Wildcard "*" handlers run after specific DocType handlers

What it can do on your machine

Read from SKILL.md and the folder at commit 36cfa80. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are python).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • docs.frappe.io

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    Claude Code, Claude.ai Projects, Claude API. Frappe v14-v16.

    From compatibility in the SKILL.md frontmatter.

Context cost

Frappe Syntax Hooks Events loads about 3.1k tokens when it runs, and up to ~8.5k if it reads all its reference files. Until then it costs about 174 tokens; SKILL.md has 1,013 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~174
When it runs · the whole SKILL.md, loaded when a task matches
~3.1k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~8.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from Impertio-Studio/Frappe_Claude_Skill_Package at commit 36cfa80, republished under its MIT licence (© Impertio-Studio). 1,013 words, ~3,117 tokens.

Download SKILL.mdSave it as .claude/skills/frappe-syntax-hooks-events/SKILL.md (or your agent's skills folder). This skill also uses 4 other files; get the full folder from GitHub.
name
frappe-syntax-hooks-events
description
Use when implementing document lifecycle hooks via doc_events in hooks.py, understanding event execution order, or extending/overriding document behavior from another app. Prevents silent hook failures from wrong event names, incorrect execution order assumptions, and broken override chains. Covers doc_events hook syntax, all document events (before_insert, validate, on_submit, etc.), event execution order, extend vs override behavior, cross-app doc_events. Keywords: doc_events, hooks.py, before_insert, validate, on_submit, on_cancel, lifecycle, document events, override, extend, event order, which event fires when, before_save vs validate, document event list..
compatibility
Claude Code, Claude.ai Projects, Claude API. Frappe v14-v16.
license
MIT
metadata.author
OpenAEC-Foundation
metadata.version
2.0

Document Lifecycle Hooks (doc_events)

Quick Reference: Event Execution Order

Insert (new document)
OrderEventPurposeCan Raise?
1before_insertSet defaults before namingYES
2before_namingModify naming logicYES
3autonameSet the name propertyYES
4before_validateAuto-set missing valuesYES
5validateValidation logic — throw to abortYES
6before_saveFinal mutations before DB writeYES
7db_insertInternal — writes row to DB—
8after_insertPost-insert logic (runs once ever)YES
9on_updatePost-save logic (runs on every save)YES
10on_changeFires if any field value changedYES
Save (existing document)
OrderEventPurpose
1before_validateAuto-set missing values
2validateValidation logic — throw to abort
3before_saveFinal mutations before DB write
4db_updateInternal — updates row in DB
5on_updatePost-save logic
6on_changeFires if any field value changed
Submit
OrderEventPurpose
1before_validateAuto-set missing values
2validateValidation logic
3before_saveFinal mutations before DB write
4before_submitPre-submit logic — throw to abort
5db_updateInternal — updates row in DB
6on_submitPost-submit logic (GL entries etc)
7on_updatePost-save logic
8on_changeFires if any field value changed
Cancel
OrderEventPurpose
1before_cancelPre-cancel validation
2db_updateInternal — updates row in DB
3on_cancelPost-cancel logic (reverse GL etc)
4on_changeFires if any field value changed
Delete
OrderEventPurpose
1on_trashPre-delete cleanup
2after_deletePost-delete logic
Other Operations
OperationEvents (in order)
Renamebefore_rename → after_rename
Amendbefore_insert chain runs on the new amended doc
Update After Submitbefore_update_after_submit → db_update → on_update_after_submit → on_change

doc_events in hooks.py: Syntax

Basic Structure
python
# hooks.py
doc_events = {
    "Sales Invoice": {
        "on_submit": "myapp.events.sales_invoice.on_submit",
        "on_cancel": "myapp.events.sales_invoice.on_cancel",
    },
    "Purchase Order": {
        "validate": "myapp.events.purchase_order.validate",
    }
}
Wildcard: Apply to ALL DocTypes
python
doc_events = {
    "*": {
        "after_insert": "myapp.events.global_handler.after_insert_all",
        "on_update": "myapp.events.global_handler.track_changes",
    }
}

ALWAYS use "*" (string with asterisk) as the key. This fires the handler for every DocType.

Multiple Handlers per Event
python
doc_events = {
    "Sales Invoice": {
        "on_submit": [
            "myapp.events.accounting.create_gl_entries",
            "myapp.events.notifications.send_invoice_email",
        ]
    }
}
Handler Function Signature
python
# myapp/events/sales_invoice.py
def on_submit(doc, method=None):
    """
    doc    — the Document instance (e.g., Sales Invoice)
    method — string name of the event (e.g., "on_submit"), or None
    """
    if doc.grand_total > 10000:
        frappe.sendmail(...)

ALWAYS accept method as the second parameter (with default None). Frappe passes it automatically.


Decision Tree: Which Event to Use

"I need to validate data before saving"

→ Use validate. ALWAYS raise frappe.throw() here to block invalid saves.

"I need to set default values automatically"

→ Use before_validate. This runs before validate, so your defaults are set before validation checks.

"I need to run logic only on first creation"

→ Use after_insert. This fires ONLY on insert, NEVER on subsequent saves.

"I need to run logic on every save (insert + update)"

→ Use on_update. This fires on both insert and save operations.

"I need to create linked documents after submit"

→ Use on_submit. NEVER create linked docs in validate — the document is not yet committed.

"I need to reverse linked documents on cancel"

→ Use on_cancel. ALWAYS clean up GL entries, stock ledger entries, and linked docs here.

"I need to modify the document name"

→ Use autoname in the controller, or before_naming for conditional logic.

"I need to prevent deletion under certain conditions"

→ Use on_trash. Raise frappe.throw() to block deletion.

"I need to update a submitted document's fields"

→ Use before_update_after_submit for validation and on_update_after_submit for side effects.

"I need logic that runs only when values actually changed"

→ Use on_change. This fires only when at least one field value differs from the DB state.


doc_events vs Controller Events

Both mechanisms trigger the SAME events. The difference is WHERE you register them.

AspectController (class method)doc_events (hooks.py)
Location{doctype}.py controller filehooks.py in your app
Use whenYou OWN the DocTypeYou are EXTENDING another app's DocType
ExecutionRuns first (controller)Runs after controller method
Multiple appsOnly one controller per DocTypeMultiple apps can register handlers

ALWAYS use doc_events when hooking into a DocType you do NOT own. NEVER modify another app's controller file directly.

Execution Order Within a Single Event

For a given event (e.g., validate):

  1. Controller method runs first (def validate(self))
  2. doc_events handlers run in app installation order
  3. Wildcard "*" handlers run after specific DocType handlers

Show full SKILL.md (390 more words)Show less

extend_doctype_class [v16+]

In Frappe v16+, extend_doctype_class provides a cleaner alternative to doc_events for adding methods to existing DocTypes.

hooks.py
python
extend_doctype_class = {
    "Sales Invoice": [
        "myapp.overrides.sales_invoice.SalesInvoiceExtension"
    ]
}
Extension Class (Mixin)
python
# myapp/overrides/sales_invoice.py
import frappe

class SalesInvoiceExtension:
    def validate(self):
        """This is called as part of the controller chain."""
        if self.grand_total < 0:
            frappe.throw("Grand total cannot be negative")

    def custom_method(self):
        """Custom methods are also available on the doc instance."""
        return self.items
Key Rules
  • ALWAYS use extend_doctype_class over override_doctype_class in v16+ when multiple apps may extend the same DocType.
  • Multiple apps can extend the same DocType — extensions stack via MRO.
  • Class resolution order follows hooks priority: class Final(App2Mixin, App1Mixin, Original).
  • Extension methods (like validate) run as part of the controller, NOT as separate doc_events handlers.

override_doctype_class [v14+]

Completely replaces the controller class. Use with extreme caution.

python
# hooks.py
override_doctype_class = {
    "ToDo": "myapp.overrides.todo.CustomToDo"
}
python
# myapp/overrides/todo.py
from frappe.desk.doctype.todo.todo import ToDo

class CustomToDo(ToDo):
    def validate(self):
        super().validate()  # ALWAYS call super() to preserve original logic
        # Your additions here

NEVER use override_doctype_class if extend_doctype_class is available (v16+). Only ONE app can override a DocType — last-installed app wins, silently breaking other apps.


Multi-App Event Ordering

When multiple apps register doc_events for the same DocType and event:

  1. Handlers execute in app installation order (as listed in sites/{site}/site_config.json → installed_apps).
  2. The order can be changed via Setup > Installed Applications > Update Hooks Resolution Order.
  3. For override_doctype_class, the last-installed app wins (only one override applies).
  4. For extend_doctype_class (v16+), all extensions stack cumulatively.

Transaction Behavior

All document events from before_validate through on_change run inside a single database transaction.

  • If ANY event raises an exception, the ENTIRE operation rolls back (including db_insert/db_update).
  • after_insert, on_update, on_submit, on_cancel — all run BEFORE the transaction commits.
  • The transaction commits only AFTER all events complete successfully.
  • after_delete runs after the DELETE statement but still within the request transaction.

NEVER assume data is committed to DB inside any event handler. Other concurrent requests will NOT see your changes until the full request completes.


Critical Rules

  1. ALWAYS use frappe.throw() to abort operations — NEVER use raise Exception.
  2. NEVER modify doc.name outside of autoname or before_naming.
  3. ALWAYS call super().{event}() when overriding controller methods in subclasses.
  4. NEVER use doc.save() inside validate or before_save — this causes infinite recursion.
  5. ALWAYS use doc.flags.ignore_permissions = True explicitly if your hook needs to bypass permissions — NEVER assume hooks run as Administrator.
  6. NEVER put slow operations (API calls, file I/O) in validate — use after_insert or on_update with frappe.enqueue() instead.
  7. ALWAYS use doc.flags to communicate between events in the same request (e.g., doc.flags.skip_notification = True).
  8. NEVER rely on on_change for critical logic — it only fires when values actually differ from the database state.

See Also

© Impertio-Studio, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 4 other files (references) in skills/source/syntax/frappe-syntax-hooks-events of Impertio-Studio/Frappe_Claude_Skill_Package.

  • SKILL.md
  • references/.gitkeep
  • references/anti-patterns.md
  • references/event-order.md
  • references/examples.md

Open the folder on GitHubat commit 36cfa80

Compare with similar skills

Frappe Syntax Hooks Events next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Frappe Syntax Hooks Events compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Frappe Syntax Hooks Events this skillImpertio-Studio/Frappe_Claude_Skill_Package189—~3.1kAutomated safety check: PassMIT
Docnexu-io/open-design100k—~266Automated safety check: PassApache-2.0
Docsremotion-dev/remotion63k—~248Automated safety check: PassCustom licence
Eventscoreyhaines31/marketingskills54k—~3kAutomated safety check: PassMIT
Update Docsvercel/next.js143k—~1.9kAutomated safety check: PassMIT
DocsPrefectHQ/fastmcp28k—~1kAutomated safety check: PassApache-2.0

Similar skills

  • Doc

    nexu-io/open-design

    Read, create, and edit .docx documents with formatting and layout fidelity via OpenAI's document skill.

    100k GitHub stars~266 tokensUpdated today
    Documents & OfficeAuto-check passed
  • Docs

    remotion-dev/remotion

    Official

    Start the Remotion docs site and open it in the Codex browser.

    63k GitHub stars~248 tokensUpdated today
    Media & CreativeAuto-check passed
  • Events

    coreyhaines31/marketingskills

    When the user wants to plan, run, sponsor, speak at, or get pipeline from events — webinars, conferences, trade shows, meetups, dinners, workshops, virtual summits, or user conferences.

    54k GitHub stars~3k tokensUpdated yesterday
    Marketing & SEOAuto-check passed
  • Update Docs

    vercel/next.js

    Official

    This skill should be used when the user asks to "update documentation for my changes", "check docs for this PR", "what docs need updating", "sync docs with code", "scaffold docs for this feature"…

    143k GitHub stars~1.9k tokensUpdated today
    Documents & OfficeAuto-check passed
  • Docs

    PrefectHQ/fastmcp

    Write or revise a page under docs/ for gofastmcp.com. An agent skill from PrefectHQ/fastmcp.

    28k GitHub stars~1k tokensUpdated today
    Frontend & DesignAuto-check passed
  • Docs Diagrams

    vercel/next.js

    Official

    Draw diagrams for the Next.js docs in the style of the ones already published there: the light/dark PNGs an mdx references with <Image srcLight="/docs/light/<name.png" srcDark="/docs/dark/<name.png".

    143k GitHub stars~2.9k tokensUpdated today
    DevelopmentAuto-check passed

More from Impertio-Studio/Frappe_Claude_Skill_Package

All 61 skills in this repo
  • Frappe Ops Website Deploy

    Impertio-Studio/Frappe_Claude_Skill_Package

    Deploy HTML/CSS websites to ERPNext/Frappe (v15/v16) as Web Pages via the REST API.

    189 GitHub stars~2.5k tokensUpdated 23 days ago
    Auto-check passed
  • Frappe Agent Architect

    Impertio-Studio/Frappe_Claude_Skill_Package

    A skill your agent uses when designing multi-app Frappe architectures, deciding whether to split functionality into separate apps, or implementing cross-app communication patterns.

    189 GitHub stars~2.8k tokensUpdated 23 days ago
    Auto-check passed
  • Frappe Agent Debugger

    Impertio-Studio/Frappe_Claude_Skill_Package

    A skill your agent uses when debugging Frappe errors, using bench console for live inspection, analyzing tracebacks, or reading Frappe log files.

    189 GitHub stars~2.9k tokensUpdated 23 days ago
    Auto-check passed
  • Frappe Agent Interpreter

    Impertio-Studio/Frappe_Claude_Skill_Package

    A skill your agent uses when receiving vague or unclear ERPNext/Frappe development requests that need interpretation.

    189 GitHub stars~3.2k tokensUpdated 23 days ago
    Auto-check passed
  • Frappe Agent Migrator

    Impertio-Studio/Frappe_Claude_Skill_Package

    A skill your agent uses when migrating a Frappe app between major versions, detecting breaking API changes, or resolving post-migration errors.

    189 GitHub stars~2.8k tokensUpdated 23 days ago
    Auto-check: notes
  • Frappe Agent Validator

    Impertio-Studio/Frappe_Claude_Skill_Package

    A skill your agent uses when reviewing or validating Frappe/ERPNext code against best practices and common pitfalls.

    189 GitHub stars~2.8k tokensUpdated 23 days ago
    Auto-check passed

Questions about Frappe Syntax Hooks Events

What does Frappe Syntax Hooks Events do?

A skill your agent uses when implementing document lifecycle hooks via docevents in hooks.py, understanding event execution order, or extending/overriding document behavior from another app. Frappe Syntax Hooks Events is an agent skill from Impertio-Studio/Frappe_Claude_Skill_Package.py, understanding event execution order, or extending/overriding document behavior from another app.

When should I use Frappe Syntax Hooks Events?

Frappe Syntax Hooks Events fits situations like: implementing document lifecycle hooks via docevents in hooks.py; understanding event execution order; extending/overriding document behavior from another app.

How do I install Frappe Syntax Hooks Events in Claude Code?

Run `npx skills add Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-syntax-hooks-events -a claude-code`. Or copy the skill folder (skills/source/syntax/frappe-syntax-hooks-events in Impertio-Studio/Frappe_Claude_Skill_Package) into .claude/skills/frappe-syntax-hooks-events in your project. Claude Code loads it when a task matches its description.

How do I install Frappe Syntax Hooks Events in Codex?

Run `npx skills add Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-syntax-hooks-events -a codex`. Or copy the skill folder (skills/source/syntax/frappe-syntax-hooks-events in Impertio-Studio/Frappe_Claude_Skill_Package) into .agents/skills/frappe-syntax-hooks-events in your project. Codex loads it when a task matches its description.

Can I use Frappe Syntax Hooks Events in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-syntax-hooks-events -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/frappe-syntax-hooks-events, .gemini/skills/frappe-syntax-hooks-events, .github/skills/frappe-syntax-hooks-events and .opencode/skills/frappe-syntax-hooks-events in your project.

What does Frappe Syntax Hooks Events need to run?

SKILL.md names no scripts, command-line tools or credentials: Frappe Syntax Hooks Events is instructions for the agent only. Our summary lists: Python 3. Compatibility (from SKILL.md): Claude Code, Claude.ai Projects, Claude API. Frappe v14-v16..

Does Frappe Syntax Hooks Events access the network?

SKILL.md names 1 domain. As links in the text: docs.frappe.io. This is read from the text; nothing was executed.

Is Frappe Syntax Hooks Events safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Frappe Syntax Hooks Events use?

Frappe Syntax Hooks Events is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Frappe Syntax Hooks Events use?

About 3.1k tokens (SKILL.md is roughly 12k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 5.4k tokens, read only when the agent opens those files.

What are the alternatives to Frappe Syntax Hooks Events?

Skills that share tags, products or a category with Frappe Syntax Hooks Events: Doc (nexu-io/open-design, 100k stars), Docs (remotion-dev/remotion, 63k stars), Events (coreyhaines31/marketingskills, 54k stars) and Update Docs (vercel/next.js, 143k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Frappe Syntax Hooks Events?

Impertio-Studio (a GitHub organization) maintains it in Impertio-Studio/Frappe_Claude_Skill_Package, which has 189 GitHub stars. The repository holds 61 skills in this directory. The repository was last updated on September 17, 2026.

Source: Impertio-Studio/Frappe_Claude_Skill_Package on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.