Automate formatting, linting, auditing, and notifications using lifecycle triggers.
Lifecycle hooks allow you to execute shell scripts automatically before or after specific agent events (such as after editing a file, compiling the project, or finishing a task loop). This helps automate formatting, testing, and team notifications without manual intervention.
You can subscribe scripts to the following lifecycle events:
| Event Name | Trigger Condition | Common Use Case |
|---|---|---|
on_edit_complete | Fires immediately after the agent modifies any file. | Run Prettier/Linter on the edited files. |
on_agent_complete | Fires when the agent achieves its task goal successfully. | Run a build, run test coverage, or commit changes. |
pre_execution_audit | Fires before the agent writes changes. | Scan diff files for open keys or credentials. |
on_command_fail | Fires if a command executed in the terminal fails. | Notify on slack or generate diagnostic dumps. |
.m0x/hooks.json)To enable hooks, create a folder named .m0x/ in the root of your workspace, and add a hooks.json file inside it:
{
"hooks": [
{
"event": "on_edit_complete",
"command": "npx prettier --write",
"args": ["${file_path}"]
},
{
"event": "on_agent_complete",
"command": "git add ${workspace_root} && git commit -m 'chore: updates by CoderX agent'"
}
]
}When a hook is executed, CoderX injects context-specific variables that you can reference in your command arguments:
${file_path}: The absolute path of the file that was modified (available in on_edit_complete).${workspace_root}: The root path of the active workspace.${task_goal}: The string description of the agent's objective.${exit_code}: The return code of the failed command (available in on_command_fail).To ensure the agent only produces syntactically correct code that passes lint requirements before merging:
Create a folder named .m0x in your workspace root.
Create .m0x/hooks.json and add a script for on_edit_complete to run npm run lint -- --fix on modified files.
Run a task with the agent. You will see the linter running in the background console after each file modification, keeping your workspace clean.