cost-optimization-background-llm

cost-optimization-background-llm is a skill for Claude Code, Codex from humanerd-drew/opencode-drewgent. It costs 50 tokens per session (3,579 once invoked), scanned A, original, MIT.

A workflow for lowering the cost of language-model calls made by scheduled jobs and background workers while leaving interactive chat and command paths unchanged.

In plain words
What is it for?
Use it to review cron jobs, background tasks, and kanban workers; route necessary calls to a cheaper model; replace unnecessary calls with deterministic logic; and verify the result.
Why use it?
It helps find background calls that use an expensive model unnecessarily or use a model for work that could be handled by fixed code. It then checks that the changes had the intended effect.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: mentions OpenCode.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/humanerd-drew/opencode-drewgent/cost-optimization-background-llm
Any agent
npx skills add humanerd-drew/opencode-drewgent --skill cost-optimization-background-llm
Clone the repo
git clone --depth 1 https://github.com/humanerd-drew/opencode-drewgent

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cost-optimization-background-llm

README.md
[![agentmods](https://agentmods.dev/badge/skills/humanerd-drew/opencode-drewgent/cost-optimization-background-llm.svg)](https://agentmods.dev/skills/humanerd-drew/opencode-drewgent/cost-optimization-background-llm)
Your own site
<a href="https://agentmods.dev/skills/humanerd-drew/opencode-drewgent/cost-optimization-background-llm"><img src="https://agentmods.dev/badge/skills/humanerd-drew/opencode-drewgent/cost-optimization-background-llm.svg" alt="Measured on agentmods" height="20"></a>
Per session 50 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,579 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00050 $0.03579
Opus 5 $0.00025 $0.01790
Sonnet 5 $0.00010 $0.00716
Haiku 4.5 $0.00005 $0.00358

Measured 2d ago against content hash 4b305e15cea6, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

cost-optimization-background-llm scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

And add a `_run_script_subprocess()` helper that calls `subprocess.run()`
skills/software-development/cost-optimization-background-llm/SKILL.md · 324 lines

How it starts

The opening of the file, as written. The whole thing — 324 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Cost Optimization — Background LLM Calls

Reduce LLM token spend on background/scheduled work in {{AGENT_NAME}} without touching the user-facing interactive path (CLI / ACP / Discord messages). Terminal-direct calls are off-scope by user preference.

  • hermes-model-routing — broader framework for model selection across all 4 routing levels (main/delegation/auxiliary/provider_routing). This skill focuses on the cost dimension; the routing skill covers the complete selection framework.

When to use

Trigger words from user: "cost optimization", "background LLM", "cron LLM", "token cost", "cheap model", "스케줄 작업과 백그라운드".

Decision tree

Background LLM call site discovered
    │
    ├── (1) Is the LLM call essential?
    │     │
    │     ├── Yes (report synthesis, MCP query, instruction) → keep LLM
    │     │   but route to cheaper model via config.yaml
    │     │
    │     └── No (simple shell interpretation) → make deterministic
    │
    ├── (2) What cost lever is available?
    │     │
    │     ├── Smart-routing cheap_model != main model
    │     │   → config.yaml smart_model_routing.cheap_model.{provider,model}
    │     │
    │     ├── Auxiliary task model override
    │     │   → config.yaml auxiliary.{task}.{provider,model}
    │     │     tasks: vision, web_extract, compression, session_search,
    │     │            skills_hub, approval, mcp, flush_memories
    │     │
    │     ├── Script-based fast path (cron)
    │     │   → jobs.json add `script:` field + scheduler.py branch
    │     │
    │     └── Task body classification (kanban worker)
    │         → classify first non-empty line; shell-prefix → subprocess
    │
    └── (3) Verify with hard evidence, not just "Done ✅" claims.

Procedure (5 phases)

Phase 1 — Inventory

# 1a) Cron jobs: list all jobs
jq '.jobs[] | {id, name, enabled, schedule, last_status, last_run_at}' \
   ~/.{{AGENT_NAME_LOWER}}/cron/jobs.json

# 1b) Find scheduler entry point
grep -n "run_job\|run_conversation\|AIAgent" \
   ~/.{{AGENT_NAME_LOWER}}/source/{{AGENT_NAME_LOWER}}-agent/cron/scheduler.py

# 1c) Background threads / fire-and-forget
grep -rn "threading.Thread\|daemon=True" \
   ~/.{{AGENT_NAME_LOWER}}/source/{{AGENT_NAME_LOWER}}-agent/ | grep -v test_

# 1d) Kanban worker LLM path
grep -n "AIAgent\|agent.chat\|run_conversation" \
   ~/.{{AGENT_NAME_LOWER}}/scripts/run_kanban_worker.py

# 1e) Auxiliary task consumers
grep -rn "call_llm\|async_call_llm" \
   ~/.{{AGENT_NAME_LOWER}}/source/{{AGENT_NAME_LOWER}}-agent/agent/ | grep -v test_

Read the full file on GitHub · 324 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 324 lines · 50 tokens per session scan A 4b305e15cea6

Subscribe to this mod's changes

cost-optimization-background-llm is a skill published in the GitHub repository humanerd-drew/opencode-drewgent (2 stars, last pushed 1mo ago), licensed MIT. It adds 50 tokens to every session and 3,579 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

ml-training-recipes

Battle-tested PyTorch training recipes for all domains — LLMs, vision, diffusion, medical imaging, protein/drug discovery, spatial omics, genomics. Covers training loops, optimizer selection (AdamW, Muon), LR scheduling, mixed precision, debugging, and systematic experimentation. Use when training or fine-tuning…

Orchestra-Research/AI-Research-SKILLs · 88 tokens

map

Build and commit a Cortex function knowledge graph — maps structural dependencies and domain intent relationships across all AI functions in the project. Supports --reduce (default on) for transitive reduction of the dependency graph.

Snowflake-Labs/cocoplus · 42 tokens

context-add

Guided wizard to capture or update organizational Snowflake/Cortex standards into .cocoplus/context/ .md. Presents a menu of 6 standard types, collects answers via multi-turn dialogue, and commits the file.

Snowflake-Labs/cocoplus · 48 tokens

cocolean

CocoLean — minimum viable Cortex surface discipline. Pre-build decision ladder and intensity mode management. Invoke with $lean, $lean lite, $lean full, or $lean ultra.

Snowflake-Labs/cocoplus · 41 tokens

test

Enter the Test phase of CocoBrew. Reads spec.md test requirements, generates test cases, executes SQL validation and quality checks, records results in test.md. Can be re-run without full rebuild. Requires Build phase completion.

Snowflake-Labs/cocoplus · 47 tokens

map-diff

Analyze the impact of staged git changes against the committed Cortex function knowledge graph — shows which downstream functions are affected before you commit.

Snowflake-Labs/cocoplus · 28 tokens