ClaudeMods
☰
ZH-TW
● 0 人在線上 · 瀏覽 0 次
贊助提交作品
GitHub 儲存庫 · 發布者 nogu66

git-ops

Claude Mod(Claude Code 函式 hook 外掛):/git 會在提示列上方繪製可點選的面板,處理日常 git 操作——用按鈕選取分支(也可篩選後按 Enter,或按數字鍵),確認後就會切換;pull/push/fetch、全部暫存與提交也都有按鈕。不提供 force-push、reset 或 rebase。

已翻譯

關於這個 mod

git-ops

日本語

這是一個 Claude Mod(以函式 hook 建立的 Claude Code 外掛):/git 會在提示列上方的區域繪製可點選的 git 面板。用按鈕選取分支,確認後就會切換——也能執行 pull / push / fetch、全部暫存與提交,不必輸入 git 指令。

git-ops demo: /git opens the panel, pick a branch, confirm, checked out

Git · main (origin/main, ahead 4)              ↓ pull  ↑ push  fetch  refresh
▸ branches (12)     changes (13)
checkout: type to filter…            ← previous branch
[ feat/sandbox-rewrite ]       [ feature/seo-optimization ]
[ fix/sandbox-trailing-slash ] ● main (current)
[ feat/github-link-card ]      [ pensive-lamport ]

它會透過 $.process.run 呼叫一般的 git(傳入 argv 陣列,絕不使用 shell 字串),所以不需要自己的驗證或設定:目前工作目錄裡 git 已解析到的遠端、認證資料與上游追蹤設定,都會直接生效。

**刻意限制在安全的日常操作:**查看狀態、列出分支、切換分支(既有分支或新分支)、pull、push、fetch、全部暫存與提交。不提供 force-push、reset、rebase 或 clean——面板按鈕不該讓破壞性操作變成一鍵就能執行。

需求

  • 啟用 CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 的 Claude Code 建置版本。函式 hook 目前是 early-access,API 可能變更;不支援函式 hook 的建置版本會直接忽略這個外掛的 hooks 模組。
  • git 位於 PATH,且工作目錄是 git 儲存庫。
  • 終端機介面(在桌面與行動裝置上,面板會不加修改地經過終端機)。

安裝

/plugin marketplace add nogu66/claude-code
/plugin install git-ops@nogu-marketplace

也可以不安裝直接試用:

git clone https://github.com/nogu66/claude-code.git
cd claude-code/git-ops
claude --plugin-dir .        # .claude/settings.json here turns function hooks on

接著在任何 git 儲存庫中執行 /git。

面板

/git(或 /git show)會顯示面板;/git stop 會將它隱藏。

**先把焦點移到面板。**開啟面板後,按鍵仍會交給一般提示列——原本要輸入篩選框的文字或數字快速鍵不會送到面板。按 ctrl+x tab 聚焦面板;接著用 Tab/方向鍵移動,Enter 執行,Esc 返回提示列。只有終端機回報支援的位置才能使用滑鼠點選(也就是全螢幕版面)。

  • 標題列——左側顯示目前分支、上游與領先/落後狀態;右側顯示 ↓ pull、↑ push、fetch 和 refresh。它們會作用在目前分支既有的上游。
  • 分頁——branches (n) 與 changes (n)。同一時間只繪製一個主體,讓這一列保持精簡。
  • branches 分頁——用來快速切換到其他分支:
    • 本機分支依最近提交時間倒序排列,以並排的框線按鈕顯示;目前分支則改顯示為綠色的 ● name (current) 標籤;
    • 點選按鈕(或按 Tab 移到按鈕後按 Enter),也可以按對應的數字(1–9,前九個可切換的分支);
    • 篩選框:輸入內容會縮小清單(依序為完全符合、名稱前綴、/ 段落前綴、子字串),下方那一行會說明按 Enter 會做什麼——Enter → checkout <best match>,沒有符合項目時則為 Enter → create new branch <name>;
    • ← previous branch——執行 git checkout -;
    • 沒有確認就不會切換:上列每一種操作都會先開啟確認框(Check out <branch>? · [ OK ] / [ cancel ],快速鍵 y / n);有未提交的變更時也會顯示警告。
  • changes 分頁——左側是已暫存(綠色),右側是未暫存(黃色)和未追蹤;下方有 + stage all(git add -A)與提交輸入框(按 Enter 執行 git commit -m)。

切換分支會先詢問。其他操作——pull、push、fetch、全部暫存、提交——會在你點選或按下 Enter 的瞬間執行,效果完全等同於輸入 git 指令。push 會連到你的電腦之外的遠端端點。

文字子命令

使用同一套 argv 建構器,不開啟面板:

| Command | Runs | |---|---| | /git status | git status | | /git branch | git branch | | /git checkout <branch> | git checkout <branch> | | /git checkout -b <branch> | git checkout -b <branch> | | /git back | git checkout - | | /git pull · /git push · /git fetch | the same, no flags | | /git stage | git add -A | | /git commit <message> | git commit -m <message> | | /git help | prints this list |

文字子命令會立即執行,不經過確認步驟。

限制

  • 面板會在自己的操作完成或點選 refresh 後重新整理——其他地方執行 git 時不會重新整理(例如在 Bash 工具呼叫中執行)。
  • 面板狀態(篩選文字、提交草稿、開啟的分頁)只在這個工作階段的記憶體中保存。
  • 在篩選框輸入的分支名稱只防止開頭是 - 或空白(因此名稱不會被當成 git 旗標);其他無效內容由 git 自己拒絕。
  • 只顯示本機分支,最多顯示 60 個;沒有遠端分支選擇器、合併、rebase、stash、log 或 diff 檢視。
  • 它會和其他在提示列上方區域繪製內容的 mod 共用這一列;透過 next(e) 串接,所以可以堆疊顯示,但這種組合尚未測試。

開發

bun test                  # pure logic in hooks/lib/gitops.ts — no $ or UI to mock
claude plugin validate .  # lists the hooked events and $ calls
  • hooks/register.tsx——唯一接觸 $ 的檔案:註冊 /git、執行 git、繪製 AbovePrompt 面板,並保存記憶體中的 UI 狀態。
  • hooks/lib/gitops.ts——純函式:命令解析、git argv 建構器、分支/狀態輸出解析、分支篩選、Enter 目標判斷與欄位版面配置。
  • tests/gitops.test.ts——上述功能的測試。

如需精確型別,請在啟用函式 hook 的工作階段執行 /plugin-types;它會寫入 .claude/types/claude-code.d.ts。

授權

MIT

安裝

請先查看作者 README,確認 marketplace 與外掛名稱;指令可能隨儲存庫結構而變動。

claude plugin marketplace add nogu66/claude-code
claude plugin install git-ops
原文 / README

git-ops

日本語

A Claude Mod (a Claude Code plugin built on function hooks): /git draws a clickable git panel in the band above the prompt. Pick a branch with a button, confirm, and it checks out — plus pull / push / fetch, stage-all and commit, without typing a git command.

git-ops demo: /git opens the panel, pick a branch, confirm, checked out

Git · main (origin/main, ahead 4)              ↓ pull  ↑ push  fetch  refresh
▸ branches (12)     changes (13)
checkout: type to filter…            ← previous branch
[ feat/sandbox-rewrite ]       [ feature/seo-optimization ]
[ fix/sandbox-trailing-slash ] ● main (current)
[ feat/github-link-card ]      [ pensive-lamport ]

It shells out to plain git through $.process.run (an argv array, never a shell string), so it needs no auth or config of its own: whatever git already resolves in the current working directory — remotes, credentials, upstream tracking — is what runs.

Deliberately limited to safe, everyday operations: status, branch listing, checkout (existing or new branch), pull, push, fetch, stage-all, commit. No force-push, reset, rebase or clean — a panel button shouldn't put a destructive operation one click away.

Requirements

  • A Claude Code build with function hooks, enabled with CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1. Function hooks are early-access and their API can change; builds without them simply ignore this plugin's hooks module.
  • git on PATH, and a git repository as the working directory.
  • The terminal surface (the panel passes through untouched on desktop/mobile).

Install

/plugin marketplace add nogu66/claude-code
/plugin install git-ops@nogu-marketplace

Or try it without installing:

git clone https://github.com/nogu66/claude-code.git
cd claude-code/git-ops
claude --plugin-dir .        # .claude/settings.json here turns function hooks on

Then run /git inside any git repository.

The panel

/git (or /git show) shows the panel; /git stop hides it.

Move the keys into the panel first. Opening the panel leaves your keystrokes with the normal prompt — text meant for the filter box, or a digit hotkey, never reaches the panel. Press ctrl+x tab to focus it; then Tab/arrows move, Enter presses, Esc returns to the prompt. Mouse clicks only work where the terminal reports them (the fullscreen layout).

  • Title row — current branch, upstream and ahead/behind on the left; ↓ pull, ↑ push, fetch, refresh on the right. They act on the current branch's existing upstream.
  • Tabs — branches (n) and changes (n). Only one body is drawn at a time, which keeps the band short.
  • branches tab — built for getting to another branch quickly:
    • local branches, most recently committed-to first, as framed buttons in side-by-side columns; the current branch is a green ● name (current) label instead;
    • click a button (or Tab to it and press Enter), or press its digit (1–9, the first nine switchable branches);
    • a filter box: typing narrows the list (exact match, then name prefix, then /-segment prefix, then substring), and the line beneath says what Enter will do — Enter → checkout <best match>, or Enter → create new branch <name> when nothing matches;
    • ← previous branch — git checkout -;
    • nothing switches without an OK: every one of the above opens a confirmation first (Check out <branch>? · [ OK ] / [ cancel ], hotkeys y / n), with a warning when there are uncommitted changes.
  • changes tab — staged (green) on the left, unstaged (yellow) and untracked on the right; below them + stage all (git add -A) and a commit box (Enter runs git commit -m).

Checkout asks first. Everything else — pull, push, fetch, stage all, commit — runs the moment you click or press Enter, exactly as if you had typed the git command. push reaches outside your machine.

Text subcommands

The same argv builders, without the panel:

| Command | Runs | |---|---| | /git status | git status | | /git branch | git branch | | /git checkout <branch> | git checkout <branch> | | /git checkout -b <branch> | git checkout -b <branch> | | /git back | git checkout - | | /git pull · /git push · /git fetch | the same, no flags | | /git stage | git add -A | | /git commit <message> | git commit -m <message> | | /git help | prints this list |

Text subcommands run immediately, without the confirmation step.

Limitations

  • The panel refreshes after its own actions or a refresh click — not when git runs elsewhere (for instance in a Bash tool call).
  • Panel state (filter text, commit draft, open tab) lives in memory for the session only.
  • Branch names typed into the filter box are only guarded against a leading - and whitespace (so a name can't be read as a git flag); git itself rejects anything else invalid.
  • Local branches only, at most 60 shown; no remote-branch picker, merge, rebase, stash, log or diff view.
  • It shares the above-prompt band with any other mod that draws there; it chains next(e) so they stack, but that combination isn't tested.

Development

bun test                  # pure logic in hooks/lib/gitops.ts — no $ or UI to mock
claude plugin validate .  # lists the hooked events and $ calls
  • hooks/register.tsx — the only file that touches $: registers /git, runs git, draws the AbovePrompt panel, and holds its in-memory UI state.
  • hooks/lib/gitops.ts — pure functions: command parsing, git argv builders, branch/status output parsing, branch filtering and the Enter-target decision, column layout.
  • tests/gitops.test.ts — tests for the above.

For exact types, run /plugin-types in a session with function hooks on; it writes .claude/types/claude-code.d.ts.

License

MIT

更多類似作品