Cleanup Github Worktree logo

Cleanup Github Worktree

OrganizationPopular
TencentBlueKing
cleanup-github-worktree

清理长时间未使用的 git worktree(GitHub 版)。仅在用户明确要求清理 worktree 时使用,不自动触发。 关键词:清理 worktree、删除 worktree、移除旧分支、worktree 回收。

Overview

PublisherTencentBlueKing
Repositorybk-ci
Skill namecleanup-github-worktree
Stars
2.5K
Forks
524
Bundled files
2
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by TencentBlueKing on GitHub. Read the source before you install it.

Installation

Install the Cleanup Github Worktree AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/TencentBlueKing/bk-ci.git /tmp/bk-ci
mkdir -p .claude/skills
cp -r /tmp/bk-ci/ai/skills/cleanup-github-worktree .claude/skills/cleanup-github-worktree
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Cleanup Github Worktree in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Cleanup Github Worktree on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Cleanup Github Worktree is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

清理过期 Worktree(GitHub 版)

手动触发:当用户明确要求清理、删除或回收长时间未使用的 worktree 时执行。

前置约束

必须在 master 上执行:执行前 git branch --show-current;若不是 master,中止并提示用户切换。

工作流

Step 1: 选择清理时间范围

使用 AskQuestion 让用户选择阈值:

  • 提示:选择清理阈值:超过多久未使用的 worktree 将被清理?
  • 选项:
    • 1 周(对应 7 天)
    • 2 周(对应 14 天)
    • 1 个月(对应 30 天)

将用户选择映射为天数:

选项天数
1 周7
2 周14
1 个月30

Step 2: 预览过期 Worktree

运行清理脚本,输出候选分支名列表(每行一个分支名),不执行删除。

根据操作系统选择脚本(通过用户信息中的 OS Version 判断):

Windows(PowerShell):

powershell
powershell -File .cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.ps1 -Days <天数>

macOS / Linux(Bash):

bash
bash .cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.sh -d <天数>

将脚本输出的分支名列表展示给用户。如果没有找到过期 worktree,告知用户并结束。

Step 3: 用户确认

使用 AskQuestion 让用户确认是否继续:

  • 提示:以上 <N> 个 worktree 将被清理(关闭 GitHub Issue、移除 worktree、删除本地分支),是否继续?
  • 选项:
    • 确认清理
    • 取消

用户选择取消时,结束工作流。

Step 4: 批量执行 close-github-worktree-done

对 Step 2 识别出的每一个候选分支,以该分支名作为目标分支,执行 close-github-worktree-done skill 的 Step 1 ~ Step 5 完整流程(跳过其 Step 0 的交互选择)。

  • 批量场景下,Step 3 关闭 Issue 默认可直接对 open 状态执行关闭(state=closed, state_reason=completed),无需逐个再次 AskQuestion;已 closed 的跳过。
  • 有未提交变更的分支:按 close-github-worktree-done Step 2 规则跳过,在最终报告中标记为"跳过(有未提交变更)"。
  • 单个分支处理失败不中断整批,继续处理下一个。

Step 5: 汇总报告

向用户展示清理结果摘要,包含每个分支的处理状态:

分支名GitHub Issueworktree本地分支备注
bug-12994✅ closed✅ 已移除✅ 已删除
feat-11524⏭ 跳过✅ 已移除✅ 已删除分支名无 issue 号
pref-12948跳过(有未提交变更)

脚本说明

脚本系统路径
cleanup-worktree.ps1Windows.cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.ps1
cleanup-worktree.shmacOS/Linux.cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.sh

脚本职责:

  1. 通过 git worktree list --porcelain 获取所有 worktree
  2. 跳过主 worktree(第一个)和 bare 条目
  3. 通过 git log -1 --format=%ct <branch> 获取分支最后一次 commit 时间;detached HEAD 时回退到目录修改时间
  4. 筛选超出阈值的条目,仅输出候选分支名列表(每行一个),供本 skill Step 2 解析使用

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Cleanup Github Worktree AI skill do?

清理长时间未使用的 git worktree(GitHub 版)。仅在用户明确要求清理 worktree 时使用,不自动触发。 关键词:清理 worktree、删除 worktree、移除旧分支、worktree 回收。

Why use Cleanup Github Worktree on TypingMind?

Because you install it once and use it with any model. Cleanup Github Worktree is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Cleanup Github Worktree in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/TencentBlueKing/bk-ci/tree/master/ai/skills/cleanup-github-worktree. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Cleanup Github Worktree?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Cleanup Github Worktree?

As many as you like. As long as a model supports skills, you can use Cleanup Github Worktree with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Cleanup Github Worktree AI skill free?

It is published on GitHub by TencentBlueKing. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇