config Command
The config
command provides an interactive terminal interface for viewing and editing Claude Code's configuration settings, including model settings, UI preferences, and API keys.
Implementation
The command is implemented in commands/config.tsx
as a type: 'local-jsx' command that renders a React component:
import { Command } from "../commands";
import { Config } from "../components/Config";
import * as React from "react";
const config = {
type: "local-jsx",
name: "config",
description: "Open config panel",
isEnabled: true,
isHidden: false,
async call(onDone) {
return <Config onClose={onDone} />;
},
userFacingName() {
return "config";
},
} satisfies Command;
export default config;
Like the bug
command, this command uses JSX to render an interactive UI component. The actual functionality is implemented in the Config
component located in components/Config.tsx
.
UI Component
The Config
component implements a rich terminal-based settings interface with the following features:
-
Settings Management: Displays a list of configurable settings with their current values.
-
Multiple Setting Types: Supports various setting types:
boolean
: Toggle settings (true/false)enum
: Options from a predefined liststring
: Text input valuesnumber
: Numeric values
-
Interactive Editing: Allows users to:
- Navigate settings with arrow keys
- Toggle boolean and enum settings with Enter/Space
- Edit string and number settings with a text input mode
- Exit configuration with Escape
-
Configuration Persistence: Saves settings to a configuration file using
saveGlobalConfig
.
Configuration Options
The component exposes numerous configuration options, including:
-
Model Configuration:
- AI Provider selection (anthropic, openai, custom)
- API keys for small and large models
- Model names for both small and large models
- Base URLs for API endpoints
- Max token settings
- Reasoning effort levels
-
User Interface:
- Theme selection (light, dark, light-daltonized, dark-daltonized)
- Verbose output toggle
-
System Settings:
- Notification preferences
- HTTP proxy configuration
Technical Implementation Notes
The Config
component demonstrates several advanced patterns:
-
State Management: Uses React's
useState
to track:- Current configuration state
- Selected setting index
- Editing mode state
- Current input text
- Input validation errors
-
Reference Comparison: Maintains a reference to the initial configuration using
useRef
to track changes. -
Keyboard Input Handling: Implements sophisticated keyboard handling for navigation and editing:
- Arrow keys for selection
- Enter/Space for toggling/editing
- Escape for cancellation
- Input handling with proper validation
-
Input Sanitization: Cleans input text to prevent control characters and other problematic input.
-
Visual Feedback: Provides clear visual indication of:
- Currently selected item
- Editing state
- Input errors
- Available actions
-
Change Tracking: Tracks and logs configuration changes when exiting.
User Experience Design
The config component showcases several UI/UX design principles for terminal applications:
-
Modal Interface: Creates a focused settings panel that temporarily takes over the terminal.
-
Progressive Disclosure: Shows relevant controls and options based on the current state.
-
Clear Instructions: Displays context-sensitive help text at the bottom of the interface.
-
Visual Highlighting: Uses color and indicators to show the current selection and editing state.
-
Immediate Feedback: Changes take effect immediately, with visual confirmation.
-
Multiple Input Methods: Supports keyboard navigation, toggling, and text input in a unified interface.
-
Safe Editing: Provides validation and escape routes for configuration editing.
The config
command demonstrates how Claude Code effectively combines the simplicity of terminal interfaces with the rich interaction capabilities typically associated with graphical applications, creating a powerful yet accessible configuration experience.