Developer docs
Start
Build with AI
Themes
Apps
- App development
- App development best practices
- Hooks and filters
- The App API
- Sending email from apps
- Admin bar for apps and themes
- Public routes for apps
- Admin screens, routes and UI components
- Dashboard widgets
- Data tables
- AJAX actions
- Media and uploads for apps
- App permissions
- Content types, blocks and widgets
- Content types, taxonomies and custom fields
- Search
- When an app fails: fault isolation and recovery
API and AI agents
Security and contributing
Basehim Dev Tools: build and manage your site with an AI agent
Basehim Dev Tools is a free app that lets an AI agent such as Claude work on your site through its MCP server: manage content, build and change themes and apps, read logs and fix problems. You install it from the Marketplace in your dashboard, connect the agent and choose what it may do. Every code change is checked before it is kept, and every change can be undone.
- What an agent can do
- Requirements
- Set up in five steps
- Modes: what the agent is allowed to do
- Working with the agent
- How changes are kept safe
- When something goes wrong
- Tool reference
- Good practice
What an agent can do
Every Basehim site has a built-in MCP server at /mcp. On its own, it gives an agent the content tools: search, read, create and update posts and pages, manage categories and tags, browse the media library, moderate comments, and read settings, users, menus and widget areas.
Dev Tools adds the tools for code:
| Area | What the agent can do with Dev Tools |
|---|---|
| Themes | Read and write theme files, create a new theme, see which theme is active. You switch themes yourself under Appearance → Themes, or the agent does it with PHP execution. |
| Apps | Read and write app files, create a new app, and activate, deactivate, re-scan or uninstall apps. |
| Diagnostics | Read the core log and app logs, run read-only SQL queries, list routes and render any page. |
| Checks | PHP syntax checks, health checks, the history of every change, and rollback. |
| Running code | Optional and off by default: run a PHP snippet inside the site, for example to change a setting or a menu that the content tools can only read. |
In practice, that means you can ask an agent for work like this, and it does it on the site itself:
- Write and publish posts, tidy categories and tags, fill in missing excerpts.
- Restyle the theme, add a template for one category, or build a new theme from a description or a screenshot.
- Build an app: an admin screen, a contact form, a dashboard card, a scheduled import, a public page.
- Find out why an app was switched off or a page shows an error, by reading the logs, then fix it.
- Check every page of the site at phone width and fix what overflows.
Requirements
| Item | Requirement |
|---|---|
| Basehim | 1.2.54 or later |
| Your account | An administrator: changing files needs manage_apps; running PHP needs manage_options |
| Site address | HTTPS, reachable from the internet, so the agent can connect to /mcp |
| Agent | Any MCP client that supports remote servers, such as Claude (custom connectors) or Claude Code |
| Recommended | The PHP command line and proc_open on the server, so each change can be tested by starting the site in a separate process; the curl extension, for the health checks. Without them, Dev Tools still works and reports which checks it skipped. |
Set up in five steps
Step 1: Install Dev Tools from the Marketplace
- In your dashboard, open Marketplace and find Basehim Dev Tools (category Development).
- Click Install. The download is checked against its checksum before it is installed.
- Click Activate.
Basehim Dev Tools now appears in the sidebar under Apps. It starts in Disabled mode, so nothing is reachable until you choose otherwise.
Step 2: Set up recovery
Do this before the agent changes anything. It gives you a way back that works even if the site, the admin and MCP are all down.
- Open Basehim Dev Tools → Recovery.
- Click Create key. The key is shown once: save it in your password manager.
- Click Install endpoint. This places
devtools-recovery.phpnext toindex.php. If the site folder isn't writable, download the script and upload it there with your file manager. - Click Test recovery.
Step 3: Connect the agent
Claude (OAuth). In Claude, add a custom connector with the address https://your-site.com/mcp and keep OAuth as the sign-in method. A window opens your site: sign in as an administrator, check the permissions on the Authorize screen, and click Allow access. The full walkthrough, with screenshots, is in Connect an AI assistant to your site.
Other MCP clients (API key). Open API → Keys, create a key for an administrator account, and tick only the scopes you need:
| Scope | Allows |
|---|---|
dev:read | Reading files, logs and the database, rendering pages, checks, the operations history |
dev:write | Changing app and theme files, and the app lifecycle |
dev:recover | Rolling back a change |
dev:execute | Running PHP snippets. Tick it only if you will switch on Allow PHP execution. |
Add the content scopes too (for example posts:read and posts:write) if the agent should also work on content. For Claude Code:
claude mcp add --transport http my-site https://your-site.com/mcp \
--header "Authorization: Bearer basehim_your_key"
Step 4: Choose the mode
Open Basehim Dev Tools → Controls and choose Read-only to let the agent look, or Development enabled to let it change apps and themes. The mode is checked on every call, so the change applies at once, also to connections that are already open. The modes are explained below.
Step 5: Start
Start a new conversation with the connector switched on, and ask the agent to call dev_status first. It reports the mode, exactly which tools work now and which checks this server can run. Then give it the first task.
Modes: what the agent is allowed to do
| Mode | The agent can |
|---|---|
| Disabled (default) | Read the mode and the operations history, and roll back earlier changes. No code, logs or database are visible. |
| Read-only | Read app, theme and core source, logs and the database (read-only, credentials redacted), render pages and run checks. Nothing on the site can change. |
| Development enabled | Change app and theme files and drive the app lifecycle. Every change is snapshotted, validated, health-checked and rolled back automatically if it breaks the site. |
Allow PHP execution is a separate switch under Controls, off by default, and works only in Development mode. With it, the agent can run PHP inside the site, which is how it can change things that have no tool of their own, such as menus and settings. PHP it runs is not snapshotted or rolled back, so switch it on only for the task that needs it.
The MCP tools tab lists all 21 tools with a switch for each, so you can turn off any tool you never want used. The content tools are controlled separately, by the scopes of the connection and the role of the account.
Working with the agent
Describe the result you want, and let the agent read before it writes. For example:
Read the active theme and tell me how the home page template is built. Don't change anything yet.
Add a "Blog" page template to the active theme that lists posts from the Blog category, 12 per page, with pagination. Check it at phone width with dev_render_page.
Build an app called "Opening hours": an admin screen to set the hours for each day, and a widget that shows them. Follow basehim.com/docs/ai-context, then activate it and check the logs.
The Events app was switched off after the last update. Find out why from the logs, fix it and activate it again.
List the posts without an excerpt and write one for each, under 160 characters. Show me the list before you save anything.
For apps and themes, point the agent at AI context for Basehim development: a compact page of Basehim's rules and real function names, so it doesn't guess. Prompts for building with AI has ready-made requests for common jobs.
Every change the agent makes appears under Basehim Dev Tools → Operations, with each file before and after, the checks that ran and the result.
How changes are kept safe
Every call goes through the same steps, in this order:
- Permission. The mode, the per-tool switch, the scopes of the connection and the role of the account behind it are checked on the server for every call.
- Confirmation. Deleting or renaming a file, uninstalling an app, running PHP and rolling back return a one-time token first. The agent must repeat the exact same call with the token, so a destructive step is never taken by accident. This is on by default.
- Where it may write. Only inside
content/apps/…andcontent/themes/…. Core files,.htaccess,.env, configuration, version-control folders, links and Dev Tools itself can never be changed. Secret files are never readable, and credentials are removed from logs and query results.
Every change to files is then handled as one operation:
- Snapshot. Each file it touches is copied, with its hash, before anything changes.
- Validate. PHP is syntax-checked and JSON is decoded before anything is written. If either fails, nothing changes.
- Apply. Each file is replaced in one step, so a visitor never sees half a file. A file that changed since the agent read it is not overwritten.
- Check. The site is started in a separate process, and the home page, the admin sign-in and the MCP endpoint are requested and compared with before the change.
- Keep or undo. If any check fails, every file of the operation is restored and verified by hash. Changes to several files are applied and undone together.
If an error shows up later, on a page the checks didn't visit, the fatal error sentinel restores the latest change to that app or theme on the first request that fails (within 30 minutes of the change). After three automatic rollbacks in an hour, Dev Tools stops further writes until you look.
A check that couldn't run is reported as skipped, never as passed.
When something goes wrong
In order of convenience; each one works when the ones before it don't:
- It usually fixes itself. A change that breaks the site is rolled back within the same call, or by the sentinel on the first failing request.
- Roll back. Ask the agent to call
dev_rollback(it needsdev:recoverand works in every mode), or open Operations → the operation → Restore snapshot in the admin. - The recovery endpoint. If the site, the admin and MCP are all down, open
https://your-site.com/devtools-recovery.php, enter your recovery key, and restore the last change or a specific operation. Quarantine there switches every tool off so the agent can't keep trying. It works without Basehim running. - File manager only. Rename the folder
content/apps/basehim-devtoolsto switch Dev Tools off completely; its settings and history are kept. The snapshots instorage/devtools/tx/can be copied back by hand.
Two things Dev Tools can't undo: changes made by PHP the agent ran, and database changes made by an app's own install or upgrade code. Take a backup first when either is involved.
Tool reference
| Group | Tools | Scope |
|---|---|---|
| Read and inspect | dev_status, dev_list_files, dev_read_file | dev:read |
| Search and diagnostics | dev_search_files, dev_read_log, dev_db_query, dev_render_page | dev:read |
| Change files | dev_write_file, dev_delete_file, dev_rename_file, dev_apply_changes | dev:write |
| Apps and themes | dev_app_list, dev_theme_list (dev:read); dev_app_lifecycle (dev:write) | As listed |
| Core | dev_list_routes, dev_opcache | dev:read; clearing OPcache needs Development mode |
| Testing | dev_php_lint, dev_health_check (dev:read); dev_run_php (dev:execute) | As listed |
| History and rollback | dev_operations (dev:read); dev_rollback (dev:recover) | As listed |
The core content tools (search_content, list_posts, create_post, update_page and the rest) are listed in MCP and AI agents.
Good practice
- Develop on a staging site. Use Development enabled on a copy of your site, then move the finished app or theme to the live site. Checks catch broken code, not code that works but does the wrong thing.
- Switch back to Disabled when you're done. Snapshots, history and recovery keep working.
- Give the least access. Only the scopes the task needs; Read-only when the agent only has to look; Allow PHP execution only for the task that needs it.
- Read what the agent changed. Every operation lists its files before and after. Review them as you would a colleague's work, especially anything that handles payments, personal data, uploads or accounts.
- Back up before uninstalling apps or running PHP. Neither is snapshotted.
- Never paste secrets into a chat. Nothing here needs your
.env, database password or recovery key. If a key ends up in a conversation, revoke it under API → Keys.
Dev Tools is an app like any other: its code runs in the same PHP process as Basehim. Its rules keep an honest agent within the limits you set, but it is not a sandbox for untrusted code.
Related
- Build with AI: three ways to work with an AI assistant, and a safe workflow
- Connect an AI assistant to your site
- MCP and AI agents
- AI context for Basehim development and Prompts for building with AI
- App development best practices
Leave a comment