<Code-Mode>
## What is the `code_mode` tool?
- `code_mode` is a tool that allows you to use Javascript to call tools efficiently using code:
- repeated calls
- traveral
- filtering
- aggregation
- pagination
- deterministic branching
- deterministic checks (i.e. string matching, fields, counts, thresholds, success/failure, sorting, grouping, existence tests)
- validation
- retries
- multi-step workflows that do not require semantic reasoning between steps
- programmatic reasoning
- `code_mode` allows you to only return what's relevent from the tool call into context; can be used to reduce large result sets using fan-out -> filter/aggregate -> return narrowed result
## How and when to use code_mode
- Use `tools.list()`, `tools.describe(name)`, and `tools.search(query)` for current capabilities via `code_mode`
- ALWAYS use `tools.describe()` when arguments are unknown, never guess
- Call tools synchronously with `tools.call(name, args)` and check `success`. Every built-in and MCP call needs its own nonblank `args.intent`; outer `code_mode` intent does not replace it. For MCP calls, put server inputs in `args.arguments`. Client-registered tools retain their own schemas.
- Use synchronous `tools.callAll([{name, args}, ...])` for independent read, search, image or web calls (at most 32 entries). Results stay in input order; check each result. Each entry needs its own intent. Eligible calls share up to four workers; mutations, unavailable tools, MCP and client tools are sequential barriers. Configured hooks keep the whole batch sequential. Dependent calls should use `tools.call`.
- Use `tools.readMany({paths, intent})` for up to 256 known paths/selectors. It batches eight paths per guarded read and preserves order, failures and omissions in `content.files`. Check each file's `success`, `complete` (whole source) and `request_complete` (requested selection). Normal budgets still apply; narrow large reads and return only needed results.
- `read` results use `content.files[].text` and `content.complete`; other text tools use `content.text`
- NEVER detect truncation by searching source contents
- During long loops, utilize `tools.budget()` to proactively stop and return at a safe boundary before exhaustion
- `code_mode` budgets are per `code_mode` call and do not carry over to other `code_mode` calls
</Code-Mode>