Skip to main content
ubx optimize reads .xcl files and recent cost history, then uses AI to identify concrete cost-saving opportunities. Recommendations are classified as FIX (auto-applicable) or ADV (advisory).

Usage

ubx optimize [flags]

Flags

FlagDescription
--applyInteractively apply fixable (FIX) recommendations
--format <fmt>Output format: text, json
--min-saving <amount>Only show recommendations saving ≥ this amount per month (USD)

Requirements

Requires UBX_AI_API_KEY or ai { enabled = true } in workspace config.

Examples

ubx optimize                          # show all recommendations
ubx optimize --min-saving 10          # only savings >= $10/mo
ubx optimize --apply                  # interactively apply fixes
ubx optimize --format json            # JSON output for CI/dashboards

Output

  FIX    networking/stack.xcl:14  aws.ec2.Instance  Downsize t3.large → t3.micro  (-$52.00/mo)
  ADV    —                        aws.rds.Instance  Purchase Reserved Instance     (-$120.00/mo)
  ADV    —                        aws.ec2.Instance  Switch to Spot for batch jobs  (-$35.00/mo)

  ─── Summary ──────────────────────────────────────────────
  1 fixable · 2 advisory
  Potential savings: -$207.00/mo  (fixable: -$52.00/mo · advisory: -$155.00/mo)
  Run 'ubx optimize --apply' to apply fixable recommendations.

Recommendation types

TypeDescription
FIXModifies a .xcl attribute in-place — instance size, feature toggles, storage tier
ADVAdvisory action in the cloud console — Reserved Instances, Spot, CDN, etc.

Interactive apply

ubx optimize --apply
For each FIX recommendation:
  FIX  networking/stack.xcl:14 — t3.large → t3.micro  (-$52.00/mo)
  Apply this fix? [y/N/s(kip all)]
  • y — apply the fix (rewrites the .xcl file)
  • N — skip this recommendation
  • s — skip all remaining recommendations
After applying, ubx runs ubx fmt on modified files.

JSON output

{
  "recommendations": [
    {
      "type": "FIX",
      "file": "networking/stack.xcl",
      "line": 14,
      "resource": "aws.ec2.Instance",
      "description": "Downsize instance from t3.large to t3.micro",
      "from": "t3.large",
      "to": "t3.micro",
      "saving": 52.00
    }
  ]
}

AI model

Uses configPkg.DefaultAIModel (claude-haiku-4-5). Override in workspace config.