Skip to content
Reference

CLI & Python API

Every command, flag and function in one place. cz is a short alias for contextzip, and -h works on every command.

Command builder

Toggle flags to compose a command and preview its output.

Scope
Flags

Live preview

$ contextzip

✓ Detected Next.js + Node.js · high confidence

✓ Scanned 2,752 files & Packed 44 files · 185 KB → 63 KB, ↓66% smaller

✓ Saved to · .contextzip/output/codebase/codebase.zip · snapshot #14 (k3f9a2)

✓ Ready to paste

Run flags

These work on contextzip, include and exclude, placed after the verb.

FlagWhat it does
-i, --include PATHOnly include files under these paths. Naming an excluded path brings it back. Repeatable.
-e, --exclude PATTERNExtra exclusion patterns, gitignore syntax. Repeatable.
-p, --prompt TEXTLet Gemini pick the files relevant to this task.
--git-changesOnly staged, unstaged and untracked files. Needs a git repository.
-n, --dry-runShow what would be included; write nothing.
-o, --output FILEWrite the ZIP to this exact path, bypassing .contextzip/.
--no-clipboardDon't put the ZIP on the clipboard.
--no-gitignoreIgnore .gitignore and use only the built-in rules.
-v, --verboseList every included and excluded file.
--hereOnly package the folder you're in. Paths stay relative to the project root.
--from REPOPackage a GitHub, GitLab or Bitbucket repository instead of the local project.
--ref REFBranch, tag or commit to package with --from.
--jsonPrint one JSON object instead of terminal output. Never prompts.
--versionPrint the installed version.

Commands

contextzip

Details →

contextzip [run flags]

Detect the stack, leave out the noise, package the project.

contextzip REPO

Details →

contextzip github.com/user/repo [--ref REF] [run flags] (also gitlab.com, bitbucket.org, gh:, gl:, bb:)

Package a GitHub, GitLab or Bitbucket repository without cloning it. Same as --from REPO.

include

Details →

contextzip include PATH… [run flags]

Package only these paths. Naming an excluded path, like .env, brings it back.

exclude

Details →

contextzip exclude PATTERN… [run flags]

Package everything except these gitignore-style patterns. Quote patterns with * so your shell doesn't expand them.

apply-zip

Details →

contextzip apply-zip [ZIP] [--snapshot ID] [-n] [-v] [--review | --editor | --safe-only | -y] [--remove-moved] [--allow-delete] [--json]

Put an AI-returned ZIP back into your project — matched, merged around your edits, reviewable side by side.

apply-zip --pr

Details →

contextzip apply-zip ZIP --pr [--from REPO] [-n] [-y] [--json]

For a packaged GitHub repository: open a pull request with the AI's changes, no clone needed.

watch

Details →

contextzip watch -- COMMAND [ARGS]…

Run a command and package debug context when an error appears.

config

Details →

contextzip config [--reset-key] [--set-workspace LOC] [--reset-workspace] [--show-key-path] [--ui]

Gemini key, workspace location and the visual config UI. No flags shows your current setup.

snapshots

Details →

contextzip snapshots [--json]

List the numbered snapshots apply-zip merges replies against.

update

Details →

contextzip update [--check] [-y]

Check PyPI and upgrade in place with pip, pipx or uv. A standalone build prints its npm, Homebrew or Scoop command instead.

mcp

Details →

contextzip mcp

Run contextzip as an MCP server for AI agents. Needs pip install "contextzip[mcp]" (Python 3.10+).

setup-path

Details →

python -m contextzip setup-path [-y]

Fix “cz is not recognized”: put the folder pip installed cz into on your PATH.

Where files go

.contextzip/
.contextzip/├── output/│   ├── codebase/      codebase.zip  + .report.txt   (latest only)│   ├── git-changes/   changes.zip   + report│   ├── prompt/        vibe.zip      + report│   └── watch/         debug-context.zip├── snapshots/         #1, #2, … — what you sent, kept for merging├── inbox/             drop AI-returned ZIPs here│   └── applied/       archived after apply-zip└── config.json        project config (optional)

Lives at your git root by default — see workspace location. Old outputs are cleaned up automatically.

Python API

Everything the CLI does is a plain function underneath — no Click, no Rich output, no SystemExit. Functions return objects and raise typed exceptions.

round_trip.py
from contextzip import get_files, get_git_changes, create_zip, apply_zip # Every project file that passes the rules — plain pathlib.Path objectscollection = get_files(include=["src/"], exclude=["*.log"])for path in collection.files:    print(path) # Only what changed, zipped (with a local manifest beside it)pkg = create_zip(get_git_changes(), output="/tmp/changes.zip")print(f"Packed {pkg.file_count} files -> {pkg.zip_path}") # Later: apply the ZIP an AI tool returnedresult = apply_zip()print(f"Wrote {len(result.written)} files")
FunctionReturns
get_files(path=None, *, include, exclude, use_gitignore=True, use_project_config=True)FileCollection of project files after the rules
get_git_changes(path=None, *, use_project_config=True)FileCollection of staged, unstaged and untracked files
create_zip(collection, output=None)PackageResult — zip_path, file_count, sizes, redacted, skipped_in_zip, snapshot
apply_zip(zip_path=None, *, project_dir=None, manifest=None, include_risky=False)ApplyResult — written, skipped, removed, applied_zip_path, zip_kept
detect_ecosystem(path=None)DetectionResult — the detected stacks

All exceptions inherit from ContextzipError: NotARepositoryError, GitNotFoundError, GitCommandError, NoFilesError and ZipNotFoundError. Source and docstrings are on GitHub.