session_exec
Run commands in persistent sessions and shape output via grep, line limits, and character caps for AI agents.
Instructions
Run a command in a session; returns a structured ExecResult JSON (stdout, stderr, exit_code, duration_ms, cwd, truncated). Optionally pass budget to shape output: {grep:{pattern,context?}, keep:{mode:"all"|"tail"|"head"|"head_tail",n?|head?+tail?}, max_chars?}. Shaping is line-based, client-side, AFTER secret redaction; it never changes the exit code or side effects. When applied, the result includes a budget report (per-stream mode + lines_total/lines_kept).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| budget | No | Shape THIS command's output (overrides the session default). | |
| command | Yes | The shell command to run. | |
| session_id | Yes | Session id from session_create. |