git-worktree-precommit-hook-flutter-failure

git-worktree-precommit-hook-flutter-failure is a skill for Claude Code, Codex from divinevideo/divine-mobile. It costs 153 tokens per session (1,023 once invoked), scanned A, original, MPL-2.0.

A troubleshooting guide for Flutter projects whose Git pre-commit checks fail only when working in a Git worktree, a separate checkout linked to the same repository.

In plain words
What is it for?
Use it to diagnose and fix hooks that run flutter analyze or dart analyze during commits.
Why use it?
It explains how Git’s worktree environment variables can cause Flutter or Dart dependency resolution to fail inside the hook.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: mentions Claude Code; installed under .agents/ (shared by several agents).

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/divinevideo/divine-mobile/git-worktree-precommit-hook-flutter-failure
Any agent
npx skills add divinevideo/divine-mobile --skill git-worktree-precommit-hook-flutter-failure
Clone the repo
git clone --depth 1 https://github.com/divinevideo/divine-mobile

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for git-worktree-precommit-hook-flutter-failure

README.md
[![agentmods](https://agentmods.dev/badge/skills/divinevideo/divine-mobile/git-worktree-precommit-hook-flutter-failure.svg)](https://agentmods.dev/skills/divinevideo/divine-mobile/git-worktree-precommit-hook-flutter-failure)
Your own site
<a href="https://agentmods.dev/skills/divinevideo/divine-mobile/git-worktree-precommit-hook-flutter-failure"><img src="https://agentmods.dev/badge/skills/divinevideo/divine-mobile/git-worktree-precommit-hook-flutter-failure.svg" alt="Measured on agentmods" height="20"></a>
Per session 153 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,023 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00153 $0.01023
Opus 5 $0.00077 $0.00511
Sonnet 5 $0.00031 $0.00205
Haiku 4.5 $0.00015 $0.00102

Measured 3d ago against content hash 10c5120e4cdc, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

git-worktree-precommit-hook-flutter-failure scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/skills/git-worktree-precommit-hook-flutter-failure/SKILL.md · 104 lines

How it starts

The opening of the file, as written. The whole thing — 104 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Git Worktree Pre-Commit Hook Flutter Failure

Problem

When using git worktree for parallel development, pre-commit hooks that run flutter analyze fail during git commit even though:

  • Running flutter analyze directly in the worktree passes with no issues
  • Running the pre-commit hook script manually passes
  • The hook passes in the main repo checkout

Root Cause

Git sets GIT_DIR, GIT_INDEX_FILE, and GIT_WORK_TREE environment variables during hook execution. In a worktree, GIT_DIR points to .git/worktrees/<name>/ instead of .git/. When flutter analyze internally runs flutter pub get, pub chokes on this worktree-style GIT_DIR path and fails to resolve dependencies.

The failure is invisible when the hook uses 2>/dev/null on stderr — you only see "Resolving dependencies..." then the failure message, with the actual error suppressed.

Context / Trigger Conditions

  • Using git worktree add for parallel branch development
  • Pre-commit hook runs flutter analyze or dart analyze
  • Hook output shows "Resolving dependencies..." then immediately fails
  • No actual analysis errors are reported
  • The hook uses set -e (exit on error)
  • 2>/dev/null may hide the actual failure cause

Diagnosis

Reproduce the exact failure by simulating git's hook environment:

# This will FAIL (simulates hook execution in worktree)
GIT_DIR=/path/to/main/.git/worktrees/<name> \
  flutter analyze --no-fatal-infos 2>/dev/null

# This will PASS (without git env vars)
flutter analyze --no-fatal-infos

Solution

Add unset GIT_DIR GIT_INDEX_FILE GIT_WORK_TREE to the pre-commit hook after all git commands but before any flutter/dart commands.

#!/bin/bash
set -e

cd "$(git rev-parse --show-toplevel)/mobile"

# Git operations (these NEED the git env vars)
STAGED_DART_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.dart$' || true)

if [ -z "$STAGED_DART_FILES" ]; then
    echo "No Dart files staged, skipping checks"
    exit 0
fi

# Unset git env vars BEFORE running flutter/dart commands.
# Git sets these during hook execution, and flutter pub get
# (called internally by flutter analyze) chokes on worktree-style
# GIT_DIR paths.
unset GIT_DIR GIT_INDEX_FILE GIT_WORK_TREE

# Now flutter/dart commands work in both main repo and worktrees
dart format --output=none --set-exit-if-changed lib test
flutter analyze --no-fatal-infos

Read the full file on GitHub · 104 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 104 lines · 153 tokens per session scan A 10c5120e4cdc

Subscribe to this mod's changes

git-worktree-precommit-hook-flutter-failure is a skill published in the GitHub repository divinevideo/divine-mobile (265 stars, last pushed today), licensed MPL-2.0. It adds 153 tokens to every session and 1,023 once invoked, about $0.0008 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

git-advanced-workflows

Master advanced Git workflows including rebasing, cherry-picking, bisect, worktrees, and reflog to maintain clean history and recover from any situation. Use when managing complex Git histories, collaborating on feature branches, or troubleshooting repository issues.

wshobson/agents · 54 tokens

gsd-audit-fix

Autonomous audit-to-fix pipeline — find issues, classify, fix, test, commit.

open-gsd/gsd-core · 25 tokens

git-mastery

Advanced Git: rebase, bisect, reflog, cherry-pick, worktrees, LFS. Triggers: rebase, bisect, cherry-pick, reflog, force push, merge conflict, worktree.

softspark/ai-toolkit · 51 tokens

git-bisect-assistant

Automatically performs git bisect to identify the first bad commit that introduced a bug or failure. Use when debugging regressions, tracking down when a test started failing, or identifying which commit broke functionality. Handles flaky tests with retry logic and provides comprehensive reports with bisect logs and…

ArabelaTso/Skills-4-SE · 64 tokens

semantic-szz-analyzer

Identify bug-introducing commits using semantic analysis that extends traditional SZZ algorithm. Distinguishes semantic changes from refactorings or code movements using control-flow and data-flow similarity analysis. Use when analyzing bug-fix commits to trace back to bug-introducing changes, investigating software…

ArabelaTso/Skills-4-SE · 96 tokens

szz-bug-introducing-commit-identifier

Identifies bug-introducing commits using SZZ-style analysis based on bug-fixing commits, commit history, and code blame information. Use this skill when you need to trace bugs back to their origin, identify which commits introduced bugs, analyze bug-fix commits to find root causes, perform software repository mining…

ArabelaTso/Skills-4-SE · 121 tokens