Course lesson

Control the Exact Context You Give Claude Code with Repomix and Gomplate Plugins

Relying on an AI's built-in tools to read your project files can be unpredictable. You might not know exactly what context is being used, making it difficult to create reliable and repeatable workflows. This lesson introduces a powerful solution: combining...

Duration
3 min
Access
Included
Transcript
Needs source

Relying on an AI's built-in tools to read your project files can be unpredictable. You might not know exactly what context is being used, making it difficult to create reliable and repeatable workflows. This lesson introduces a powerful solution: combining the gomplate templating engine with custom plugins to gain absolute control over the context you provide to an AI.

This lesson demonstrates how to create a custom gomplate plugin that uses repomix—a CLI tool for bundling repository files. By defining a simple command in a YAML configuration, you can dynamically inject the precise contents of your project files into any prompt template. This allows you to bypass the AI's internal tooling entirely, feeding it the exact information it needs to perform a task.

The result is a highly deterministic and reusable system for prompt engineering. You'll learn to compose complex prompts from multiple files, shell command outputs, and static text, giving you the power to build sophisticated and reliable automation pipelines for interacting with AI models like Claude.

How it Works

  1. Create a .gomplate.yaml: This file defines your custom commands, or "plugins."
  2. Define the Plugin: Map a plugin name (e.g., repomix) to a shell command. We'll use the repomix CLI with flags like --stdout and --include to specify which files to bundle.
  3. Use the Plugin in a Template: In a text file (e.g., prompt.txt), use {{ repomix }} to call your custom command.
  4. Execute and Pipe: Run gomplate with your template file. It will execute the repomix command, inject its output into the template, and print the final, context-rich prompt. This can then be piped directly to an AI model.

Key Benefits

  • Precise Context Control: You decide exactly which files and what content the AI sees.
  • Reusable Workflows: Create standardized prompts that can be run repeatedly for consistent results.
  • Bypass AI Tooling: Avoid reliance on an AI's potentially flaky or opaque file-reading capabilities.
  • Powerful Composition: Combine the output of any CLI tool with static text and other template functions to build complex prompts.

Commands

The repomix tool bundles all project files by default.

Terminal
repomix

The --stdout flag pipes the output directly to the terminal instead of creating a file.

Terminal
repomix --stdout

You can precisely control the output by combining flags to include specific files and remove the file summary.

Terminal
repomix --include "package.json,index.ts" --no-file-summary --stdout

Find the executable path for a command and copy it to the clipboard.

Terminal
which repomix | pbcopy

Execute gomplate using a template file.

Terminal
gomplate -f prompt.txt

Execute gomplate and pipe the final rendered prompt to the Claude CLI.

Terminal
gomplate -f prompt.txt | claude -p

Code Snippets

A simple prompt template that uses a custom repomix command to inject file context.

Please analyze these files:

{{ repomix }}

List 3 ways to improve the code.

The .gomplate.yaml configuration defines a custom repomix plugin, specifying the command path and the arguments to run.

plugins:
  repomix:
    cmd: /Users/johnlindquist/.npm-global/bin/repomix
    args: ["--stdout", "--include", "**/*.json,**/*.ts", "--no-file-summary"]

A more advanced prompt template that composes multiple files and a custom command.

{{ file.Read "prompts/tone.txt" }}
{{ file.Read "prompts/steps.txt" }}

Please analyze these files:

{{ repomix }}

List 3 ways to improve the code.