Environment Variables
KnightCode uses environment variables in three ways:
KnightCode uses environment variables in three ways:
- Variables such as
KNIGHTCODE_OFFLINEconfigure the KnightCode process. - KnightCode sets process markers so child processes can identify KnightCode as the launching agent.
- Commands run by the LLM-callable shell tools receive
KNIGHTCODE_*variables describing the current session.
Provider API-key variables are documented separately in Providers.
Process Marker
The CLI and RPC entry points set two process markers:
AI_AGENT=knightcodeis a generic marker that lets tooling identify KnightCode as the agent that launched the process.KNIGHTCODE_CODING_AGENT=trueis KnightCode-specific and lets child processes detect that they run inside KnightCode.
Child processes inherit both markers. They are not session-specific and are not set automatically when KnightCode is embedded through the SDK.
Shell Tool Session Environment
Commands run by the bash and powershell tools receive the current KnightCode session state:
| Variable | Description |
|---|---|
KNIGHTCODE_SESSION_ID | Current session ID |
KNIGHTCODE_SESSION_FILE | Absolute path to the current session JSONL file; unset for ephemeral sessions |
KNIGHTCODE_PROVIDER | Currently selected model provider |
KNIGHTCODE_MODEL | Currently selected model ID |
KNIGHTCODE_REASONING_LEVEL | Current effective reasoning level: off, minimal, low, medium, high, xhigh, or max |
The values are resolved when each command starts. Switching models or changing the reasoning level therefore affects the next shell command without restarting KnightCode. KNIGHTCODE_PROVIDER and KNIGHTCODE_MODEL identify the selected KnightCode model, not a different upstream model that a router may choose internally.
When asked which model or provider is running, inspect these variables instead of inferring the answer from the system prompt:
printf '%s/%s\n' "$KNIGHTCODE_PROVIDER" "$KNIGHTCODE_MODEL"
printf 'reasoning=%s session=%s\n' "$KNIGHTCODE_REASONING_LEVEL" "$KNIGHTCODE_SESSION_ID"The session file can be inspected directly when the session is persistent:
if [ -n "$KNIGHTCODE_SESSION_FILE" ]; then
tail -n 1 "$KNIGHTCODE_SESSION_FILE"
fiThese variables are injected into the LLM-callable bash and powershell tools. They are not injected into user-entered ! or !! commands.
Custom Shell Tools
Tools created with createBashTool() or createPowerShellTool() expose the session environment by default when registered with KnightCode. Injection happens before spawnHook, so a hook receives the variables in ctx.env:
const bashTool = createBashTool(cwd, {
spawnHook: (ctx) => ({
...ctx,
env: { ...ctx.env, CI: "1" },
}),
});Disable session metadata independently of the spawn hook:
const powershellTool = createPowerShellTool(cwd, {
exposeSessionEnvironment: false,
spawnHook: (ctx) => ctx,
});When disabled, KnightCode removes inherited values for these variables so nested KnightCode processes do not expose stale parent-session metadata.
KnightCode Process Configuration
These variables are read by KnightCode itself:
| Variable | Description |
|---|---|
KNIGHTCODE_CODING_AGENT_DIR | Override the config directory; default is ~/.knightcode/agent |
KNIGHTCODE_CODING_AGENT_SESSION_DIR | Override session storage; overridden by --session-dir |
KNIGHTCODE_PACKAGE_DIR | Override the package directory, useful for Nix/Guix store paths |
KNIGHTCODE_OFFLINE | Disable automatic network activity, including model catalog refreshes |
KNIGHTCODE_DISABLE_FILE_CHECKPOINTS | Set to 1, true, or yes to stop backing up files before edits; /undo then rewinds the conversation only. See Sessions |
KNIGHTCODE_SKIP_VERSION_CHECK | Disable automatic version checks and downloads; explicit knightcode update still works |
KNIGHTCODE_DISABLE_AUTO_UPDATE | Set to 1 to disable automatic update downloads while retaining update notices, overriding the user-level autoUpdate setting; explicit knightcode update still works |
KNIGHTCODE_TELEMETRY | Override install/update telemetry and provider attribution headers: 1/true/yes or 0/false/no |
KNIGHTCODE_CODEMODE_MAX_WORKERS | Maximum codemode workers alive at once across all sessions in the process; default 2. Each worker's script may use up to 256 MB. Raise it when one process runs several sessions, such as in-process subagents. Further scripts wait for a free worker. See Codemode |
KNIGHTCODE_CACHE_RETENTION | Set to long for extended provider prompt caching where supported |
KNIGHTCODE_SHARE_VIEWER_URL | Override the base URL used by /share |
KNIGHTCODE_BUG_ENDPOINT | Override the origin /bug uploads go to; default is https://remote.knightcode.dev |
KNIGHTCODE_CLEAR_ON_SHRINK | Set to 1 to clear empty rows when rendered content shrinks; the terminal.clearOnShrink setting takes precedence. See Settings |
KNIGHTCODE_HARDWARE_CURSOR | Set to 1 to show the hardware cursor; see Terminal setup |
KNIGHTCODE_CLIPBOARD_OSC52 | Set to 1 to also send copied text to the terminal with OSC 52 after the local clipboard write, as KnightCode does over SSH. Use it when a remote client reaches KnightCode without SSH variables, such as a multiplexer attached from another machine or a remote IDE daemon |
KNIGHTCODE_HYPERLINKS | Override OSC 8 hyperlink detection with 1, 0, or auto |
KNIGHTCODE_PROGRAM_STATUS | Override OSC 7501 program status detection: 1 always reports, 0 never reports; otherwise KnightCode reports only after the terminal confirms support. See Terminal setup |
KNIGHTCODE_IMAGE_PROTOCOL | Override inline image detection with kitty, iterm2, none, or auto |
KNIGHTCODE_TRUE_COLOR | Override truecolor detection with 1, 0, or auto |
KNIGHTCODE_TUI_ESC_TIMEOUT | How long to wait after a lone ESC before treating it as Escape, in milliseconds; defaults to 100 over SSH and 10 otherwise. Increase if Alt-key input is misread as Escape |
BRAVE_API_KEY | Brave Search key for websearch when none is stored with /tools; see Web tools |
VISUAL, EDITOR | External editor fallback when externalEditor is unset |
HTTP_PROXY, HTTPS_PROXY | Proxy outbound HTTP requests |
Update controls
Automatic updates are on by default. For a persistent preference without
environment variables, open /settings and set Automatic updates to false,
or set "autoUpdate": false in your user-level settings.json; see
Disable automatic updates for file locations
and an example.
To use an environment variable instead, set it before launching KnightCode. For the current PowerShell terminal:
$env:KNIGHTCODE_DISABLE_AUTO_UPDATE = "1"
knightcodeTo persist it for your Windows user:
[Environment]::SetEnvironmentVariable("KNIGHTCODE_DISABLE_AUTO_UPDATE", "1", "User")Then restart your terminal app or IDE so new KnightCode processes inherit it.
On macOS or Linux, add this line to your shell profile (~/.zshrc or ~/.bashrc),
then open a new terminal:
export KNIGHTCODE_DISABLE_AUTO_UPDATE=1This variable overrides autoUpdate: true. Any non-empty value disables automatic
downloads, including 0; unset it to return control to settings.json. To suppress
update notices and checks too, use KNIGHTCODE_SKIP_VERSION_CHECK=1 instead.
Explicit knightcode update remains available with either variable.
Provider credentials such as ANTHROPIC_API_KEY, OPENAI_API_KEY, and provider-specific configuration are listed in Providers.
Models Configuration
This reference lists the fields of models.json. See Configure a compatible endpoint for examples and Configuration for the file location.
Keybindings Reference
KnightCode exposes named actions, such as app.session.new, that can be assigned keybindings. You can change default assignments or bind unassigned actions in KnightCode's user...