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.
Context and Thinking Levels
Section titled “Context and Thinking Levels”Context budget
Section titled “Context budget”| 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.
Automatic compaction
Section titled “Automatic compaction”- 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./compactreports manual failure explicitly, while/newclears the summary. - Compaction is still semantically lossy. Store durable rules and critical task state in project instruction files.
Thinking levels
Section titled “Thinking levels”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_thinkingand signature blocks persist asproviderStateand are replayed after tool calls and resume; mismatched provider state is ignored when switching providers. - Entry points:
--thinking <level>,CODEN_THINKING_LEVEL, configthinkingLevel, REPL/thinking [level].
Related references
Section titled “Related references”Language and Thinking Levels
Section titled “Language and Thinking Levels”Language
Section titled “Language”- CodeN defaults to Chinese and never reads the system locale.
- Language resolution:
--lang <zh|en>(this process only, no config write) > user configlanguage> defaultzh. - The project config
languagefield 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, mode0600). - 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
--langor config values error out (exit code 2); an invalid--langon the command line only reports the error and writes no config.
Thinking levels
Section titled “Thinking levels”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.
Provider mapping
Section titled “Provider mapping”- OpenAI:
reasoning_effort;off→minimal(displayed asoff→minimal). - Anthropic: explicit thinking budgets (1024 / 25% / 50% / 75%), requiring
reservedOutputTokens > 1024;offsends{ type: "disabled" }. defaultsends no parameter, preserving pre-upgrade behavior.
Scope boundaries
Section titled “Scope boundaries”- 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.