# Hooks using git bash on windows

**URL:** <https://forum.buildkite.community/t/hooks-using-git-bash-on-windows/2049>\
**Category:** General\
**Created:** [May 20, 2022, 7:36pm UTC](https://forum.buildkite.community/t/hooks-using-git-bash-on-windows/2049 "2022-05-20T19:36:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pragmaxwell](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@pragmaxwell](https://forum.buildkite.community/u/pragmaxwell)\
**Post date:** [May 20, 2022, 7:36pm UTC](https://forum.buildkite.community/t/hooks-using-git-bash-on-windows/2049/1 "2022-05-20T19:36:20Z")

</div>

Hi there, we have our windows boxes set to use `shell="C:\Program Files\Git\bin\bash.exe"` in their buildkite-agent.cfg.

…we ALSO have a `command.bat` that runs the command with `"%ProgramFiles%\Git\bin\bash.exe" -c "!BUILDKITE_COMMAND!"`

If I delete the `command.bat`, jobs will error, trying to run the `command` hook in cmd. Which seems like it always runs hooks in cmd.

QUESTION 1: I’d like to have the agent shell set to bash, and the agent run the `command` hook in bash. Is this possible?

I noticed in [the documentation](https://buildkite.com/docs/agent/v3/hooks#job-hooks-on-windows) it says the command hook can be run IF the shell is set to powershell.

QUESTION 2: Does that mean it will run `command.bat` in powershell? or does it need to be called `command.ps1`? Why does this work, and not bash?

Thanks.

---

<div class="post-metadata">

**Author:** ![pragmaxwell](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@pragmaxwell](https://forum.buildkite.community/u/pragmaxwell)\
**Post date:** [May 20, 2022, 8:33pm UTC](https://forum.buildkite.community/t/hooks-using-git-bash-on-windows/2049/2 "2022-05-20T20:33:27Z")

</div>

So I ended up having a `command.ps1` just pipe directly into our bash `command` hook. This achieves what I wanted, but I would have expected a shell=bash would use the bash hooks in the first place.

```auto
&"$Env:ProgramFiles\Git\bin\bash.exe" -c ".buildkite/hooks/command"

```

For context the specific problem we were having is all of our CI runs in bash so we ran BUILDKITE\_COMMAND with bash like so

```auto
"%ProgramFiles%\Git\bin\bash.exe" -c "!BUILDKITE_COMMAND!"

```

The problem was if there’s any spaces in the command, like `echo "wow look a space"`, it would completely stop the entire job at the space. It would end with `wow`. Not great!

Regardless, I think the docs should call this oddity out at least.

---

<div class="post-metadata">

**Author:** ![chomey](https://avatars.discourse-cdn.com/v4/letter/c/b4bc9f/32.png) [@chomey](https://forum.buildkite.community/u/chomey)\
**Post date:** [May 26, 2022, 10:28pm UTC](https://forum.buildkite.community/t/hooks-using-git-bash-on-windows/2049/3 "2022-05-26T22:28:14Z")

</div>

I’m also seeing this as well and would love an update!

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [May 27, 2022, 8:41pm UTC](https://forum.buildkite.community/t/hooks-using-git-bash-on-windows/2049/4 "2022-05-27T20:41:57Z")

</div>

Hey folks!

Unfortunately, Windows has some caveats and the agent use batch as default for the hooks. The workaround you proposed is the best alternative at the moment.

Best,
