Skip to main content

Module code_mode

Module code_mode 

Source
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:

  1. local eligibility check (entrypoint, unattended, provider, …) passes
  2. the one-time caveats dialog counts as accepted
  3. the server gate tengu_rustling_blossom counts as open
  4. 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§

CodeModeError
Error building the Code Mode binary.

Functions§

patch
Return binary with Code Mode forced on.
patched_binary
Path of a patched copy of binary (resolved through PATH), 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.