optimize-dockerfile

optimize-dockerfile is a command for Claude Code from rohitg00/awesome-claude-code-toolkit. It costs 22 tokens per session (441 once invoked), scanned A, original, Apache-2.0.

A command that improves an existing Dockerfile, the recipe used to build a container image. It targets image size, build speed, caching, and security while checking that the result still runs.

In plain words
What is it for?
Use it to apply multi-stage builds, better instruction ordering, cache mounts, smaller bases, non-root execution, versioned images, and health checks.
Why use it?
It removes unnecessary files, layers, packages, and build tools from the final image, which can reduce storage and attack surface and improve repeat builds.

Command for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the docker-helper plugin — 2 commands shipped together

Good fit Use it to apply multi-stage builds, better instruction ordering, cache mounts, smaller…

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/rohitg00/awesome-claude-code-toolkit/optimize-dockerfile
About the project

Awesome Claude Code Toolkit is a curated collection of extensions and configuration for Claude Code, including agents, skills, commands, plugins, hooks, rules, templates, MCP configurations, and companion apps. It is for Claude Code users who want ready-made workflows and integrations for different development tasks. The catalogue add-ons are selected components from this toolkit.

rohitg00/awesome-claude-code-toolkit · 2,593 stars · on GitHub

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.

Clone the repo
git clone --depth 1 https://github.com/rohitg00/awesome-claude-code-toolkit

Made for: Claude Code.

Or install docker-helper, the plugin that ships this one along with the rest of its 2 commands.

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 optimize-dockerfile

README.md
[![agentmods](https://agentmods.dev/badge/commands/rohitg00/awesome-claude-code-toolkit/optimize-dockerfile.svg)](https://agentmods.dev/commands/rohitg00/awesome-claude-code-toolkit/optimize-dockerfile)
Your own site
<a href="https://agentmods.dev/commands/rohitg00/awesome-claude-code-toolkit/optimize-dockerfile"><img src="https://agentmods.dev/badge/commands/rohitg00/awesome-claude-code-toolkit/optimize-dockerfile.svg" alt="Measured on agentmods" height="20"></a>
Per session 22 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 441 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.00022 $0.00441
Opus 5 $0.00011 $0.00220
Sonnet 5 $0.00004 $0.00088
Haiku 4.5 $0.00002 $0.00044

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

Security

Grade A, and why

optimize-dockerfile scanned grade A with 0 findings 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 3d 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/docker-helper/commands/optimize-dockerfile.md · 55 lines

What it actually says

Optimize an existing Dockerfile for smaller images, faster builds, and better security.

Steps

  1. Read the existing Dockerfile and analyze each instruction.
  2. Check for size optimization opportunities:
    • Use Alpine or distroless base images where possible.
    • Combine RUN commands to reduce layers.
    • Remove package manager caches in the same layer as installs.
    • Use multi-stage builds to exclude build tools from the final image.
    • Copy only necessary files, not the entire context.
  3. Check for build cache optimization:
    • Order instructions from least to most frequently changing.
    • Copy dependency files before source code.
    • Use --mount=type=cache for package manager caches.
  4. Check for security best practices:
    • Use specific version tags for base images.
    • Run as non-root user: USER <non-root>.
    • Set HEALTHCHECK instruction.
    • Do not store secrets in environment variables or build args.
    • Minimize installed packages to reduce attack surface.
  5. Apply optimizations and compare before/after image sizes.
  6. Verify the optimized image still runs correctly.

Format

Dockerfile Optimization: <path>

Before: <size>MB, <layers> layers
After: <size>MB, <layers> layers
Reduction: <percent>%

Changes:
  1. Switched base from node:20 to node:20-alpine (-600MB)
  2. Combined 5 RUN commands into 2 (-3 layers)
  3. Added multi-stage build, excluded devDependencies (-200MB)
  4. Added non-root USER instruction (security)

Verification: container starts and passes health check

Rules

  • Always test the optimized image before recommending changes.
  • Do not sacrifice build reliability for marginal size gains.
  • Preserve build cache efficiency; do not combine steps that change independently.
  • Keep security fixes separate from optimization changes for clear review.
  • Document why each base image was chosen.
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. 3d ago First seen · 55 lines · 22 tokens per session scan A ff7825baf684

Subscribe to this mod's changes

optimize-dockerfile is a command published in the GitHub repository rohitg00/awesome-claude-code-toolkit (2,593 stars, last pushed 3mo ago), licensed Apache-2.0. It adds 22 tokens to every session and 441 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.