Frappe_Claude_Skill_Package frappe-ops-bench
install
source · Clone the upstream repo
git clone https://github.com/OpenAEC-Foundation/Frappe_Claude_Skill_Package
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/OpenAEC-Foundation/Frappe_Claude_Skill_Package "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/source/ops/frappe-ops-bench" ~/.claude/skills/openaec-foundation-frappe-claude-skill-package-frappe-ops-bench && rm -rf "$T"
manifest:
skills/source/ops/frappe-ops-bench/SKILL.mdsource content
Bench CLI Complete Reference
Complete bench CLI reference for site management, app lifecycle, configuration, and multi-tenancy.
Version: v14/v15/v16
Quick Reference: Essential Commands
| Task | Command |
|---|---|
| Create bench | |
| Create site | |
| Set default site | |
| Get app | |
| Install app | |
| Start dev server | |
| Run migrations | |
| Build assets | |
| Backup site | |
| Restore backup | |
| Open console | |
| Open DB shell | |
| Check scheduler | |
| View pending jobs | |
| Update everything | |
| Drop site | |
Workflow 1: Creating a New Bench
# Initialize bench with specific Frappe version bench init myproject --frappe-branch version-15 # With Python version bench init myproject --frappe-branch version-15 --python python3.11 # Enter bench directory (REQUIRED for all subsequent commands) cd myproject
What
creates:bench init
myproject/ ├── apps/ # Installed Frappe apps (frappe is default) ├── sites/ # All sites and shared config │ └── common_site_config.json ├── config/ # Redis, Procfile, supervisor configs ├── env/ # Python virtual environment ├── logs/ # Log files └── Procfile # Process definitions for bench start
Critical Rules
- ALWAYS specify
to pin Frappe version--frappe-branch - ALWAYS run commands from inside the bench directory
- NEVER run bench commands as root — use a dedicated frappe user
Workflow 2: Site Management
Creating Sites
# Basic site creation bench new-site mysite.localhost --admin-password admin # With specific database bench new-site mysite.localhost --db-name mysite_db --admin-password admin # With MariaDB root password bench new-site mysite.localhost --mariadb-root-password rootpass --admin-password admin # Install apps during creation bench new-site mysite.localhost --admin-password admin --install-app erpnext
Setting Default Site
bench use mysite.localhost # OR set environment variable for current session: export FRAPPE_SITE=mysite.localhost
Dropping a Site
bench drop-site mysite.localhost --force # Deletes database and archives site directory
Site Directory Structure
sites/mysite.localhost/ ├── site_config.json # Site-specific config (db credentials) ├── private/ # Auth-required files, backups ├── public/ # Publicly accessible files ├── locks/ # Scheduler lock files └── task-logs/ # Scheduler task logs
Workflow 3: App Management
# Download app from GitHub bench get-app erpnext --branch version-15 bench get-app https://github.com/org/custom-app.git --branch main # Install app on a site bench --site mysite install-app erpnext # List installed apps bench --site mysite list-apps # Remove app from site (creates backup first) bench --site mysite uninstall-app custom_app # Remove app from bench entirely bench remove-app custom_app # Switch app branch bench switch-to-branch version-15 erpnext frappe # Exclude app from updates bench exclude-app custom_app # Re-include app in updates bench include-app custom_app
Critical Rules
- ALWAYS
beforeget-app
— get downloads, install activatesinstall-app - ALWAYS backup before
— it deletes app-related datauninstall-app - NEVER manually delete app folders — use
bench remove-app
Workflow 4: bench update: What It Does
# Full update (pull + migrate + build + restart) bench update # Update specific app only bench update --pull --app erpnext # Skip build step bench update --no-build # Skip backup bench update --no-backup # Reset to upstream (DESTROYS local changes) bench update --reset
executes these steps in order:bench update
- Backup all sites
- Pull latest code for all apps (
)git pull - Install Python/Node requirements
- Build static assets (
)bench build - Run migrations on all sites (
)bench migrate - Restart bench processes
Critical Rules
- ALWAYS run
in a screen/tmux session — it takes timebench update - NEVER use
in production without understanding it does--resetgit reset --hard - ALWAYS test updates on staging first
Workflow 5: bench migrate
# Migrate specific site bench --site mysite migrate # Migrate all sites bench --site all migrate # Check if safe to migrate (no pending jobs) bench --site mysite ready-for-migration
What
does:bench migrate
- Runs schema sync (DocType changes → database)
- Runs patches (data migrations)
- Rebuilds search index
- Syncs translations
- Rebuilds Dashboard cache
When to Migrate
- After
(done automatically)bench update - After changing hooks.py
- After adding/modifying DocTypes
- After pulling code changes
- NEVER skip migrate after code changes — leads to schema mismatches
Workflow 6: bench build
# Build all apps bench build # Build specific app bench build --app myapp # Build with bundle analyzer bench build --app myapp --production # Watch mode (auto-rebuild on file changes) bench watch
When to Build
- After changing JS/CSS files
- After
(done automatically)bench get-app - After modifying
package.json - ALWAYS build after modifying client-side assets
Workflow 7: Console and Database Access
# IPython console (with Frappe loaded) bench --site mysite console # In console: # >>> frappe.get_doc("Sales Invoice", "INV-001") # >>> frappe.db.sql("SELECT name FROM `tabUser` LIMIT 5") # Auto-reload on code changes bench --site mysite console --autoreload # MariaDB shell bench --site mysite mariadb # >>> SELECT name, email FROM tabUser LIMIT 5; # PostgreSQL shell bench --site mysite postgres # Execute a method directly bench --site mysite execute myapp.tasks.daily_cleanup bench --site mysite execute myapp.api.process --kwargs '{"name": "INV-001"}' # Make authenticated request as Administrator bench --site mysite request GET /api/resource/User
Workflow 8: Backup and Restore
# Backup (database + files) bench --site mysite backup # Creates: sites/mysite/private/backups/ # YYYY-MM-DD_HHMMSS-mysite-database.sql.gz # YYYY-MM-DD_HHMMSS-mysite-files.tar # YYYY-MM-DD_HHMMSS-mysite-private-files.tar # Backup all sites bench backup-all-sites # Backup with encryption bench --site mysite backup --backup-encryption-key mykey # Restore from backup bench --site mysite restore /path/to/database.sql.gz # Restore with files bench --site mysite restore /path/to/database.sql.gz \ --with-public-files /path/to/files.tar \ --with-private-files /path/to/private-files.tar # Partial restore bench --site mysite partial-restore /path/to/database.sql.gz
Critical Rules
- ALWAYS backup before
,bench update
, oruninstall-appdrop-site - Backups older than 24 hours auto-deleted by default — configure
keep_backups_for_hours - ALWAYS test restore on a staging site before relying on a backup
Workflow 9: Scheduler and Background Jobs
# Enable/disable scheduler bench --site mysite scheduler enable bench --site mysite scheduler disable bench --site mysite scheduler pause bench --site mysite scheduler resume # Check scheduler health bench doctor # View queued jobs bench show-pending-jobs # Purge pending jobs bench --site mysite purge-jobs # Manually trigger scheduler event bench --site mysite trigger-scheduler-event hourly # Start worker manually (for debugging) bench worker --queue short
Workflow 10: Multi-Tenancy
DNS-Based Routing (Recommended)
# Enable DNS multi-tenancy bench config dns_multitenant on # Create sites with proper hostnames bench new-site site1.example.com --admin-password admin bench new-site site2.example.com --admin-password admin # Regenerate nginx config bench setup nginx # Reload nginx sudo service nginx reload
Requests are routed by matching the
Host header to site names.
Port-Based Routing (Alternative)
bench config dns_multitenant off bench new-site site2.localhost --admin-password admin bench set-nginx-port site2.localhost 8082 bench setup nginx sudo service nginx reload
Custom Domain Mapping
# Add domain to site bench setup add-domain site1.example.com --site mysite bench setup nginx sudo service nginx reload
Configuration: common_site_config.json
Located at
sites/common_site_config.json — applies to ALL sites.
Essential Keys
| Key | Default | Purpose |
|---|---|---|
| 1 | Number of background job workers |
| false | Auto-sync DocType changes to files |
| false | Enable DNS-based multi-tenancy |
| 2 | Web server worker count (min: 2) |
| 0 | Take all sites offline |
| 0 | Pause job scheduler |
| — | Default site when host not matched |
| false | Enable Server Scripts |
| 60 | Seconds between scheduler checks |
| 8000 | Development server port |
| 9000 | Socket.IO port |
| false | Auto-reload on asset rebuild |
Redis Configuration
| Key | Default |
|---|---|
| |
| |
| |
Setting Config Values
# Set common config (all sites) bench config set-common-config -c background_workers 4 bench config set-common-config -c developer_mode 1 # Set site-specific config bench --site mysite set-config developer_mode 1 bench --site mysite set-config maintenance_mode 1 # View current config bench --site mysite show-config
Configuration: site_config.json
Per-site config at
sites/<sitename>/site_config.json.
Mandatory Keys
| Key | Purpose |
|---|---|
| or |
| Database name |
| Database password |
Important Optional Keys
| Key | Purpose |
|---|---|
| Administrator initial password |
| Full site URL (with protocol) |
| Apps to install on restore/reinstall |
| CORS origins (, URL, or array) |
| Upload limit (default: 10MB) |
| Disable all outgoing email |
| Debug level (0-2, level 2 shows SQL queries) |
Environment Variable Overrides
Environment variables override config files. Key mappings:
FRAPPE_REDIS_QUEUE, FRAPPE_REDIS_CACHE, FRAPPE_DB_HOST, FRAPPE_DB_PORT, FRAPPE_DB_NAME, FRAPPE_DB_PASSWORD.
Priority: Environment Variable > site_config.json > common_site_config.json > Default
Production Setup
sudo bench setup production frappe-user # nginx + supervisor + fail2ban bench setup lets-encrypt mysite.example.com # SSL sudo bench restart # Restart services bench disable-production # Back to development
Version Differences
| Feature | V14 | V15 | V16 |
|---|---|---|---|
| bench init | Yes | Yes | Yes |
| Scheduler tick interval | ~240s | ~240s | 60s |
config (separate) | No | No | Yes |
| No | Yes | Yes |
command | No | Yes | Yes |
command | No | Yes | Yes |
command | No | Yes | Yes |
| Gettext translations | No | No | Yes |
Reference Files
| File | Contents |
|---|---|
| commands.md | Full command reference with all options |
| examples.md | Common workflow examples |
| custom-commands.md | Creating custom bench CLI commands with Click |
| anti-patterns.md | Common bench mistakes and fixes |