Copilot CLI hooks fail on Windows: command runs under PowerShell, which can't execute te-hook

Aperta
#204 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@sykuang ci sta già lavorando.

Dal 11/11/2026.

  • #206 di @sykuang — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
github, powershell, python

Direzione di ricerca

Read plugin/hooks/copilot-hooks.json and the existing Windows handling in the Codex manifest. Check how Copilot hook commands are configured for bash and powershell, then verify the proposed shell lookup against the Windows environments in the report. Done means all six hooks run without errors on Windows and te status shows the repository.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

On Windows, every Copilot CLI hook from the plugin fails with exit code 1, so TokenEconomizer never runs (no state under ~/.tokeneconomizer/repos/...).

plugin/hooks/copilot-hooks.json uses only command:

"command": "\"${PLUGIN_ROOT}/scripts/te-hook\" --host copilot"

Per the Copilot hooks reference, command is copied to both bash and powershell. On Windows, Copilot CLI runs the powershell variant, and PowerShell can't execute the extensionless POSIX script te-hook (Cannot run a document in the middle of a pipeline: ...\plugin\scripts\te-hook).

docs/PLUGIN.md already notes that Copilot CLI on Windows is untested, so this may be expected. I'm filing it with a verified workaround.

Environment

  • Windows 11, Copilot CLI 1.0.107 (standalone copilot.exe)
  • Git for Windows (C:\Program Files\Git); its bin\ is not on the machine PATH by default (only Git\cmd)
  • Python 3.15 via the Python install manager
  • Plugin installed from a local clone at main (marketplace add + copilot plugin install tokeneconomizer@tokeneconomizer)

Repro

  1. Install the plugin on Windows as above.
  2. In any git repo: copilot -p "Reply with just: ok"
  3. ~/.copilot/logs/process-*.log shows, once per hook:
    [ERROR] [rust:hooks] Hook from "tokeneconomizer@tokeneconomizer" execution failed: Error: Hook command failed with code 1

What I tested

Variant Normal user PATH PATH with Git bin on it
Original command ❌ 4 hook failures ❌ 4 hook failures
"command": "sh \"${PLUGIN_ROOT}/scripts/te-hook\" ..." ❌ (sh not on PATH) ✅
Split bash + powershell with sh lookup (below) ✅ ✅

A plain sh prefix isn't enough, because Git for Windows doesn't put sh.exe on PATH by default. Deriving it from git.exe alone isn't enough either: some hosts bundle a Git whose sh.exe is under usr\bin instead of bin.

Suggested fix

Keep the POSIX command as bash, and add a powershell entry that locates sh.exe (PATH first, then next to git.exe):

{
  "type": "command",
  "bash": "\"${PLUGIN_ROOT}/scripts/te-hook\" --host copilot",
  "powershell": "$s=(Get-Command sh.exe -ErrorAction SilentlyContinue).Source; if(-not $s){$g=Split-Path (Split-Path (Get-Command git.exe -ErrorAction SilentlyContinue).Source); $s=@(\"$g\\bin\\sh.exe\",\"$g\\usr\\bin\\sh.exe\") | Where-Object {Test-Path $_} | Select-Object -First 1}; & $s \"${PLUGIN_ROOT}/scripts/te-hook\" --host copilot",
  "timeoutSec": 30
}

With this applied to all 6 events, I get no hook errors, te status shows the repo, and toolprune records the catalog. A small te-hook.ps1 wrapper would be cleaner than the inline one-liner. The Codex manifest's commandWindows handling looks like the equivalent of this for Codex.

Possibly related: #167 (te launcher on Windows/Git Bash).

Lingua principale
Python
Stelle
5.6k
Fork
344
Merge medio
17h 41m
PR unite (30g)
73

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/TokenEconomizer

Tutte le issue di microsoft/TokenEconomizer

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.