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

John Lindquist
InstructorJohn Lindquist

Social Share Links

Tweet

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.

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.

[00:00] Inside of your prompt you can also create arbitrary commands which you map to a file called gomplate.yaml. I'll bring this over here and these commands are treated as plugins. So we'll call this plugin RepoMix and then we'll pass in the path to RepoMix. And if you're not familiar with RepoMix, after you install it using the npm global install, we'll take all of the files inside of your project and then bundle them up into a single file. Now we can also say RepoMix standard out, and instead of bundling up into a file it will pipe it through standard out.

[00:37] And there are also many other flags as far as customizing what is output around which files you want to include, or including diffs, or this time we're going to focus on no file summary, meaning that once I come down and I run repo mix include package.json, And this could just be a comma delimited list of files, the package.json and index.ts, and then just paste in the no file summary flag and then standard out. You'll see we'll get an XML separated list of files showing the directory structure. These are both in the root and then the files and all of their contents where the index is simply that and the package.json is this. So this will allow me to take that same command. I'm going to find where RepoMix is installed and pb copy it to the clipboard.

[01:35] So in my configuration we could paste the full path and then in the arguments we have standard out we can include package.json and for now let's just do all of the JSON files and all the TypeScript files. And so now when I run my GOM plate and I include the prompt file, this will take my prompt template and it looks like it's not recognizing RepoMix. I think I made the mistake of naming this .yml, or it should be .yaml. That's usually an interchangeable extension, but we'll try it again. And now we have our template.

[02:15] That's three ways to improve the code. And then the output of the RepoMix plugin. So everything inside of here, and then the beginning of our template. So now we can compose together various files. Let's say file, read, prompts, tone, file, read, prompts, steps, then just leave list three ways to improve the code.

[02:35] Since this code is simply boilerplate it won't probably give us too much to work with. But we'll run our GOM plate, load the prompt, pass it to Claude with the print flag, hit enter, and then in the result you can see the tone, you can see the steps, you can see that it knew about the package.json, saying we should probably add a linter, talks about updating the main index file, And it did all of this without Cloud Code using any of its tools to read or grep or list or find any files. We're essentially forcing the exact context we want with the purpose of building reusable workflows.