Skip to main content

Overview

RTK provides token-optimized alternatives for Docker and Kubernetes commands. Achieve 80%+ token savings through:
  • Compact lists: Tabular format with essential info only
  • Aggregation: Show counts and summaries
  • Smart truncation: Limit output to most relevant items
  • Deduplication: Collapse repeated log lines

Docker Commands

rtk docker ps

Compact container list with essential details.

Examples

Features

  • Container ID: Truncated to 12 chars
  • Name: Container name
  • Image: Short image name (strip registry prefix)
  • Ports: Compact port mapping
  • Truncation: Max 15 containers shown

Implementation

From src/container.rs:docker_ps():

rtk docker images

Compact image list with size aggregation.

Examples

Features

  • Total size: Aggregated across all images
  • Short names: Repository:tag format
  • Size units: Automatic MB/GB conversion
  • Truncation: Max 15 images shown

rtk docker logs

Deduplicated container logs.

Examples

Features

  • Deduplication: Collapse repeated lines with count
  • Timestamp preservation: Keep first occurrence timestamp
  • Error highlighting: Preserve all error lines
  • Tail support: Works with --tail flag

Kubernetes Commands

rtk kubectl pods

Compact pod list with namespace support.

Examples

Features

  • Ready status: Container ready count
  • Restart count: Show if > 0
  • Status icons: βœ“ (Running), βœ— (Failed), ⏸ (Pending)
  • Namespace: Optional -n flag support

rtk kubectl services

Compact service list.

Examples

Features

  • Service type: ClusterIP, NodePort, LoadBalancer
  • Cluster IP: Internal IP
  • Port mapping: Internal β†’ external (for NodePort)
  • Truncation: Max 15 services

rtk kubectl logs

Deduplicated pod logs.

Examples

Features

  • Deduplication: Collapse repeated log lines
  • Multi-container: Works with -c container flag
  • Follow mode: Compatible with -f flag
  • Namespace: Works with -n flag

Common Patterns

Container Lists

All list commands follow this pattern:
  1. Execute with --format for structured output
  2. Parse fields (ID, name, image, status, ports)
  3. Compact long strings (truncate IDs, strip registry)
  4. Group similar items
  5. Show count + top N items

Log Deduplication

All log commands use this algorithm:

Exit Code Preservation

All container commands preserve exit codes:

Implementation Reference

Key functions in src/container.rs:
  • docker_ps(): Parses docker ps --format output
  • docker_images(): Aggregates image sizes
  • docker_logs(): Deduplicates log lines
  • kubectl_pods(): Parses kubectl get pods -o json
  • kubectl_services(): Parses service JSON
  • kubectl_logs(): Deduplicates pod logs

Port Compaction

Strips:
  • 0.0.0.0: prefix
  • /tcp suffix
  • Whitespace

Image Name Shortening

Token Savings Summary

Next Steps

Testing

Test runner optimizations

JavaScript

Modern JS/TS stack tools