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.
Tools and Risk Levels
Section titled “Tools and Risk Levels”Built-in tools
Section titled “Built-in tools”| 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.
Risk levels and authorization
Section titled “Risk levels and authorization”| 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) |
Dangerous-command detection (bash)
Section titled “Dangerous-command detection (bash)”These command fragments escalate bash risk to dangerous:
rm -r / rm --recursivesudogit reset --hardgit clean -fgit push --force / --force-with-leasegit checkout -- <path>git restoremkfs / fdisk / ddkillall / pkillcurl|sh or wget|shpath contains /etc /usr /bin /sbinRisk classification is a heuristic guard against mistakes, not a security sandbox: bash and plugins run with the current user’s process permissions.
Plugin tools
Section titled “Plugin tools”- Tools registered by local or npm plugins use their declared
riskfield 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
AbortSignalcancellation.
Related references
Section titled “Related references”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].