Expand description
Force Code Mode (the REPL tool) on for SDK sessions.
The stock CLI (verified 2.1.329) refuses Code Mode for every
non-interactive session (-p / stream-json), so no SDK gets it. With
SessionOptions::code_mode the SDK runs a patched copy of the CLI
instead; the installed binary is never modified.
The patch touches only the Code Mode opt-in module of Bun’s embedded module graph:
- local eligibility check (
entrypoint,unattended, provider, …) passes - the one-time caveats dialog counts as accepted
- the server gate
tengu_rustling_blossomcounts as open - the module’s precompiled bytecode is dropped, so Bun compiles the patched source (the bytecode would otherwise run unchanged)
Every edit keeps the byte length, so no offset in the binary moves. An anchor that is missing or ambiguous (a CLI version this patch does not know) is an error, never a silent partial patch.
Layout of Bun’s standalone module graph (Format B, Claude Code 2.1.280+):
trailer "\n---- Bun! ----\n" preceded by a 32-byte offsets struct
(byte_count: u64, modules: (u32 offset, u32 len), …); the module list
is 52-byte entries of six (u32 offset, u32 len) pointers (name,
contents, sourcemap, bytecode, module_info, bytecode_origin_path) plus
four flag bytes; offsets are relative to trailer - 32 - byte_count.
Enums§
Functions§
- patch
- Return
binarywith Code Mode forced on. - patched_
binary - Path of a patched copy of
binary(resolved throughPATH), built on first use and cached under<cache>/claude-code-agent/code-mode/. The cache key is the installed binary’s name, size and mtime plus this SDK’s version, so a CLI update or a new patch builds a new copy.