You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fired before a bash command executes (tool calls and user `!`/`!!`). Use it to rewrite commands or override execution settings. You can also block execution by returning `{ block: true, reason?: string }`. For follow-up hints based on output, pair this with `tool_result`.
555
+
556
+
```typescript
557
+
pi.on("before_bash_exec", async (event) => {
558
+
if (event.command.includes("rm -rf")) {
559
+
return { block: true, reason: "Blocked by policy" };
560
+
}
561
+
562
+
if (event.source==="tool") {
563
+
return {
564
+
cwd: "/tmp",
565
+
env: {
566
+
...event.env,
567
+
MY_VAR: "1",
568
+
PATH: undefined, // remove PATH
569
+
},
570
+
};
571
+
}
572
+
});
573
+
```
574
+
575
+
Return a `BashExecOverrides` object to override fields, or return `{ block: true, reason?: string }` to reject the command. Any field set to a non-undefined value replaces the original (`command`, `cwd`, `env`, `shell`, `args`, `timeout`). For `env`, set a key to `undefined` to remove it.
576
+
552
577
#### tool_result
553
578
554
-
Fired after tool executes. **Can modify result.**
579
+
Fired after tool executes. **Can modify result.** Use this to post-process outputs (for example, append hints or redact secrets) before the result is sent to the model.
If `event.isError` is true, return `{ errorMessage: "..." }` to override the thrown error message (optionally alongside `content`). Returning `errorMessage` on a successful tool result forces the tool to be treated as an error.
0 commit comments