How to Enable Auto-Injection of the Repo Map in OpenClaude: 3 Configuration Methods
Add "repoMap": true to your ~/.openclaude.json configuration file, pass the --repo-map CLI flag, or set the OPENCLAUDE_REPO_MAP=1 environment variable to automatically build and inject the repository map into every session's system context.
OpenClaude uses a repo map—a token-budgeted, PageRank-weighted representation of your codebase—to give the model instant awareness of file structures and relationships. When you enable auto-injection via the repoMap flag, the map is built at startup by buildRepoMap in src/context/repoMap/renderer.ts and embedded directly into the system context under the key repoMap (as defined in src/context.ts), eliminating the need to manually trigger the /repomap command.
What Is the Repo Map and Why Auto-Inject It?
The repo map is a compressed summary of your repository that includes filenames, tags, and a PageRank-style relevance score for each file. It is constructed by crawling the git file tree in src/context/repoMap/gitFiles.ts and ranking components using a token-budgeted algorithm in src/context/repoMap/renderer.ts.
Without auto-injection, you must manually request the map during each session. By enabling the flag, the map is automatically attached to the systemContext object that is supplied to every Session instance in src/assistant/sessionHistory.ts. This allows the model to reference files, imports, and dependencies immediately without explicit commands.
Configuration Methods to Enable Auto-Injection
You can enable auto-injection of the repo map through three complementary interfaces. All methods reference the same settings schema defined in src/utils/settings/settings.ts.
1. JSON Configuration File (Persistent)
The recommended approach for daily usage is editing the global configuration file.
- Open or create
~/.openclaude.json(or the file pointed to byOPENCLAUDE_CONFIG_DIR):
nano ~/.openclaude.json
- Add the
repoMapkey with a boolean or string value:
{
"repoMap": true
}
Set "repoMap": "auto" to allow OpenClaude to decide whether to inject the map based on the current token budget constraints.
- Save the file. On the next startup,
src/context.tsreads this value into thehas_repo_mapproperty and merges therepoMapobject into the system context.
2. CLI Flag (Per-Session Override)
For one-off invocations where you need the map without changing global settings, use the commander-based CLI entrypoint in src/entrypoints/cli.ts:
openclaude --repo-map chat "Explain the dependencies in src/utils/git.ts"
To explicitly disable the map for a single run:
openclaude --no-repo-map chat "General programming question"
3. Environment Variable (CI/CD and Scripts)
In automated environments or shell scripts, export OPENCLAUDE_REPO_MAP before invoking the CLI. The startup environment builder in src/utils/subprocessEnv.ts injects this variable, which src/context.ts checks during context construction.
export OPENCLAUDE_REPO_MAP=1
openclaude chat "What files import the Tree-sitter parser?"
Use OPENCLAUDE_REPO_MAP=auto for budget-aware injection in CI pipelines.
How Auto-Injection Works Under the Hood
Understanding the implementation helps debug injection failures. The process involves three distinct phases:
-
Map Construction – When the flag is enabled,
buildRepoMap(insrc/context/repoMap/renderer.ts) executes a PageRank algorithm over the file graph produced bysrc/context/repoMap/gitFiles.ts. The output is aRepoMapResultobject (defined insrc/context/repoMap/types.ts) containing the compressed file tree. -
Context Assembly – In
src/context.ts, the system gathers context:
const [gitStatus, repoMap] = await Promise.all([ … ]);
const systemContext = {
…,
has_repo_map: repoMap !== null,
...(repoMap && { repoMap })
};
The spread operator conditionally inserts the repoMap key only when the flag is truthy and the build succeeds.
- Session Injection – The assembled
systemContextis passed to every newSessioninstance. Because the map resides in the system prompt, the model can referenceRepoMapTool(exposed viasrc/tools/RepoMapTool/RepoMapTool.ts) and answer questions about file relationships without explicit/repomapcalls.
Practical Configuration Examples
Enable Globally via Config
// ~/.openclaude.json
{
"repoMap": true,
"smartRouting": "auto",
"autoUpdates": false
}
Now any chat automatically includes the map:
openclaude chat "Which file contains the authentication logic?"
One-Off Repository Analysis
openclaude --repo-map chat "Show me the PageRank-ranked list of TypeScript files"
CI Pipeline Integration
#!/usr/bin/env bash
set -e
export OPENCLAUDE_REPO_MAP=auto
openclaude review --pr=123
Troubleshooting Auto-Injection Failures
If the model does not recognize repository files during sessions, verify the flag state:
-
Symptom: The model responds with "I don't have access to repository files."
- Cause: The
repoMapflag is unset or falsy. - Fix: Check
~/.openclaude.jsonfor therepoMapkey, or verifyOPENCLAUDE_REPO_MAPis exported in your shell.
- Cause: The
-
Symptom: Slow startup or
RepoMapResulterrors.- Cause: Missing Tree-sitter parsers or graph library dependencies.
- Fix: Run
bun installto ensuretree-sitteris compiled and verifyexternals.tsincludes the repo-map graph algorithm dependencies.
-
Symptom: Map missing in Docker or CI environments.
- Cause: Environment variable not propagated to the subprocess.
- Fix: Explicitly pass
OPENCLAUDE_REPO_MAP=1in your container environment block.
Summary
- Set
"repoMap": truein~/.openclaude.jsonfor persistent auto-injection. - Use
--repo-mapfor temporary per-session enablement. - Export
OPENCLAUDE_REPO_MAP=1for shell scripts and CI/CD pipelines. - The map is built by
src/context/repoMap/renderer.tsand injected viasrc/context.tsinto every session's system context. - When enabled, the model gains immediate access to
RepoMapToolwithout manual/repomapcommands.
Frequently Asked Questions
What values does the repoMap setting accept?
The setting accepts true (always inject), false (never inject), or "auto" (inject only when the token budget allows). These values are validated against the schema in src/utils/settings/settings.ts.
Does enabling auto-injection slow down OpenClaude startup?
Yes, marginally. The buildRepoMap function runs a PageRank analysis over the repository graph, which requires parsing files through Tree-sitter. The impact depends on repository size, but the result is cached for the session duration.
Can I manually trigger the repo map if auto-injection is disabled?
Yes. Even with repoMap: false, you can run the /repomap command at any time. This command is handled in src/commands/repomap/repomap.ts and will generate a fresh map on demand without modifying the global configuration.
Why does the environment variable use 1 instead of true?
Environment variables are strings; OpenClaude interprets OPENCLAUDE_REPO_MAP=1 as truthy in src/utils/subprocessEnv.ts and src/context.ts. The value auto is also recognized as a special string constant, matching the JSON configuration behavior.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →