Gemini CLI just got a major upgrade with version 0.26.0 (released January 28, 2026), introducing hooks as a default-enabled feature that lets developers inject custom logic straight into the AI agent’s lifecycle.
Hooks are synchronous scripts (shell commands) that run at key moments like BeforeTool, AfterAgent, BeforeAgent, SessionEnd and more, which allow you to inject guardrails, auto-context, and quality gates right into the agent’s loop with JSON I/O. No more begging the model to “please don’t use any” in every prompt π For us (TypeScript devs), this means saying goodbye to loose any types, lint disasters, and forgotten project context once and for all.
I recently put together a small, practical example repo to show how this works in a real TypeScript project: https://github.com/nazrul-kabir/gemini-cli-hooks-example
It turns Gemini into a strict, type-safe teammate that lints on write, loops until tests pass, blocks circular deps, and keeps barrel files in sync. Think of it as your personal code-review bot that runs before you even see the output.
Why Hooks Are a Big Deal for Devs Right Now
Before hooks, you’d stuff your .gemini/GEMINI.md with endless rules β and half the time the model would “forget” them anyway. Hooks make enforcement deterministic:
- Block bad patterns instantly (e.g., any without justification)
- Auto-fix lint/style issues on the fly
- Keep long sessions coherent with fresh context
- Run real tests and loop until green
From what I’ve seen in dev communities (Reddit threads, GitHub discussions, the official blog), people are loving this for exactly these reasons: turning flaky AI suggestions into production-ready PRs with way less manual cleanup.
My top Gemini CLI Hooks for TypeScript: Strict Typing, Tests & More
I ranked these based on what actually saves the most of my time and prevents the most headaches in a real TS project:
- strict-any (BeforeTool Hook)
Blocks any code with: any(unless properly justified with a disabled comment). Forces the AI to use proper interfaces, generics, or unions instead.
β In TS projects,anyis the fastest way to introduce subtle bugs that explode later. This hook catches it before the file hits disk. - lint-fix (BeforeTool Hook)
Automatically runseslint --fixon whatever the AI is about to write. Clean, consistent code lands every time, no more fixing missing semicolons or quote styles yourself.
β Huge for teams or monorepos where style consistency is sacred. Saves PR comments and keeps the focus on logic, not formatting. - test-loop (AfterAgent Hook)
After each response, it runsnpm test(or vitest/jest). If tests fail β deny the response & Gemini gets the error logs as fresh context and retries until green.
β This is the one that feels like magic. Turns one-shot generations into proper TDD cycles β perfect for implementing features or refactors without constant supervision. - check-cycles (BeforeTool Hook)
Usesmadge --circularto scan the updated import graph. If a circular dependency would be introduced β block the write and explain why.
β Circular deps are silent killers in large TS codebases (infinite loops, weird resolution issues). This prevents them proactively, especially valuable when the AI is adding new modules or utils. - sync-barrel (BeforeTool Hook)
When a new file is created in a directory, the hook checks if the barrel (index.ts) needs an export update. If missing β deny and prompt the AI to add it (or auto-append in some setups). β Keeps your imports clean and tree-shakable. No more forgetting to export new components/utils, the AI handles barrel maintenance for you.
Quick Start: Clone & Try in ~5 Minutes
git clone https://github.com/nazrul-kabir/gemini-cli-hooks-example.git
cd gemini-cli-hooks-example
npm install
gemini
Inside the session (first time):
/hooks enable-all
Now try a naughty prompt like: “Add a helper function that uses any for everything and skips types”
β Watch strict-any block it, lint-fix clean it up if allowed, and test-loop force fixes until tests pass. It’s satisfying.
The GEMINI.md also sets strict behavioral rules so the AI knows it’s in a strict, type-focused environment from the start.
Final Thoughts: Hooks Turn AI from Assistant to Reliable Teammate
For developers, Gemini CLI + these hooks shifts the experience from “cool but flaky” to “daily driver I trust.” You get AI speed without sacrificing the safety, maintainability, and team standards.
The repo is small, opinionated, and easy to fork/extend β add your own complexity checker, build notifier, or whatever fits your stack. If you tweak one or build something new (maybe auto-mock gen after interfaces?), submit a PR. The more shared examples we have, the better this ecosystem gets.
What’s the first hook you’d tweak or add for your projects? Drop a comment here or open an issue/PR on the repo. Let’s make Gemini-assisted coding way less chaotic β and way more fun. π
Happy coding (and hooking)!