$npx -y skills add Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-syntax-hooksUse when configuring Frappe hooks.py for app events, scheduler tasks, document events, fixtures, boot session, jenv customization, or website routing. Covers v14/v15/v16 including extend_doctype_class. Keywords: hooks.py, doc_events, scheduler_events, fixtures, app_include_js, ov
| 1 | # Frappe Configuration Hooks (hooks.py) |
| 2 | |
| 3 | Configuration hooks in hooks.py enable custom apps to extend Frappe/ERPNext |
| 4 | behavior. This skill covers ALL non-document-event hooks. For `doc_events` |
| 5 | (validate, on_submit, on_update, etc.), see **frappe-syntax-hooks-events**. |
| 6 | |
| 7 | ## Quick Reference: Hook Categories |
| 8 | |
| 9 | | Category | Key Hooks | Reference | |
| 10 | |----------|-----------|-----------| |
| 11 | | App metadata | `app_name`, `app_title`, `required_apps` | Below | |
| 12 | | Frontend assets | `app_include_js/css`, `web_include_js/css` | Below | |
| 13 | | Install/migrate | `before_install`, `after_install`, `after_migrate` | Below | |
| 14 | | Scheduler | `hourly`, `daily`, `cron`, `*_long` | [scheduler-events.md](references/scheduler-events.md) | |
| 15 | | Session/auth | `on_login`, `on_logout`, `auth_hooks` | [bootinfo.md](references/bootinfo.md) | |
| 16 | | Request middleware | `before_request`, `after_request` | [request-lifecycle.md](references/request-lifecycle.md) | |
| 17 | | Permissions | `permission_query_conditions`, `has_permission` | [permissions.md](references/permissions.md) | |
| 18 | | DocType overrides | `override_doctype_class`, `doctype_js` | [overrides.md](references/overrides.md) | |
| 19 | | Website/portal | `website_route_rules`, `portal_menu_items` | [request-lifecycle.md](references/request-lifecycle.md) | |
| 20 | | File handling | `before_write_file`, `write_file` | Below | |
| 21 | | Email | `override_email_send`, `default_mail_footer` | Below | |
| 22 | | PDF | `pdf_header_html`, `pdf_footer_html` | Below | |
| 23 | | Jinja | `jinja.methods`, `jinja.filters` | Below | |
| 24 | | Boot/client data | `extend_bootinfo`, `notification_config` | [bootinfo.md](references/bootinfo.md) | |
| 25 | | Data/fixtures | `fixtures`, `global_search_doctypes` | Below | |
| 26 | | Method overrides | `override_whitelisted_methods`, `standard_queries` | [overrides.md](references/overrides.md) | |
| 27 | |
| 28 | --- |
| 29 | |
| 30 | ## Decision Tree: Which Hook Do I Need? |
| 31 | |
| 32 | ``` |
| 33 | What do you want to achieve? |
| 34 | | |
| 35 | +-- ADD JS/CSS to desk or portal? |
| 36 | | +-- Desk --> app_include_js / app_include_css |
| 37 | | +-- Portal --> web_include_js / web_include_css |
| 38 | | +-- Specific form --> doctype_js |
| 39 | | +-- List view --> doctype_list_js |
| 40 | | |
| 41 | +-- RUN periodic background tasks? |
| 42 | | +-- < 5 min execution --> hourly / daily / weekly / monthly |
| 43 | | +-- 5-25 min execution --> hourly_long / daily_long / etc. |
| 44 | | +-- Exact time needed --> cron |
| 45 | | See: frappe-syntax-hooks > scheduler-events.md |
| 46 | | |
| 47 | +-- SEND data to client at page load? |
| 48 | | +-- extend_bootinfo |
| 49 | | |
| 50 | +-- MODIFY controller of existing DocType? |
| 51 | | +-- v16+ --> extend_doctype_class (RECOMMENDED) |
| 52 | | +-- v14/v15 --> override_doctype_class (last app wins) |
| 53 | | |
| 54 | +-- MODIFY API endpoint? |
| 55 | | +-- override_whitelisted_methods |
| 56 | | |
| 57 | +-- CUSTOMIZE permissions? |
| 58 | | +-- List filtering --> permission_query_conditions |
| 59 | | +-- Document-level --> has_permission |
| 60 | | |
| 61 | +-- REACT to document save/submit/delete? |
| 62 | | +-- See frappe-syntax-hooks-events skill |
| 63 | | |
| 64 | +-- EXPORT/IMPORT configuration? |
| 65 | | +-- fixtures |
| 66 | | |
| 67 | +-- SETUP on install or migrate? |
| 68 | | +-- after_install / after_migrate |
| 69 | | |
| 70 | +-- ADD custom Jinja functions? |
| 71 | | +-- jinja.methods / jinja.filters |
| 72 | | |
| 73 | +-- CUSTOMIZE website routing? |
| 74 | | +-- website_route_rules |
| 75 | | See: request-lifecycle.md for full routing pipeline |
| 76 | | |
| 77 | +-- INTERCEPT every request/response? |
| 78 | | +-- before_request / after_request |
| 79 | | See: request-lifecycle.md for lifecycle flow |
| 80 | | |
| 81 | +-- CUSTOM page rendering? |
| 82 | | +-- page_renderer hook |
| 83 | | See: request-lifecycle.md for renderer architecture |
| 84 | ``` |
| 85 | |
| 86 | --- |
| 87 | |
| 88 | ## 1. App Metadata Hooks |
| 89 | |
| 90 | ALWAYS include these in every hooks.py: |
| 91 | |
| 92 | ```python |
| 93 | app_name = "myapp" |
| 94 | app_title = "My App" |
| 95 | app_publisher = "My Company" |
| 96 | app_description = "Custom ERPNext extensions" |
| 97 | app_email = "info@mycompany.com" |
| 98 | app_license = "MIT" |
| 99 | required_apps = ["erpnext"] # Declare dependencies |
| 100 | ``` |
| 101 | |
| 102 | --- |
| 103 | |
| 104 | ## 2. Frontend Asset Injection |
| 105 | |
| 106 | ```python |
| 107 | # Desk (backend UI) assets — loaded on EVERY desk page |
| 108 | app_include_js = "/assets/myapp/js/myapp.min.js" # string or list |
| 109 | app_include_css = "/assets/myapp/css/myapp.min.css" |
| 110 | |
| 111 | # Website/portal assets — loaded on EVERY web page |
| 112 | web_include_js = "/assets/myapp/js/web.min.js" |
| 113 | web_include_css = "/assets/myapp/css/web.min.css" |
| 114 | |
| 115 | # Web form specific assets |
| 116 | webform_include_js = {"My Web Form": "public/js/my_webform.js"} |
| 117 | webform_include_css = {"My Web Form": "public/css/my_webform.css"} |
| 118 | |
| 119 | # Form script extensions (extend OTHER apps' forms) |
| 120 | doctype_js = {"Sales Invoice": "public/js/sales_invoice.js"} |
| 121 | |
| 122 | # List view script extensions |