Lesson
Control the Exact Context You Give Claude Code with Repomix and Gomplate Plugins
Take control of your AI’s context. Learn to build a gomplate plugin that runs repomix for precise, repeatable prompts using exactly the files you define.
- 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
- Create a
.gomplate.yaml: This file defines your custom commands, or "plugins." - Define the Plugin: Map a plugin name (e.g.,
repomix) to a shell command. We'll use therepomixCLI with flags like--stdoutand--includeto specify which files to bundle. - Use the Plugin in a Template: In a text file (e.g.,
prompt.txt), use{{ repomix }}to call your custom command. - Execute and Pipe: Run
gomplatewith your template file. It will execute therepomixcommand, 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.
repomix
The --stdout flag pipes the output directly to the terminal instead of creating a file.
repomix --stdout
You can precisely control the output by combining flags to include specific files and remove the file summary.
repomix --include "package.json,index.ts" --no-file-summary --stdout
Find the executable path for a command and copy it to the clipboard.
which repomix | pbcopy
Execute gomplate using a template file.
gomplate -f prompt.txt
Execute gomplate and pipe the final rendered prompt to the Claude CLI.
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.