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

$ docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS                    NAMES
abc123456789   nginx:latest             "/docker-entrypoint.…"   2 hours ago     Up 2 hours     0.0.0.0:8080->80/tcp    web-server
def987654321   postgres:14-alpine       "docker-entrypoint.s…"   3 hours ago     Up 3 hours     0.0.0.0:5432->5432/tcp  db
ghi555666777   redis:7-alpine           "docker-entrypoint.s…"   1 day ago       Up 1 day       0.0.0.0:6379->6379/tcp  cache
...
# 20+ lines, ~900 tokens

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():
// Uses docker --format for structured output
docker ps --format "{{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}\t{{.Ports}}"

// Compacts port mappings
"0.0.0.0:8080->80/tcp, 0.0.0.0:8443->443/tcp""8080:80,8443:443"

rtk docker images

Compact image list with size aggregation.

Examples

$ docker images
REPOSITORY               TAG       IMAGE ID       CREATED         SIZE
nginx                    latest    abc123456789   2 weeks ago     142MB
postgres                 14-alpine def987654321   3 weeks ago     231MB
redis                    7-alpine  ghi555666777   1 month ago     32MB
node                     18-alpine jkl888999000   2 months ago    174MB
...
# 20+ lines, ~800 tokens

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

$ docker logs web-server --tail 50
2024-01-23 10:00:01 GET /api/users 200
2024-01-23 10:00:02 GET /api/users 200
2024-01-23 10:00:03 GET /api/users 200
2024-01-23 10:00:04 GET /api/posts 200
2024-01-23 10:00:05 GET /api/users 200
...
# 50 lines, ~1500 tokens

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

$ kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
web-deployment-abc123-xyz456        1/1     Running   0          2d
api-deployment-def789-uvw123        1/1     Running   1          5d
worker-deployment-ghi456-rst789     2/2     Running   0          1d
db-statefulset-0                    1/1     Running   0          10d
...
# 20+ lines, ~900 tokens

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

$ kubectl get svc
NAME           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
web-service    ClusterIP   10.96.0.1       <none>        80/TCP           10d
api-service    NodePort    10.96.0.2       <none>        8080:30080/TCP   5d
db-service     ClusterIP   10.96.0.3       <none>        5432/TCP         20d
...
# 15+ lines, ~700 tokens

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

$ kubectl logs web-deployment-abc123-xyz456 --tail=50
2024-01-23 10:00:01 INFO: Server started on port 8080
2024-01-23 10:00:02 INFO: Request received GET /health
2024-01-23 10:00:03 INFO: Request received GET /health
2024-01-23 10:00:04 INFO: Request received GET /health
2024-01-23 10:00:05 INFO: Request received GET /api/users
...
# 50 lines, ~1800 tokens

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:
// From src/log_cmd.rs
for line in logs {
    if line == previous_line {
        count += 1
    } else {
        if count > 1 {
            output.push(format!("{} (x{})", previous_line, count))
        } else {
            output.push(previous_line)
        }
        count = 1
        previous_line = line
    }
}

Exit Code Preservation

All container commands preserve exit codes:
rtk docker ps || echo "Docker daemon not running"
rtk kubectl get pods -n production || echo "Namespace not found"

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

// From src/container.rs:compact_ports()
"0.0.0.0:8080->80/tcp, 0.0.0.0:8443->443/tcp"

"8080:80,8443:443"
Strips:
  • 0.0.0.0: prefix
  • /tcp suffix
  • Whitespace

Image Name Shortening

// From src/container.rs:docker_images()
"registry.example.com/org/nginx:latest"

"nginx:latest"

Token Savings Summary

CommandStandard TokensRTK TokensSavings
docker ps (10 containers)900180-80%
docker images (15 images)800150-81%
docker logs --tail 501,500450-70%
kubectl get pods (20 pods)900180-80%
kubectl logs --tail 501,800400-78%

Next Steps

Testing

Test runner optimizations

JavaScript

Modern JS/TS stack tools