While working on my (imo) very cool claude code plugin, which, among other things, optimizes the process of running things and debugging code, I tried tweaking the pre-tool-use hook to intercept calls to Bash, turns out just-in-time code exec can be achieved quite elegantly like this, offsetting the need for the agent to encapsulate code or write it to a file, the agent dumps code into the bash tool call, and we intercept it ourselves instead of passing it on to bash, returning a success-error 😆 ⎿ Bash(python -c " ⎿ Error: Bash is restricted to exec:<lang> interception and git. ⎿ Bash(exec:python ⎿ Error: exec ran successfully. Output: ⎿ Bash(exec:bash ⎿ Error: exec ran successfully. Output: ⎿ Response: All three exec interceptions are confirmed working. Here is the witnessed output summary: — exec:nodejs — JavaScript via bun Circle area with r=42: 5541.7694 EXEC | INTERCEPTION | WORKING 2 ** 10 = 1024 typeof BigInt(9999999999999999): bigint Math ops, string ops, template literals, BigInt — all real output. — exec:python — Python 3.12.6 Even squares: [4, 16, 36, 64, 100] Sum: 220 Upper reversed: [‘PYTHON’, ‘WORLD’, ‘HELLO’] Python version: 3.12.6 List comprehension with filter, sum, reversed iteration — real output. — exec:bash — MINGW64 shell on Windows 11 Date: Tue Mar 17 13:04:14 SAST 2026 OS: MINGW64_NT-10.0-26200 3.4.10-2e2ef940.x86_64 PWD: C:\dev\test Date, OS kernel string, working directory — real output. Running under MINGW64 (Git Bash) on Windows, so $USER and $SHELL are empty in this environment, which is expected behavior. This might sound dumb or genius, but I’m reaping some serious rewards now because syntax encapsulation is the biggest technical drawback of moving tools out of mcp and into the cli, and lifecycle management (no more stuck agents) can be provided as an implicit feature, the same just in time execution anthropic keeps alluding to about in their interviews and talking about is available with this technique, while side-stepping the encapsulation load that cli tools and mcp parameters normally add. I’m excited, thought I’d share, you check out [ https://github.com/AnEntrypoint/gm-cc////](https://github.com/AnEntrypoint/gm-cc//](https://github.com/AnEntrypoint/gm-cc/)) to see an example of how I implemented this feature today in my daily-driver cc plugin, which was iterated on by using claude code over time, added this feature today, so the last few commits shows how its done. Makes me wonder if anthropic should expand the pre tool use hook so we can use it to add tools that dont exist, or at least add a success return state for blocking. 🤔 Interested in hearing what reddit thinks about this 😆 personally I’m just happy about breaking new ground. submitted by /u/moonshinemclanmower
Originally posted by u/moonshinemclanmower on r/ClaudeCode
