Skip to content

Failures and Control Flow

Failures can arise in provider requests, context capacity, Hooks, permissions, or tool execution. Keep the control layers distinct: provider retry does not repeat completed tools; emergency compaction addresses context errors; cancellation propagates through signals; the step limit bounds model steps; and the Stop Hook can require continuation when the model is ready to finish.

  • All hooks matching the same event run in parallel (Promise.all), with results merged in config order.
  • Each hook is an independent system-shell child process (process group) with the workspace as its cwd.
  • The event payload arrives as JSON on stdin (1MB limit).
Parameter Default Range
timeout (config) 10 seconds 1–600 seconds (integer)
  • On timeout, SIGTERM goes to the process group; if it has not exited after 500ms, SIGKILL (Windows terminates the process directly).
  • Timeout result: timedOut: true, counted as a hook failure (never blocks).
  • On user cancellation (Ctrl+C) hooks cancel: cancelled: true, rethrown with the main-task abort.
Channel Cap Over-limit behavior
stdin 1MB inputExceeded, counted as a failure
stdout 10KB process terminated immediately, outputExceeded
stderr 10KB same
Result Handling
exit 0, empty stdout no-op (hook.completed)
exit 0, valid JSON processed per protocol (decision/context/system message)
exit 2 (controllable events) explicit block
non-zero, timeout, over limit, invalid JSON, illegal fields hook.failed: diagnostic stderr (≤2000 chars, scrubbed) and fail open

Fail-open means: decision hooks that fail produce no decision, and permissions continue through the policy layer; unsafe scenarios are decided by that layer (a failed PermissionRequest never silently allows).

  • Successful hooks show under --verbose; failures, blocks, and input conflicts always show.
  • Hook runtime events (hook.started/completed/failed/blocked) are written to the trace.
  • systemMessage output goes to the diagnostic sink (stderr).
Symptom Cause Fix
CODEN_OPENAI_API_KEY is required no key set (default provider) export CODEN_OPENAI_API_KEY=... or config env
CODEN_ANTHROPIC_API_KEY is required --provider anthropic without a key export CODEN_ANTHROPIC_API_KEY
Cannot read config ... invalid JSON in a config file fix the matching scope’s config.json
language must be zh or en illegal --lang/config value use zh/en; check the user config
--tui and --cli are mutually exclusive conflicting interface flags keep one interface flag
--smart-approve and --auto are mutually exclusive conflicting approval flags keep one
--allow-outside-workspace requires --auto the flag used alone combine with --auto
print mode requires a prompt -p without a task add a prompt argument
Anthropic enabled thinking requires maxOutputTokens greater than 1024 reservedOutputTokens <= 1024 with thinking enabled raise reservedOutputTokens or lower the thinking level
Symptom Cause Fix
runtime.step_limit (Maximum model steps (80) reached) exceeded maxSteps split the task or raise --max-steps
context.exhausted still over budget after emergency compaction /new or a fresh session; narrow the task
permission.denied permission refused use a safer operation or approve manually
permission.outside_workspace_denied outside access under --auto use --auto --allow-outside-workspace when truly needed
tool.timeout tool not finished in 60s (without cooperative cancel) shorten the command/tool logic; check plugin cancellation
edit.no_match / edit.multiple_matches oldText absent or not unique copy the exact text to replace
Symptom Cause Fix
plugin.specifier_invalid bad specifier use npm:<package> or npm:<package>@<version-or-tag>
plugin.install_busy scope transaction lock busy retry later (stale locks auto-clean)
plugin.lock_missing project sync without bun.lock plugin install first or commit the lock
plugin.lock_outdated lock file out of sync with the manifest update and commit the lock
plugin.manifest_invalid corrupted plugins.json repair the manifest; reinstall if necessary
plugin.metadata_missing / plugin.entry_invalid / plugin.api_unsupported / plugin.name_mismatch package violates the author protocol fix the package per the Author Protocol
plugin load failure, tools missing top-level/entry exception; loading .ts under Node check coden plugin list; run with Bun or use an npm plugin
plugin restart required npm plugin metadata changed at runtime restart CodeN
Symptom Cause Fix
config parse failure: unsupported hook event/invalid matcher/timeout range illegal hook config see Matchers and Execution
X config exceeds 64 commands too many hooks for one event trim the hook list
hook silently ineffective non-zero exit, timeout, output over limit, invalid JSON --verbose; check the stdin/stdout protocol
Symptom Cause Fix
skill not active directory/frontmatter mismatch or illegal file --verbose for ignored ... reasons; restart
local .ts plugin not loading under Node Node lacks data:text/typescript support run with Bun (or use an npm plugin)