Skip to content

Compaction and Thinking

Context management and model reasoning are separate control axes. Compaction preserves task state lossily as history approaches its budget; the thinking level maps to provider parameters and is snapshotted at the start of a turn. CodeN unifies the user-facing control, not the reasoning semantics of different providers or models.

Field Default Meaning
contextWindow 128000 provider context window
reservedOutputTokens 8192 maxOutputTokens of every request
safetyMargin 4096 safety margin on the input budget
input budget 115712 contextWindow − reservedOutputTokens − safetyMargin

Validation: all three must be non-negative integers; contextWindow and reservedOutputTokens must be positive; contextWindow must exceed reservedOutputTokens + safetyMargin. Estimation: text counts as length / 3.5 rounded up, +6 per message, and tool definitions are estimated from their JSON — an estimator, not provider-exact billing.

  • When the estimate exceeds 80% of the input budget, CodeN keeps the current interaction and the preceding complete interaction verbatim. Tool calls and their results remain in the same interaction unit.
  • The current session model reads all older history, including any previous compaction summary, and produces one structured Markdown handoff capped at min(2048, reservedOutputTokens). No deterministic summary is created before the model sees the history.
  • The handoff is committed only when it is non-empty, contains no tool call, reduces the replaced context, and leaves the projected request within the hard input budget. A failed automatic attempt leaves state unchanged and is not repeated during the same user turn.
  • On a provider 413 or context-length error, emergency compaction runs the same flow once; failure or a second context error throws context.exhausted. /compact reports manual failure explicitly, while /new clears the summary.
  • Compaction is still semantically lossy. Store durable rules and critical task state in project instruction files.

Six unified levels: default (default; sends no parameter), off, minimal, low, medium, high.

Level OpenAI (reasoning_effort) Anthropic (thinking budget)
default not sent not sent
off minimal (shown as off→minimal) { type: "disabled" }
minimal minimal 1024 tokens
low low 25% of reservedOutputTokens
medium medium 50%
high high 75%

Anthropic budgets clamp to [1024, reservedOutputTokens − 1]; enabling enabled thinking requires reservedOutputTokens > 1024. The budget counts inside reservedOutputTokens, so a higher level leaves fewer tokens for final text and tool calls in the same response.

  • Applies to main-agent requests only; context compaction and Smart Approval reviews keep provider defaults.
  • The level snapshot at turn start covers that turn’s tool loop and retries.
  • Anthropic thinking/redacted_thinking and signature blocks persist as providerState and are replayed after tool calls and resume; mismatched provider state is ignored when switching providers.
  • Entry points: --thinking <level>, CODEN_THINKING_LEVEL, config thinkingLevel, REPL /thinking [level].
  • CodeN defaults to Chinese and never reads the system locale.
  • Language resolution: --lang <zh|en> (this process only, no config write) > user config language > default zh.
  • The project config language field is ignored — language is a user-owned preference.
  • REPL /lang <zh|en> switches immediately and atomically updates the user-level config file (preserving other fields, mode 0600).
  • The system prompt, built-in tool descriptions, and UI share one language; the agent may follow a per-task request for another reply language without changing the UI or persisting the preference.
  • Third-party plugin names, descriptions, output, and errors always keep the author’s original text.
  • Invalid --lang or config values error out (exit code 2); an invalid --lang on the command line only reports the error and writes no config.

Six unified levels: default (default), off, minimal, low, medium, high.

Entry point Scope Persistence
--thinking <level> this process overridden into the session at startup (resume scenarios)
CODEN_THINKING_LEVEL this process none
config thinkingLevel user/project the config file itself
/thinking [level] this process and session written to session records; never to config files
/new — does not change the level

Resume precedence: explicit --thinking > saved session value > environment/project/user config > default.

  • OpenAI: reasoning_effort; off→minimal (displayed as off→minimal).
  • Anthropic: explicit thinking budgets (1024 / 25% / 50% / 75%), requiring reservedOutputTokens > 1024; off sends { type: "disabled" }.
  • default sends no parameter, preserving pre-upgrade behavior.
  • Main-agent requests only; context compaction and Smart Approval reviews keep provider defaults.
  • The turn-start snapshot covers that turn’s tool loop and retries.
  • Explicit settings never silently degrade: unsupported parameters surface as clear provider errors.