KCode CLIConfiguration

KCode Configuration

Config Files

FilePurpose
~/.kcode/settings.jsonGlobal settings
.kcode/settings.jsonProject-level settings
.kcode/settings.local.jsonLocal overrides (gitignored)
~/.kcode/models.jsonModel registry
KCODE.mdPer-project instructions (like .cursorrules)
.kcode/rules/Per-project rule files
~/.kcode/permissions.jsonGlobal permission rules
.kcode/permissions.jsonProject permission rules
~/.kcode/agents/Custom agent definitions
.kcode/agents/Project-scoped agents

Settings Priority

Highest priority first:

  1. CLI flags (--model, --permission, etc.)
  2. Managed policy locked settings (enterprise)
  3. Environment variables (KCODE_MODEL, etc.)
  4. .kcode/settings.local.json
  5. .kcode/settings.json
  6. ~/.kcode/settings.json

Settings

// ~/.kcode/settings.json
{
  "theme": "dark",
  "permissionMode": "ask",
  "maxTokens": 8192,
  "mcpServers": {},
  "hooks": {}
}

Model Registry

# List configured models
kcode models list
 
# Add a model
kcode models add mnemo:mark5 --url http://localhost:10091
 
# Set default model
kcode models default mnemo:mark5
 
# Remove a model
kcode models rm old-model

Models are stored in ~/.kcode/models.json:

{
  "models": {
    "mnemo:mark5": {
      "url": "http://localhost:10091",
      "default": true
    }
  }
}

Environment Variables

VariableDescription
KCODE_MODELOverride default model
KCODE_API_BASEOverride API base URL
KCODE_API_KEYAPI key for remote providers

Project Rules

Create KCODE.md in your project root to give KCode project-specific instructions:

# Project Rules
 
- Use TypeScript strict mode
- All API responses must include error handling
- Tests go in __tests__/ directories
- Use pnpm, not npm

KCode loads this file at the start of every conversation in that project.

Permission Rules

Define fine-grained permission rules in ~/.kcode/permissions.json:

{
  "rules": [
    { "pattern": "Edit(src/**)", "action": "allow" },
    { "pattern": "Bash(rm *)", "action": "deny" },
    { "pattern": "Edit(/etc/**)", "action": "deny" }
  ]
}

Hooks

Configure lifecycle hooks in settings to run commands, inject prompts, or call webhooks on events:

{
  "hooks": {
    "PreToolUse": [
      {
        "type": "command",
        "command": "echo 'Tool about to run'",
        "matcher": { "toolName": "Bash" }
      }
    ],
    "PostToolUse": [
      {
        "type": "http",
        "url": "https://hooks.example.com/audit",
        "method": "POST",
        "auth": "your-token"
      }
    ],
    "SessionStart": [
      {
        "type": "prompt",
        "prompt": "Remember: always write tests first"
      }
    ]
  }
}

Hook Events

28 hook events available:

EventDescription
SessionStart / SessionEndSession lifecycle
PreToolUse / PostToolUseBefore/after any tool execution
PostToolUseFailureWhen a tool call errors
PreEdit / PostEditBefore/after file edits
PreBash / PostBashBefore/after bash commands
PreWrite / PostWriteBefore/after file creation
PreCompact / PostCompactBefore/after context compaction
UserPromptSubmitWhen user sends a message
SubagentStart / SubagentStopAgent lifecycle
ModelSwitchWhen model routing switches
ContextOverflowWhen context nears capacity
NotificationDesktop notifications

Hook Types

TypeDescription
commandRun a shell command (receives JSON on stdin)
promptInject text into the conversation context
httpPOST JSON to a webhook URL (supports auth for Bearer tokens)

Custom Agents

Define custom agents as .md files with YAML frontmatter in ~/.kcode/agents/:

---
name: reviewer
description: Code review specialist
model: mnemo:mark5-max
tools: [Read, Glob, Grep]
permissionMode: deny
maxTurns: 10
effort: high
memory: true
hooks:
  [{"event": "SubagentStart", "actions": [{"type": "command", "command": "echo reviewing"}]}]
---
 
You are a senior code reviewer. Focus on:
- Security vulnerabilities
- Performance issues
- Code quality and readability

Then use it: kcode --agent reviewer "review the auth module"