Codemap.Cli
1.0.2
See the version list below for details.
dotnet tool install --global Codemap.Cli --version 1.0.2
dotnet new tool-manifest
dotnet tool install --local Codemap.Cli --version 1.0.2
#tool dotnet:?package=Codemap.Cli&version=1.0.2
nuke :add-package Codemap.Cli --version 1.0.2
codemap
Repository context, compressed. Package source code into deterministic, AI-friendly output from the command line or a reusable .NET library.
Contents
- Install
- Features
- Quick start
- Command reference
- Configuration
- Advanced capabilities
- C# library
- Development
- Troubleshooting
codemap is a .NET 10 command-line tool and reusable C# library for turning a repository into compact, AI-friendly output. It provides deterministic discovery, Git-aware filtering, token counting, DevSkim security scanning, and configurable output formats.
Installation
codemap is distributed as a .NET tool. Install the published package globally with:
dotnet tool install --global Codemap.Cli
Then run it from any directory with codemap.
Running codemap without options scans the current directory. Use --root when your current directory contains protected system folders, for example codemap --root C:\path\to\repository.
Start with codemap --root . --format markdown --output repository.md to create a shareable repository snapshot.
Features: What codemap Provides
| Capability | What it does | |
|---|---|---|
| ๐ฆ | AI-ready packaging | Combines selected source files into one readable artifact. |
| ๐งญ | Deterministic discovery | Processes files in stable path order for repeatable output. |
| ๐ฏ | Include and ignore rules | Filters paths with globs, .gitignore, and .ignore. |
| ๐ฟ | Git awareness | Includes diffs and recent commits when requested. |
| ๐ข | Token counts | Reports GPT-4-compatible cl100k_base counts per file and overall. |
| ๐ก๏ธ | Security filtering | Uses DevSkim and excludes files with actionable findings. |
| ๐งน | Content cleanup | Removes comments or empty lines and can add line numbers. |
| ๐ | Multiple formats | Writes Markdown, XML, JSON, or plain text. |
| ๐ | Size controls | Supports file-size limits, token budgets, and split output. |
| ๐ | Repository sources | Packs a local directory or clones a remote Git repository. |
| ๐ | Workflow support | Watches a directory for changes or exposes a reusable C# library. |
Quick Start
1. Install
dotnet tool install --global Codemap.Cli
2. Pack a repository
codemap --root . --format markdown --output repository.md
3. Keep output within a model context window
codemap --root . --include "src/**/*.cs" --token-budget 12000 --output compact-context.md
Generated output is deterministic when the same source, options, and Git state are used.
How to Run codemap
codemap's main workflow is simple: choose a source directory, select an output format, and write the generated repository context to a file. The examples below focus on core commands.
โ Help
Use the built-in help whenever you need to check available commands and options:
codemap --help
๐ Root
Pack the current directory into Markdown, which is convenient for sharing with an AI tool:
codemap \
--root . \
--format markdown \
--output repository.md
๐ฏ Include and Ignore
Use --include to select files and --ignore to remove paths from that selection:
codemap \
--root . \
--include "src/**/*.cs,README.md" \
--ignore "**/bin/**,**/obj/**" \
--format markdown \
--output source-context.md
codemap also reads .gitignore and .ignore automatically.
๐ก๏ธ Security Check
Use DevSkim to exclude files with actionable security findings before they enter the generated context:
codemap \
--root . \
--security-check \
--format markdown \
--output reviewed-context.md
codemap reports excluded files in the terminal. Node.js and npm are not required.
๐ Format
Use --format to choose the output that fits your workflow:
# Human- and AI-friendly document
codemap --format markdown --output repository.md
# Structured data for another program
codemap --format json --output repository.json
# XML or simple text output
codemap --format xml --output repository.xml
codemap --format plain --output repository.txt
๐ Remote
codemap can clone a repository and pack a selected branch:
codemap \
--remote microsoft/generative-ai-for-beginners \
--remote-branch main \
--format markdown \
--output remote-context.md
The same command accepts a complete Git URL. Git must be installed and available on PATH for remote repositories and Git metadata.
Requirements
- .NET SDK 10 or newer.
- Git only when using
--remote,--include-diffs, or--include-logs. - Node.js and npm are not required. Security scanning is implemented with DevSkim for .NET.
Command Reference
General form:
codemap [options]
Show the built-in command reference at any time:
codemap --help
| Option | Value | Description |
|---|---|---|
--root |
path | Source directory. Defaults to the current directory. |
--remote |
URL or owner/repository |
Clone a remote Git repository into a temporary directory before packing. |
--remote-branch |
branch | Branch to clone when using --remote. |
--config |
path | Configuration JSON file. Without this option, codemap searches for codemap.json and codemap.config.json. |
--include |
comma-separated globs | Include only matching paths, for example **/*.cs,**/*.md. |
--ignore |
comma-separated globs | Add ignore patterns for this run. |
--format |
xml, markdown, md, json, plain, txt |
Output format. Defaults to XML. |
--output |
path | Output file path. Defaults to codemap-output.md. |
--no-summary |
flag | Remove file count and token summary from structured output. |
--no-tree |
flag | Remove the directory/file listing from structured output. |
--line-numbers |
flag | Prefix each output line with its line number. |
--remove-comments |
flag | Remove common // and /* ... */ comments before rendering. |
--remove-empty-lines |
flag | Remove blank lines after other transformations. |
--security-check |
flag | Scan original files with DevSkim and exclude files with findings. |
--max-file-size |
bytes | Skip files larger than this size before reading them. |
--token-budget |
count | Fail if the final rendered output exceeds this token count. |
--include-diffs |
flag | Include git diff output. |
--include-logs |
flag | Include recent one-line Git commits. |
--include-logs-count |
count | Number of commits to include. Defaults to 20. |
--split-output |
bytes | Split output into numbered files when the rendered content exceeds this size. |
--watch |
flag | Watch the source tree and print a notification when files change. Run codemap again to regenerate output. |
--help |
flag | Show command usage, options, and examples without packing. |
Boolean options are enabled by writing the flag.
Configuration
Configuration uses JSON. codemap automatically loads codemap.json or codemap.config.json from the source root. Use --config to select another file.
{
"outputPath": "artifacts/repository.md",
"format": "Markdown",
"includePatterns": ["**/*.cs", "**/*.md"],
"ignorePatterns": ["**/test-data/**"],
"includeFileSummary": true,
"includeDirectoryStructure": true,
"showLineNumbers": false,
"removeComments": true,
"removeEmptyLines": true,
"enableSecurityCheck": true,
"maxFileSizeBytes": 500000,
"tokenBudget": 12000,
"includeGitDiffs": false,
"includeGitLogs": true,
"gitLogCount": 10,
"splitOutputBytes": 200000
}
Command-line values override configuration values. For list options such as --include and --ignore, the command-line value replaces the configured list.
Advanced Capabilities
The sections below explain behavior that is useful when tuning output for a larger repository or an automated workflow.
๐ฏ Include and Ignore Rules
codemap always skips these generated or repository directories:
.git bin obj node_modules dist coverage
It also reads these files from the source root, in this order:
.gitignore
.ignore
Patterns are evaluated in order. A pattern ignores a matching path; a pattern beginning with ! re-includes it.
# Ignore generated files
generated/
# Keep one useful fixture
!generated/example.cs
# Ignore all logs
*.log
Include patterns are applied after ignore rules. Common examples:
**/*.cs all C# files at any depth
src/** everything under src
*.md Markdown files at any directory depth
๐ก๏ธ Security Scanning
--security-check uses Microsoft DevSkim embedded rules. codemap scans the original UTF-8 source before cleanup transformations. Files with actionable DevSkim findings are excluded from the packed result instead of causing the entire operation to fail.
Excluded paths are reported on the console and exposed through the result model. Use this mode when creating context from repositories that may contain credentials, weak cryptography, or other known security patterns.
๐ Output Formats
Markdown
Markdown includes a repository summary, file listing, per-file token counts, language-aware code fences, and optional Git sections. It is the most convenient format for humans and chat-based AI tools.
XML
XML contains a codemap root, summary attributes, directory structure, file elements, and optional Git metadata. It is useful for structured downstream processing.
JSON
JSON contains summary data, file records, excluded security paths, and optional Git metadata. Each file includes its relative path, content, character count, line count, and token count.
Plain text
Plain text emits each file under a clear path separator. It is useful for tools that do not parse Markdown, XML, or JSON.
๐ข Token Counts and Limits
codemap uses the GPT-4-compatible cl100k_base tokenizer from Microsoft.ML.Tokenizers. Each packed file has a token count, and the final rendered output has an aggregate count.
--token-budget validates the final rendered output. If the output is too large, codemap returns an error rather than silently producing an incomplete result. Use --include, --ignore, --max-file-size, or --split-output to control size.
๐ Remote Repositories, Git Metadata, and Watch Mode
Clone and pack a GitHub repository:
codemap \
--remote microsoft/generative-ai-for-beginners \
--remote-branch main \
--format markdown \
--output repository.md
Use a normal URL when preferred:
codemap \
--remote https://github.com/microsoft/TypeScript.git \
--include-diffs \
--include-logs \
--include-logs-count 10
For a local repository:
codemap --root . --include-diffs --include-logs
Watch mode reports changes but does not automatically repack:
codemap --root . --watch
Using the C# Library
The reusable core can be called without the CLI:
using Codemap.Core;
var result = await new CodePacker().PackAsync(new PackOptions
{
RootDirectory = ".",
Format = OutputFormat.Markdown,
IncludePatterns = ["**/*.cs"],
EnableSecurityCheck = true,
TokenBudget = 12000
});
Console.WriteLine(result.Content);
Console.WriteLine($"Files: {result.Files.Count}");
Console.WriteLine($"Tokens: {result.TokenCount}");
The core API returns packed files, rendered content, character and token counts, Git metadata, and security-excluded paths.
Development
dotnet build Codemap.slnx
dotnet test --solution Codemap.slnx
Tests are organized under tests/Codemap.Tests/Unit/ for core behavior and tests/Codemap.Tests/Integration/ for CLI process behavior.
See docs/how-it-works.md for pipeline boundaries and extension guidance. See AGENTS.md for repository conventions.
Troubleshooting
The output is too large
Use narrower --include patterns, more --ignore patterns, --max-file-size, or --token-budget.
A file is missing
Check the default ignored directories, .gitignore, .ignore, and the include patterns. Binary and invalid UTF-8 files are intentionally skipped.
Git metadata is empty
Run from a Git working tree and verify that git is installed and available on PATH.
Remote cloning fails
Verify the repository URL, branch name, network access, and Git installation.
Security files are excluded
Review the DevSkim findings reported by the CLI. codemap excludes actionable findings by design so sensitive or risky content does not enter the generated AI context.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.12 | 104 | 9/24/2026 |
| 1.0.11 | 91 | 9/24/2026 |
| 1.0.10 | 96 | 9/22/2026 |
| 1.0.9 | 97 | 9/20/2026 |
| 1.0.8 | 93 | 9/20/2026 |
| 1.0.7 | 94 | 9/18/2026 |
| 1.0.6 | 96 | 9/17/2026 |
| 1.0.5 | 96 | 9/15/2026 |
| 1.0.4 | 95 | 9/14/2026 |
| 1.0.3 | 104 | 9/13/2026 |
| 1.0.2 | 88 | 9/12/2026 |
| 1.0.1 | 92 | 9/12/2026 |
| 1.0.0 | 103 | 9/12/2026 |
| 0.1.0 | 86 | 9/18/2026 |
Initial release of the codemap command-line tool.