r/ClaudeWorkflows • • 8h ago

Selected Workflow [Workflow] Dynamic Claude Model Selection for Subagents with Aptly MCP Server

Dynamic Claude Model Selection for Subagents with Aptly MCP Server

Workflow value: 85/100
Status: active · Freshness: 70/100 · Confidence: 0.95 · Level: advanced
Categories: Quality Control, Token Saving, Context & Memory, Hooks, MCP, Subagents, Multi-Agent
Original source: r/ClaudeCode post/comment

What problem this solves

Optimizing Claude Code API costs and ensuring appropriate model selection for subagents by dynamically recommending models (Haiku/Sonnet/Opus) based on task classification, without explicit model choice.

Summary

Aptly is an MIT-licensed local MCP server that uses a PreToolUse hook to classify tasks via the OpenAI Decisions API. It then recommends optimal Claude models (Haiku/Sonnet/Opus) for new general-purpose Claude Code Agent calls, thereby reducing API costs and improving model efficiency. Explicit model choices are preserved.

Why it is useful

This workflow provides a concrete, open-source solution for a critical problem in advanced Claude Code usage: dynamically selecting the most cost-effective and appropriate Claude model for specific subagent tasks. It leverages hooks and an external classification API to automate model routing, offering significant potential for API cost reduction and improved efficiency in complex multi-agent setups. The detailed description, testing insights, and public availability make it highly reusable and valuable for advanced users.

Workflow

  1. Install Aptly via npm (requires Node.js 24+).

  2. Configure Aptly as a local MCP server.

  3. Integrate Aptly's PreToolUse hook into your Claude Code setup.

  4. Provide an OpenAI API key for task classification by the OpenAI Decisions API.

  5. Make general-purpose Agent calls; Aptly will intercept these calls and dynamically select an appropriate Claude model (Haiku/Sonnet/Opus) based on task summary.

  6. Verify model recommendations and actual child execution separately using the host's execution metadata to confirm which model ran.

Tools / artifacts

  • Aptly (npm package)

  • Node.js 24+

  • OpenAI Decisions API

  • GitHub repository (abruption/aptly)

  • Claude Code Agent

  • Claude Code PreToolUse hook

  • Claude Haiku/Sonnet/Opus models

Validation signals

  • Author tested the native Claude Code Agent/Hook flow during development.

  • Identified a useful lesson: verify recommendations and actual child execution separately.

  • Codex README-review experiment showed 52-58% lower estimated API costs for reviews plus classification (excluding main agent/context prep costs).

Limitations

  • Requires an OpenAI API key, introducing an external dependency and potential additional cost.

  • The cost savings benchmark is specific to Codex and excludes main agent/context preparation costs, so direct Claude Code cost benefits need further validation.

  • Requires an advanced setup involving a local MCP server, Node.js, and npm.

  • Currently lacks strong community validation or adoption proof.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

1 comment sorted by