agentafk
Configuration

Environment Variables

Complete reference for all environment variables recognized by agent-afk, grouped by category.

All environment variables recognized by agent-afk are listed here, grouped by functional category. Most are optional; required variables are noted in the description. Variables can be set in your shell, a .env file, or ~/.afk/config/afk.env — that last file is loaded at startup (shell env takes precedence).

Authentication

VariableTypeDescriptionDefault
AFK_LOCAL_API_KEYstringPlaceholder API key for local Anthropic-compatible servers (vllm-mlx, etc.). Set when AFK_LOCAL_BASE_URL is configured.local
ANTHROPIC_API_KEYstringAnthropic API key. Tier-1 credential — overrides keychain OAuth and CLAUDE_CODE_OAUTH_TOKEN.
CLAUDE_CODE_OAUTH_TOKENstringClaude Code OAuth token. Tier-2 credential — used when ANTHROPIC_API_KEY is unset; falls back to keychain.
CODEX_API_KEYstringFallback OpenAI API key for the openai-compatible provider, read after OPENAI_API_KEY. Legacy name from the removed @openai/codex-sdk integration — prefer OPENAI_API_KEY.
EXA_API_KEYstringExa (exa.ai) search API key, enabling web_scrape search mode. Free tier (20k requests/month) available at https://exa.ai. When unset, search mode returns an actionable error; markdown and raw modes are unaffected.
OPENAI_API_KEYstringOpenAI API key for the openai-compatible provider (gpt-, o1, o3*, o4* models).

Model

VariableTypeDescriptionDefault
AFK_COMPACT_KEEP_LAST_TURNSnumberNumber of recent turns the compactor keeps verbatim during /compact. Default tuned in compact-handler.ts.
AFK_COMPACT_MODELstringOverride the model used by the /compact summarizer. Falls back to a cheap default (haiku-class).
AFK_DEFAULT_SUBAGENT_MODELstringOverride the default model used when a subagent is dispatched without an explicit model.
AFK_DISABLE_PROMPT_CACHEbooleanDisable Anthropic prompt caching when set to 1/true/yes/on. Unset = caching enabled.0
AFK_EFFORTstringEffort hint guiding adaptive-thinking depth, forwarded as Anthropic output_config.effort (model-gated; ignored where unsupported). Accepts low | medium | high | xhigh | max.
AFK_LOCAL_BASE_URLstringBase URL for a self-hosted Anthropic-compatible server. When set, routes traffic away from api.anthropic.com.
AFK_MAX_BUDGET_USDnumberPer-turn USD budget ceiling. Aborts the turn when projected spend would exceed this.5.00
AFK_MAX_OUTPUT_TOKENSnumberCap on output tokens per turn. Falls back to provider default when unset.
AFK_MAX_TOKENSnumberCap on total tokens per turn (input + output). Default 4096.4096
AFK_MODELstringDefault model for agent turns. Accepts slot names (small, medium, large), legacy aliases (opus, sonnet, haiku), the fixed-id fable alias (Claude Fable 5), or full model IDs.sonnet
AFK_MODEL_LARGEstringBind the "large" capability tier (most capable) to a model id/alias. Overrides afk.config.json models.large.
AFK_MODEL_LARGE_API_KEYstringPer-slot API key for the "large" tier (Stage 2). Overrides global credentials for this tier only.
AFK_MODEL_LARGE_BASE_URLstringPer-slot endpoint base URL for the "large" tier (Stage 2). Anthropic Messages base or OpenAI-compatible base per the tier provider.
AFK_MODEL_MEDIUMstringBind the "medium" capability tier (general-use) to a model id/alias. Overrides afk.config.json models.medium.
AFK_MODEL_MEDIUM_API_KEYstringPer-slot API key for the "medium" tier (Stage 2). Overrides global credentials for this tier only.
AFK_MODEL_MEDIUM_BASE_URLstringPer-slot endpoint base URL for the "medium" tier (Stage 2). Anthropic Messages base or OpenAI-compatible base per the tier provider.
AFK_MODEL_SMALLstringBind the "small" capability tier (cheap/fast) to a model id/alias. Overrides afk.config.json models.small.
AFK_MODEL_SMALL_API_KEYstringPer-slot API key for the "small" tier (Stage 2). Overrides global credentials for this tier only.
AFK_MODEL_SMALL_BASE_URLstringPer-slot endpoint base URL for the "small" tier (Stage 2). Anthropic Messages base or OpenAI-compatible base per the tier provider.
AFK_OPENAI_BASE_URLstringBase URL override for the OpenAI-compatible provider. Used for local shims (mlx_lm.server, Ollama, vLLM, LM Studio). The OpenAI SDK appends /chat/completions itself — a value ending in /chat/completions will be stripped at config-load time with a one-shot warning.
AFK_OPENAI_CHATGPT_OAUTHbooleanOpt into using ChatGPT-subscription OAuth credentials from ~/.codex/auth.json (auth_mode: chatgpt) as OpenAI provider auth. Off by default. READ-ONLY: AFK never refreshes these tokens — re-run codex when the access token expires. Routes requests over the Responses API to the private ChatGPT backend (chatgpt.com/backend-api).
AFK_OPENAI_USE_RESPONSESbooleanOpt the OpenAI-compatible provider into the OpenAI Responses API instead of Chat Completions for API-key sessions. Truthy values: 1, true, yes, on. The ChatGPT-subscription OAuth path uses Responses automatically regardless of this flag.
AFK_PROMPT_CACHE_TTLstringTTL for Anthropic prompt-cache blocks. Accepts 5m or 1h.1h
AFK_PROVIDERstringForce provider selection (anthropic | anthropic-direct | openai | openai-compatible | openai-codex). Overrides the model-name heuristic. Same surface as the --provider CLI flag; CLI flag wins when both are set.
AFK_SUGGEST_ENABLEDbooleanEnable the LLM-backed ghost-text suggestion tier in the interactive REPL. Set to 1/true/yes/on to activate. Off by default.
AFK_SUGGEST_GHOSTbooleanEnable REPL ghost-text inline suggestions (Tier-1 history/dropdown + optional Tier-2 LLM). 1 = on (default), 0 = off. Set 0/false/off/no to disable all ghost text. Tier-2 LLM is separately gated by AFK_SUGGEST_ENABLED.1
AFK_SUGGEST_MODELstringOverride the small model used for REPL ghost-text suggestions. Falls back to AFK_COMPACT_MODEL or haiku-class for anthropic, or the session model for other providers.
AFK_SYSTEM_PROMPTstringRaw operator-overlay prompt. Highest-priority overlay (over afk.config.json and AFK.md). Appended on top of the framework base (prompts/system-prompt.md) under an "# Operator configuration" header — it augments, never replaces, the base.
AFK_TASK_BUDGETnumberPer-task token budget ceiling. Aborts when cumulative usage would exceed it.100000
AFK_TEMPERATUREnumberNumeric temperature override for model sampling. Provider default if unset.
AFK_THINKINGstringExtended-thinking mode. Accepts adaptive | disabled | enabled:<N> | enabled:max. Defaults to the model-appropriate mode when unset (adaptive on current models).adaptive
AFK_TIMEOUT_MSnumberPer-turn timeout in milliseconds. Provider/SDK default if unset.
CLAUDE_MODELstringLegacy alias for AFK_MODEL — supported for back-compat with pre-AFK_* deployments.

Routing

VariableTypeDescriptionDefault
AFK_AUTO_ROUTINGbooleanAuto-route bare slash inputs to matching skills. Applies to interactive, chat, telegram, and daemon surfaces.
AFK_INTERNALbooleanTier gate. Unlocks only when set to the literal string 1 — other truthy values (true, yes) leave the tier locked. When unlocked, internal-audience skills (e.g. /audit-fit) become visible in slash listings, /help, and tab-complete. Gates surfacing only — not an access boundary; it does not change what's accessible.

Browser

VariableTypeDescriptionDefault
AFK_BROWSER_ALLOWED_DOMAINSstringComma-separated allowlist of URL host globs. When set, browser_open and any navigation that targets a host outside the list returns status: blocked_by_policy. Unset means no allowlist (permissive). Patterns use simple * glob matching against the URL host. Combines with AFK_BROWSER_BLOCKED_DOMAINS — block wins.
AFK_BROWSER_BACKENDstringSelect the browser provider backend. Phase 1 supports only playwright. Reserved for future cdp / mcp adapters. Unset defaults to playwright.
AFK_BROWSER_BLOCKED_DOMAINSstringComma-separated blocklist of URL host globs. Browser navigation that matches any entry returns status: blocked_by_policy regardless of the allowlist.
AFK_BROWSER_CONFIGstringAbsolute path to an alternate browser config file. Overrides the default ~/.afk/config/browser.json lookup. Useful for per-project overrides in CI.
AFK_BROWSER_DOM_SNAPSHOTSbooleanPhase 2 opt-in: when set to 1, every browser_act writes a gzipped DOM snapshot sidecar under ~/.afk/state/witness/<sid>/browser/dom-snapshots/. Off by default because snapshots are large; useful for post-mortem analysis of failed actions.
AFK_BROWSER_HEADLESSbooleanOverride the default headless mode for native browser-control tools. 1/true forces headless; 0/false forces headed. When unset the default is headless for daemon and subagent surfaces and headed for repl/interactive — so an operator can watch the agent work in REPL mode.
AFK_SESSION_IDstringOverride the browser session ID used by the native browser-control tools. Defaults to 'default' for single-session use. Subagents inherit the parent's session by default. Set this when running multiple concurrent AFK processes that should each manage an isolated browser context.default

MCP (Model Context Protocol)

VariableTypeDescriptionDefault
AFK_ALLOW_PROJECT_MCPbooleanAllow loading MCP configuration from <cwd>/.mcp.json. Disabled by default — opt-in to mitigate config-injection risks.

Daemon

VariableTypeDescriptionDefault
AFK_DAEMON_CWDstringWorking directory used by the daemon process for spawned agent sessions.
AFK_DAEMON_HOSTstringBind address for the daemon control HTTP surface. Defaults to 127.0.0.1 (loopback only). The control surface is unauthenticated, so bind a non-loopback address such as 0.0.0.0 only on a trusted or firewalled network. Overridden by the --host flag.
AFK_DAEMON_TASKstringDefault task description for the daemon. Falls back to afk.config.json daemon.task.
AFK_DAEMON_TASK_IDstringTask identifier the daemon uses to scope its state directory and telemetry.
AFK_SESSIONSTART_COOLDOWN_MSnumberCooldown in milliseconds between SessionStart trigger fires in the daemon. Prevents thundering-herd on rapid restarts.

Telegram

VariableTypeDescriptionDefault
AFK_TELEGRAM_ALLOWED_CHAT_IDSstringComma-separated list of Telegram chat IDs allowed to interact with the bot. Required when the bot is running.
AFK_TELEGRAM_BOT_TOKENstringAlternative env var name for the Telegram bot token, accepted by the setup wizard.
AFK_TELEGRAM_CWDstringOverride the working directory used by the Telegram bot when spawning agent sessions.
AFK_TELEGRAM_NOTIFY_MODEstringOutbound notification fan-out: primary (default — one chat), broadcast (every allowed chat), or custom (afk.config.json telegram.notify.targets). The afk.config.json telegram.notify.mode takes precedence.
AFK_TELEGRAM_PRIMARY_CHAT_IDstringDefault chat ID for outbound notifications (primary-mode routing). When unset, notifications go to the first private/DM chat in AFK_TELEGRAM_ALLOWED_CHAT_IDS. The afk.config.json telegram.notify block takes precedence.
TELEGRAM_BOT_TOKENstringTelegram bot token from @BotFather. Required to run the Telegram bot surface.
TELEGRAM_DATA_DIRstringOverride the directory where Telegram bot state is stored. Defaults to ~/.afk/state/telegram/.
TELEGRAM_VERBOSEbooleanSet to 1 to log per-message details from the Telegram bot — chat IDs, message text, latency.

Worktrees

VariableTypeDescriptionDefault
AFK_WORKTREE_AUTONAMEbooleanAuto-rename worktree branches based on the first user message in interactive mode. 1 = on (default), 0 = off.1
AFK_WORKTREE_BASEstringOverride the base git ref for worktrees created with --worktree. By default AFK bases worktrees on the remote's default branch (e.g. origin/main), fetched fresh. Set this to pin a different ref, or to HEAD to base on the local checkout. Overridden per-session by --worktree-base.
AFK_WORKTREE_BOOT_PRUNEbooleanWhen set, the daemon prunes stale worktrees at boot in addition to the cron-driven sweep.
AFK_WORKTREE_BRANCH_PREFIXstringBranch-name prefix for AFK-managed worktrees. Default afk/. Set to empty string to drop the prefix.afk/
AFK_WORKTREE_MAX_AGE_CLEANnumberMaximum age (in days) before a clean worktree is auto-pruned. Default 14.14
AFK_WORKTREE_MAX_AGE_DIRTYnumberMaximum age (in days) before a dirty worktree is auto-pruned. Default 30.30
AFK_WORKTREE_PRUNE_DISABLEbooleanDisable the worktree prune job entirely. Useful for long-running tests.
AFK_WORKTREE_SWEEP_ROOTstringOverride the root directory under which AFK worktrees are tracked for pruning.

Paths

VariableTypeDescriptionDefault
AFK_FRAMEWORK_DIRstringOverride the AFK agent-framework directory used for telemetry and briefs. Default: $AFK_HOME/agent-framework/.
AFK_HOMEstringOverride the AFK home directory. Default: ~/.afk/.~/.afk
AFK_STATE_DIRstringOverride the entire AFK state tier (sessions/, todos/, transcripts/, memory/, daemon/, etc.), not just one subdirectory. Must be an absolute path (not /). Default: $AFK_HOME/state/.

Process

VariableTypeDescriptionDefault
AFK_SHELL_WRAPPERbooleanSet to 1 or true by the optional afk shell wrapper function (installed via afk shell-init). Signals that the parent shell has the wrapper active so the post-exit cd can fire.
AGENT_SURFACEstringInternal surface marker propagated to subprocesses. Identifies which AFK surface (cli, telegram, daemon) spawned the process.
ASCIINEMA_RECbooleanSet to 1 by asciinema rec while a session is being recorded. Triggers capture-mode.
CIstringStandard CI-detection convention. Auto-set by GitHub Actions, CircleCI, etc. Used to switch off TTY-only UX.
FORCE_COLORstringStandard Node convention. Force-enable ANSI color output even when stdout is not a TTY.
HOMEstringStandard Unix home directory. Used as the fallback when AFK_HOME is unset.
NO_COLORstringStandard convention (https://no-color.org). When set to any non-empty value, disables ANSI color output.
NO_UPDATE_NOTIFIERbooleanDisable the update-available notifier on CLI startup. Standard convention shared with many Node CLIs.
NODE_ENVstringStandard Node environment marker. test | development | production. Used by routing-telemetry.ts to suppress test-time writes.
PAGERstringStandard POSIX env var naming the user's preferred pager (with optional flags). Used by /transcript to render the full session in a scrollable viewer; falls back to less -R when unset.
PATHstringSystem PATH. Read for executable resolution (git, gh, etc.) in tool handlers.
SCRIPTstringSet by script(1) on BSD/macOS/Linux to the typescript filename while a terminal session is being recorded. Presence of a non-empty value triggers capture-mode.
SHELLstringStandard POSIX env var pointing to the user's login shell binary. Used by shell-init and worktree commands to auto-detect the correct shell syntax for emitted wrapper code.
VITESTstringSet automatically by Vitest. Used at runtime to short-circuit code paths that should not fire in tests.

Debug

VariableTypeDescriptionDefault
AFK_DEBUGbooleanEnable verbose debug logging across the codebase. Accepts 1 to enable.
AFK_DEBUG_CLIPBOARDbooleanDebug bracketed-paste and image-paste handling in the interactive REPL.
AFK_DEBUG_COMPOSITORbooleanGate compositor phase-boundary traces to stderr; any truthy value enables.
AFK_DIAGNOSE_BASELINEbooleanKill switch for /diagnose reproducer baseline execution. When set to '0', the /diagnose skill skips executing the detected reproducer command for a ground-truth baseline; default enabled (runs). Set to '0' to disable.1
AFK_DUMP_PROMPTstringWrite the resolved system prompt to a file at startup. Accepts a path or 1 for default location.
AFK_SESSION_LEDGER_DISABLEDbooleanDisable the per-session durable event ledger (state/sessions/<id>/events.jsonl). Set to 1 to skip ledger writes; live cross-surface watching (e.g. the Telegram /watch command) will report no activity for sessions started while disabled.
AFK_SKILL_STREAM_VERBOSEbooleanVerbose streaming output when a skill is dispatched. Logs sub-agent setup, intermediate events, and final result.
AFK_TELEGRAM_TRACEbooleanSet to 1 to dump raw bridge traffic between the agent and the Telegram bot — debugging only.
AFK_TRACE_DISABLEDbooleanDisable the agent trace subsystem entirely. Set to 1 to skip trace file writes.
AGENT_AFK_ASCIIbooleanForce the interactive REPL tool-lane renderer to ASCII-only glyphs instead of the default Unicode box-drawing set. Accepts 1/true/yes (case-insensitive). Useful for terminals whose font lacks ┃├╰├ glyphs.
DEBUGstringStandard Node debug-package convention. When set to 1, enables verbose logging in several modules alongside AFK_DEBUG.

Miscellaneous

VariableTypeDescriptionDefault
AFK_BANNER_PLAINbooleanSuppress the ANSI-colored banner at REPL startup. Useful for non-TTY captures and CI logs.
AFK_DEMO_CLEANbooleanExplicit opt-in to capture-mode. When set to 1, suppresses high-frequency repaint drivers (spinner ticker, live thinking-preview) so recorded artifacts contain each state once instead of once per timer tick.
AFK_DIFF_LINESnumberMaximum number of diff lines shown in the inline diff render during write_file tool calls. Set to 0 for no cap. Non-integer values are silently ignored and the default applies.
AFK_SHELL_PASSTHROUGHbooleanEnable the interactive REPL !cmd / !&cmd shell-passthrough feature. On by default. Set to 0, false, off, or no (case-insensitive) to disable, so inputs beginning with ! are sent to the model as literal text instead of being executed as shell commands. Equivalent to the --no-shell-passthrough flag.1
AFK_SHOW_DIFFSbooleanShow inline diffs in the tool-lane output for edit/write tool calls. 1 = on, 0 = off.
AFK_SPINNER_TIPSbooleanShow rotating tips in the loading spinner during long calls. 1 = on, 0 = off.
AFK_USER_CARD_MAX_ROWSnumberMaximum number of visual rows emitted by renderUserCard before collapsing the remainder into a dim "…(N lines collapsed)" summary row. Defaults to 24. Non-integer or non-positive values are silently ignored and the default applies.
AFK_WRITE_DENYLISTstringComma-separated list of additional path globs that the write_file tool refuses to write to.
AFK_WRITE_DIFFbooleanShow a diff preview before each write_file tool call. Defaults provider-controlled when unset.