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 CLI

  • TABNINE_TOOL_NAME - Tool being executed (for tool hooks)

  • TABNINE_MODEL - Current model name

  • Additional variables depending on hook type

Use Cases

Logging

Policy Enforcement

External Integration

circle-info

Best Practices:

  1. Keep hooks fast – Hooks run synchronously and can slow down the CLI if they take too long.

  2. 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.

  3. Log debugging info – Hooks run silently unless they output; include useful logging to help debugging.

  4. 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

chevron-rightCheck these items:hashtag
  • Verify hooks are enabled: Use /hooks list to confirm that hooks are activated in the settings.

  • Ensure the script is executable: chmod +x .tabnine/hooks/hook-name.sh

  • Verify 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).

triangle-exclamation

See Also

Last updated

Was this helpful?