Skip to content
TheBushidoCollective avatar

hashi-gemini-cli

Bridge that runs Han's validation hooks inside Gemini CLI by translating its events into Han hook calls.

CCM score
54 of 100
GitHub stars
201
View on GitHub

Own this plugin? Claim it

What it does

  • Adds a hook component (hooks.json) that maps Gemini CLI events to Han PreToolUse, PostToolUse, and Stop hooks
  • Covers SessionStart, BeforeAgent, BeforeTool, AfterTool, AfterAgent, SessionEnd, and PreCompress, with failed validation returned as a deny or block decision
  • Enforces lint, typecheck, and test hooks after file edits, and forces another agent turn when project-wide checks fail
  • Designed for teams that already use Han plugins with Claude Code and want the same validation in Gemini CLI

Bridge plugin that enables Han's hook ecosystem (validation, context injection, orchestration) to work with Gemini CLI by translating Gemini CLI events into Han hook invocations.

Add marketplace

/plugin marketplace add TheBushidoCollective/han

Run it inside Claude Code once, then install the plugin below.

Install

/plugin install hashi-gemini-cli@han

Run it inside Claude Code after adding the marketplace.

Files

Discovered from source

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.1.0] - 2026-08-12

Added

  • catalog and track metrics from every harness, and bridge omp (#109) (a7a02ccc)
  • add SessionEnd, deny-based AfterTool feedback (97d942c4)

Fixed

  • live-test fixes for opencode and gemini-cli (2fafd014)
  • locate marketplace in installed Claude Code marketplaces (60efae09)

Other

  • live-test results and current setup for all bridges (62accccd)

[0.1.0] - 2026-07-19

Added

  • add SessionEnd, deny-based AfterTool feedback (97d942c4)

Fixed

  • live-test fixes for opencode and gemini-cli (2fafd014)
  • locate marketplace in installed Claude Code marketplaces (60efae09)

Other

  • live-test results and current setup for all bridges (62accccd)

[Unreleased]

Fixed

  • wrap gemini-hooks.json in a top-level hooks object; Gemini CLI 0.51 rejected the bare event map ("'hooks' property must be an object") and the extension loaded with zero hooks
  • locate the marketplace in installed Claude Code marketplaces (~/.claude/plugins/marketplaces/) so discovery works in any project

[0.1.0] - 2026-07-19

Added

  • add SessionEnd, deny-based AfterTool feedback (97d942c4)

[0.1.0] - 2026-03-02

Added

  • update CC feature support to 2.1.63, browse UI refactoring, and Rust GraphQL migration (8caf0ffe)
  • backend rearchitecture — Rust crates replace han-native (#70) (877601e0)

[0.1.0] - 2026-02-17

Added

  • backend rearchitecture — Rust crates replace han-native (#70) (877601e0)

[0.1.0] - 2026-02-09

Added

  • add Gemini CLI bridge plugin for Han hook ecosystem (#66) (b24c623e)

Fixed

  • resolve biome lint errors in bridge plugins and gitignore dist (e80d2d3e)

Other

  • apply biome formatting to bridge plugin sources (f792a13e)

[0.1.0] - 2026-02-09

Added

  • add Gemini CLI bridge plugin for Han hook ecosystem (#66) (b24c623e)

Fixed

  • resolve biome lint errors in bridge plugins and gitignore dist (e80d2d3e)

[0.1.0] - 2026-02-08

Added

  • Initial Gemini CLI bridge plugin for Han hook ecosystem

Readme

Han Bridge for Gemini CLI

Bridge extension that brings Han's full plugin ecosystem to Gemini CLI — validation hooks, core guidelines, 400+ skills, and 25 agent disciplines.

What This Does

Han plugins define validation hooks, specialized skills, and agent disciplines that run during Claude Code sessions. This bridge makes the entire ecosystem work in Gemini CLI:

  1. Hooks — PreToolUse, PostToolUse, and Stop validation (biome, eslint, tsc, etc.) with parallel execution
  2. Guidelines — Core principles (professional honesty, no excuses, skill selection) injected via GEMINI.md
  3. Datetime — Current time injected on every agent turn via BeforeAgent
  4. Events — Unified JSONL logging with harness: "gemini-cli" for Browse UI visibility

Coverage Matrix

Claude Code HookGemini CLI EquivalentStatus
PostToolUseAfterToolImplemented (failures return decision:"deny" with the errors as reason, hiding the tool result)
PreToolUseBeforeToolImplemented
StopAfterAgentImplemented
SessionStartSessionStartImplemented
SessionEndSessionEndImplemented (advisory; runs SessionEnd Han hooks if any, then flushes the event log)
UserPromptSubmitBeforeAgentImplemented
PreCompactPreCompressImplemented
SubagentStart/Stop—Not available
Permission denialBeforeTool decision:"deny"Implemented
MCP tool events—Not available
—BeforeModel / AfterModelIntentionally unsupported (Han has no model-level hooks)
—BeforeToolSelectionIntentionally unsupported (Han has no tool-selection hooks)

Plugin discovery reads the current enabledPlugins boolean map (what han plugin install writes) as well as the legacy plugins object map from Claude Code settings, and resolves marketplace source paths relative to the marketplace root.

Validation Flow

AfterTool (Primary Validation Path)

When the agent edits a file:

Agent edits src/app.ts via write_file
  -> Gemini CLI fires AfterTool hook
  -> Bridge maps write_file -> Write (Claude Code name)
  -> Matches PostToolUse hooks (biome, eslint, tsc)
  -> Runs hooks in parallel
  -> On failure: returns decision:"deny" with validation errors as reason
  -> Tool result is hidden; the agent sees the errors instead and fixes them

AfterAgent (Stop Validation)

When the agent finishes a turn:

Agent signals completion
  -> Gemini CLI fires AfterAgent hook
  -> Bridge runs Stop hooks (full project lint, typecheck, tests)
  -> If failures: returns decision:"block" to force continuation
  -> Agent gets another turn to fix project-wide issues

BeforeTool (Pre-Execution Gates)

Before a tool executes:

Agent about to run a tool
  -> Gemini CLI fires BeforeTool hook
  -> Bridge matches PreToolUse hooks
  -> If any hook rejects: returns decision:"deny"
  -> Tool execution is blocked

Setup

Prerequisites

Han plugins must be installed:

curl -fsSL https://han.guru/install.sh | bash
han plugin install --auto

Bun is required for running the bridge scripts.

Install the Extension

Use the install script to set up the Gemini CLI extension:

# From the han repo
bash plugins/bridges/gemini-cli/install.sh

# Or clone and install
git clone --depth 1 https://github.com/TheBushidoCollective/han.git /tmp/han
bash /tmp/han/plugins/bridges/gemini-cli/install.sh /tmp/han/plugins/bridges/gemini-cli
rm -rf /tmp/han

The install script copies the extension to ~/.gemini/extensions/han/ and sets up the correct hooks configuration for Gemini CLI.

Verify installation:

gemini extensions list
# Should show "han" extension

Note: The source repository stores Gemini CLI hooks in gemini-hooks.json (not hooks/hooks.json) to avoid conflicts with Claude Code's plugin validation. The install script places them at the correct hooks/hooks.json path that Gemini CLI expects.

Architecture

Gemini CLI Hook System
  |
  |-- SessionStart ──────────────> Plugin discovery + coordinator start
  |     hooks/hooks.json            -> systemMessage with capability summary
  |
  |-- BeforeAgent ───────────────> Datetime injection
  |     hooks/hooks.json            -> additionalContext with current time
  |
  |-- BeforeTool (matcher: *) ───> PreToolUse hooks
  |     hooks/hooks.json            -> decision:"deny" if validation fails
  |
  |-- AfterTool (matcher: write_file|replace) ──> PostToolUse hooks
  |     hooks/hooks.json            -> decision:"deny" + reason with validation errors
  |
  |-- AfterAgent ────────────────> Stop hooks (full project validation)
  |     hooks/hooks.json            -> decision:"block" if failures
  |
  |-- SessionEnd ────────────────> SessionEnd hooks (if any) + event log flush
  |     hooks/hooks.json            -> advisory, CLI does not wait
  |
  |-- GEMINI.md ─────────────────> Core guidelines context
  |     (loaded automatically)       (professional honesty, no excuses, etc.)
  |
  |-- JSONL event logger ────────> Browse UI visibility
        ~/.han/gemini-cli/projects/   (harness="gemini-cli")

Bridge Internals (src/):
  bridge.ts        Entry point (stdin JSON → handler → stdout JSON)
  discovery.ts     Read settings + marketplace + resolve plugin paths
  matcher.ts       Filter by tool name, file globs, dirsWith
  executor.ts      Spawn hook commands as parallel promises
  formatter.ts     Structure results as Gemini CLI JSON responses
  cache.ts         Content-hash caching (SHA-256)
  context.ts       Session context + datetime injection
  skills.ts        Skill discovery (counting)
  disciplines.ts   Discipline discovery (counting)
  events.ts        JSONL event logger (harness="gemini-cli")
  types.ts         Gemini CLI + Han type definitions

How Plugins Stay Compatible

Han plugins don't need modification to work with Gemini CLI. The bridge reads the same han-plugin.yml files that Claude Code uses:

# This config works in Claude Code, OpenCode, AND Gemini CLI
hooks:
  lint-async:
    event: PostToolUse
    command: "npx -y @biomejs/biome check --write ${HAN_FILES}"
    tool_filter: [Edit, Write, NotebookEdit]
    file_filter: ["**/*.{js,jsx,ts,tsx}"]
    dirs_with: ["biome.json"]

The difference is in who executes the hook:

  • Claude Code: Reads hooks.json, calls han hook run via shell
  • OpenCode: Bridge reads han-plugin.yml, runs command as JS promise
  • Gemini CLI: Bridge reads han-plugin.yml, runs command as child process, returns JSON

Same hook definition. Same validation. Different runtime.

Gemini CLI Hook Protocol

Gemini CLI hooks communicate via stdin/stdout JSON:

  • Input (stdin): { "tool_name": "write_file", "tool_input": { "path": "src/app.ts", ... } }
  • Output (stdout): { "decision": "allow" } or { "decision": "deny", "reason": "Validation errors..." }
  • Logging (stderr): All debug output goes to stderr (stdout is reserved for JSON)

Exit codes:

  • 0: Success — Gemini CLI parses stdout JSON
  • 2: Critical block — Gemini CLI aborts the action
  • Other: Warning — Gemini CLI continues unchanged

Event Logging

The bridge writes Han-format JSONL events to ~/.han/gemini-cli/projects/. Each event includes harness: "gemini-cli" to distinguish Gemini CLI sessions from Claude Code and OpenCode sessions.

On SessionStart, the bridge launches the Han coordinator in the background with han coordinator ensure --background. The coordinator discovers ~/.han/<harness>/projects on disk, watches it, and indexes each <sessionId>-han.jsonl into SQLite as a session attributed to that harness, which is what makes those sessions visible in the Browse UI. There is no registration step and no --watch-path flag. The coordinator enumerates those roots when it starts, so the very first session from a newly installed bridge is picked up at the next coordinator start or scan rather than live. Every session after that is live.

Remaining Gaps

  • MCP tool events: Gemini CLI doesn't fire AfterTool for MCP server tool calls. Validation only runs for built-in tools.
  • Subagent hooks: No Gemini CLI equivalent for SubagentStart/SubagentStop.
  • Persistent state: Each hook invocation is a separate process. Plugin discovery runs on every invocation (fast but not cached across invocations).
  • Session correlation across processes: Gemini CLI puts no session id on the hook payload, and nothing in this repo establishes that it exports GEMINI_SESSION_ID. The bridge reads that variable in exactly one place and memoizes the result, so a single process can no longer scatter its events across several ids. It cannot fix the cross-process case: Gemini CLI runs the bridge as a fresh process per hook event, so if the variable is unset, every hook event still becomes its own session. Closing this needs a real session id from the host.

Development

# From the han repo root
cd plugins/bridges/gemini-cli

# The bridge uses TypeScript directly (Bun handles it)
# No build step required

License

Apache-2.0

Details

Marketplace
TheBushidoCollective/han
Source
plugins/bridges/gemini-cli
Category
Integration
Keywords
gemini-cli, gemini, bridge, hooks, compatibility, claude-code, validation
Listed since
Apr 7, 2026

More from TheBushidoCollective/han

All 340

Similar to hashi-gemini-cli

More Developer Tools