Skip to content

Tools and Context

Tools define the agent’s action space; context defines the state on which the model can choose its next action. Tool descriptions and JSON Schemas enter the model request, while tool results become message history. Permission, risk, and path checks happen on the local execution side and must not be mistaken for a security capability of the model.

Tool Risk Input highlights Key behavior
read read path, offset (default 1), limit (default 500, max 2000) Reads UTF-8 text by 1-based line offset; output capped at 50000 chars with an omission notice; opens with O_NOFOLLOW
write modify path, content Creates or fully overwrites; file mode 0600; creates parent directories
edit modify path, oldText, newText Replaces the unique matching block exactly; returns edit.multiple_matches when not unique and edit.no_match when absent
bash modify (can escalate to dangerous) command, timeout (default 30000, range 100–60000), maxOutput (default 30000, range 1000–100000) Runs bash -lc with the workspace as cwd; non-zero exit, timeout, or cancellation are errors; timeout kills the process group
activate_skill read name Loads the full instructions and root of a skill by name; unknown names return skill.not_found; reads only the discovered entry file after verifying its content is unchanged

Tools execute sequentially in the model’s returned order; a single call times out after 60 seconds (cooperative cancellation only). All tool output is truncated to 50000 characters before re-entering context.

Level Default interactive mode --smart-approve --auto
read auto-allowed auto-allowed auto-allowed
modify human confirmation (y/s/N) LLM review, escalating to human on uncertainty auto-allowed
dangerous human confirmation (y/N only, no session grant) human confirmation auto-allowed (hook deny still applies)

These command fragments escalate bash risk to dangerous:

rm -r / rm --recursive
sudo
git reset --hard
git clean -f
git push --force / --force-with-lease
git checkout -- <path>
git restore
mkfs / fdisk / dd
killall / pkill
curl|sh or wget|sh
path contains /etc /usr /bin /sbin

Risk classification is a heuristic guard against mistakes, not a security sandbox: bash and plugins run with the current user’s process permissions.

  • Tools registered by local or npm plugins use their declared risk field and join the same authorization flow.
  • Tool names must match ^[a-zA-Z][a-zA-Z0-9_-]{0,63}$; name collisions (including with built-ins) skip the whole plugin.
  • Plugin tools share the same 60-second timeout and cooperative AbortSignal cancellation.
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].