Hooks
Intercept and customize Tabnine CLI behavior at key lifecycle points.
What are Hooks?
Hooks are scripts that run automatically at specific points during Tabnine CLI execution, allowing you to customize behavior, add logging, enforce policies, or integrate with external tools.
Hook Types
Tabnine CLI supports hooks at various lifecycle events:
before-agent - Before agent processing starts
after-agent - After agent completes
before-model - Before model request
after-model - After model response
before-tool - Before tool execution
after-tool - After tool completes
on-error - When errors occur
Enabling Hooks
Hooks must be explicitly enabled in settings:
{
"hooks": {
"enabled": true
}
}Creating Hooks
Place executable scripts in .tabnine/hooks/:. For example, add the following file: .tabnine/hooks/before-tool.sh
In order to make it executable, run the chmod command:
Hook Context
Hooks receive context via environment variables:
TABNINE_CLI=1- Running in Tabnine CLITABNINE_TOOL_NAME- Tool being executed (for tool hooks)TABNINE_MODEL- Current model nameAdditional variables depending on hook type
Use Cases
Logging
Policy Enforcement
External Integration
Best Practices:
Keep hooks fast – Hooks run synchronously and can slow down the CLI if they take too long.
Handle errors gracefully – A non-zero exit code from a hook will block the associated action. Make sure to handle failures and return appropriate exit codes.
Log debugging info – Hooks run silently unless they output; include useful logging to help debugging.
test thoroughly – Broken hooks can break Tabnine CLI. Test hooks in a safe environment before deploying to production.
Troubleshooting
There are some common problems that come up with hooks that have standard troubleshooting flows:
Hook not running
Check these items:
Verify hooks are enabled: Use
/hooks listto confirm that hooks are activated in the settings.Ensure the script is executable:
chmod +x .tabnine/hooks/hook-name.shVerify the script name matches the expected hook type:
Ensure the file name corresponds to the hook lifecycle event you expect (for example, before-tool.sh).
Check for syntax errors: Run the script manually to see any runtime or syntax errors.
Hook blocking execution
Cause: Hook returned non-zero exit code
Solution: Fix the hook script or temporarily disable hooks (for example via /hooks disable).
Security Note:
Hooks execute with your user permissions. Only use hooks from trusted sources.
See Also
Last updated
Was this helpful?
