Hooks
AIRGAP Assistant event hook configuration and usage
Overview
Hooks allow you to define commands or scripts that automatically execute when specific events occur in AIRGAP Assistant. By automating repetitive post-processing tasks, you can improve workflow efficiency.
Supported Event Types
| Event | Trigger Timing | Example Use |
|---|---|---|
onSave | After the AI saves a file | Run formatter, lint check |
onFileCreate | After the AI creates a new file | Add file header, update index |
onCommit | After a checkpoint commit is created | Update changelog |
onTaskStart | When an AI task starts | Load environment variables, initialize state |
onTaskEnd | When an AI task completes | Result logging, cleanup tasks |
How to Configure Hooks
Add a ## Hooks section within your .airgaprules file to define hooks.
# .airgaprules
## Hooks
### onSave
- If the saved file has a .ts or .tsx extension, run `npx prettier --write`.
- If the saved file has a .py extension, run the `black` formatter.
### onFileCreate
- Add the project license header to new TypeScript files.
- When creating a component file, also generate a test file template in the same directory.
### onTaskEnd
- Record the performed work in CHANGELOG.md.
Hook Execution Behavior
Commands defined in hooks are automatically suggested by the AI when the corresponding event is detected. If auto-approve is not configured, user confirmation is requested before each hook execution.
AI: Saved file utils.ts.
Run prettier per onSave hook? [Approve/Reject]
Tip: If you allow command execution in Auto Approve settings, hooks will run without separate confirmation. It is recommended to enable auto-approve only for safe commands (formatters, linters, etc.).
Hook Usage Examples
Code Quality Automation
### onSave
- Run code checks and auto-fix fixable issues.
- Run TypeScript type checking and report type errors.
Project Cleanup
### onTaskEnd
- Clean up generated temporary files.
- Output a list and summary of changed files.
Security Considerations
Keep the following in mind when using hooks in air-gapped environments:
- Verify that commands registered in hooks do not perform unintended actions.
- Do not register commands that modify system files or require administrator privileges.
- Always review the hook contents of
.airgaprulesfiles obtained from external sources before using them.
Caution: Using rule files from untrusted sources as-is may result in unintended command execution. Always verify hook contents yourself.
Related Documentation
- Rules - AI behavioral rule settings
- Workflows - Automation workflows
- Auto Approve - Auto-approval settings