Skip to content

Conversation

@quentincherifi
Copy link

Summary

Add optional AI assistant powered by Claude to help users troubleshoot and understand Kubernetes resources directly from K9s.

  • Context-aware AI that understands current cluster, namespace, and resources
  • Interactive chat view accessible via :claude or :ai commands
  • API key management via :claude set-key or config file
  • System prompt includes K8s context for relevant answers

Usage

# Set Anthropic API key
:claude set-key <your-api-key>

# Open AI chat view
:claude

# Ask a question directly
:claude why is my pod crashing?
:ai what's causing high memory usage?

Configuration

k9s:
  ai:
    enabled: true
    apiKey: "sk-ant-..."
    # or use environment variable
    apiKeyEnv: "ANTHROPIC_API_KEY"
    model: "claude-sonnet-4-20250514"
    maxTokens: 4096

New Files

  • internal/ai/client.go: Claude API client
  • internal/ai/context.go: K8s context builder for prompts
  • internal/config/ai.go: AI configuration
  • internal/view/claude.go: Claude chat view

Privacy

  • API key stored locally in K9s config file
  • Queries sent directly to Anthropic's API
  • No data collection or telemetry

Test plan

  • Build passes
  • All existing tests pass
  • Manual testing of :claude and :ai commands
  • API key persistence works
  • Chat history maintained during session

🤖 Generated with Claude Code

Add optional AI assistant powered by Claude to help users troubleshoot
and understand Kubernetes resources directly from K9s.

Features:
- Context-aware AI that understands current cluster, namespace, and resources
- Interactive chat view accessible via :claude or :ai commands
- API key management via :claude set-key or config file
- System prompt includes K8s context for relevant answers

Usage:
  :claude set-key <api-key>  - Set Anthropic API key
  :claude                    - Open AI chat view
  :claude <question>         - Ask a question directly
  :ai <question>             - Alias for :claude

Configuration (config.yaml):
  k9s:
    ai:
      enabled: true
      apiKey: "sk-ant-..."
      # or use environment variable
      apiKeyEnv: "ANTHROPIC_API_KEY"
      model: "claude-sonnet-4-20250514"
      maxTokens: 4096

New files:
- internal/ai/client.go: Claude API client
- internal/ai/context.go: K8s context builder for prompts
- internal/config/ai.go: AI configuration
- internal/view/claude.go: Claude chat view

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant