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
Fromsrc/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
--tailflag
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
-nflag 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
-ccontainer flag - Follow mode: Compatible with
-fflag - Namespace: Works with
-nflag
Common Patterns
Container Lists
All list commands follow this pattern:- Execute with
--formatfor structured output - Parse fields (ID, name, image, status, ports)
- Compact long strings (truncate IDs, strip registry)
- Group similar items
- 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 insrc/container.rs:
docker_ps(): Parsesdocker ps --formatoutputdocker_images(): Aggregates image sizesdocker_logs(): Deduplicates log lineskubectl_pods(): Parseskubectl get pods -o jsonkubectl_services(): Parses service JSONkubectl_logs(): Deduplicates pod logs
Port Compaction
0.0.0.0:prefix/tcpsuffix- Whitespace
Image Name Shortening
Token Savings Summary
| Command | Standard Tokens | RTK Tokens | Savings |
|---|---|---|---|
docker ps (10 containers) | 900 | 180 | -80% |
docker images (15 images) | 800 | 150 | -81% |
docker logs --tail 50 | 1,500 | 450 | -70% |
kubectl get pods (20 pods) | 900 | 180 | -80% |
kubectl logs --tail 50 | 1,800 | 400 | -78% |
Next Steps
Testing
Test runner optimizations
JavaScript
Modern JS/TS stack tools
