Skip to main content

Extract your codebase context for AI assistants

Project description

codecontext

Extract your codebase context for AI assistants.
CI Python 3.9+ MIT Zero dependencies v0.2.2

A zero-dependency CLI tool that packages your project structure, key files, and git history into a formatted prompt for Claude, ChatGPT, and other AI coding assistants.

pip install ctxcode
cd my-project
codecontext

Why?

When asking AI assistants about your code, you spend minutes copy-pasting file trees, key files, and git history. codecontext does it in one command — giving the AI full project context for better answers.

Install

pip install ctxcode

Or run directly:

curl -O https://raw.githubusercontent.com/hanu-14/codecontext/main/src/ctxcode/cli.py
python -m ctxcode

Usage

# Full context (tree + files + git history)
codecontext

# Specific project
codecontext path/to/project

# Output formats
codecontext --format markdown    # default - ready for AI chat
codecontext --format plain       # plain text
codecontext --format json        # machine-readable

# Copy to clipboard
codecontext --clipboard

# Save to file
codecontext -o context.md

# Exclude custom patterns
codecontext --exclude "*.log" "tmp/" "*.csv"

# Show hidden files
codecontext --hidden

# Exclude git info
codecontext --no-git

# Adjust limits
codecontext --max-files 100 --max-lines 150

Short alias

ctx                # same as codecontext
ctx ./src          # specific directory
ctx --clipboard    # copy to clipboard

Configuration

Place a .codecontext.toml in your project root:

git = true
max_files = 300
max_lines = 250
format = "markdown"
exclude = ["*.log", "tmp/"]
hidden = false

JSON and YAML formats are also supported (.codecontext.json, .codecontext.yml).

Output

The tool produces a structured document with:

  1. Project metadata — path, git remote, branch
  2. Git history — recent commits and uncommitted changes
  3. File tree — with file sizes for every entry
  4. Key files — source files with syntax highlighting
  5. Stats summary — total files and size at a glance

Perfect for pasting directly into Claude, ChatGPT, or any AI coding assistant.

Features

  • Zero dependencies — pure Python, no pip installs beyond this package
  • Smart ignore — automatically skips .git, node_modules, __pycache__, binaries, and more
  • Git aware — includes branch, remote, recent commits, and diff stats
  • File limit safety — won't overwhelm your context window
  • Language detection — syntax-highlighted code blocks for 30+ languages
  • Clipboard support--clipboard copies output directly to your clipboard
  • Multiple formats — markdown, plain text, or JSON
  • Config file — project-specific settings via .codecontext.toml
  • Custom excludes — ignore additional patterns with --exclude
  • File sizes — every file in the tree shows its size

Example

$ codecontext --format markdown

Produces:

# Codebase Context

Generated from: /Users/me/my-project
Remote: git@github.com:user/my-project.git
Branch: main

Recent commits:
abc1234 feat: add user authentication
def5678 fix: resolve payment timeout

## Project Structure

my-project/
├── src/
│   ├── main.py (2KB)
│   └── utils.py (1KB)
├── tests/
│   └── test_main.py (3KB)
├── pyproject.toml (1KB)
└── README.md (3KB)

## Key Files (6 files, 10KB)

### `src/main.py`

```python
def greet(name):
    return f"Hello, {name}!"

...


## Changelog

### v0.2.0
- Clipboard support (`--clipboard`)
- Multiple output formats: markdown, plain, JSON
- Configuration file support (`.codecontext.toml`, `.json`, `.yml`)
- File sizes in tree output
- Custom exclude patterns (`--exclude`)
- Hidden files flag (`--hidden`)
- Stats summary in output

### v0.1.0
- Initial release
- File tree with smart ignore patterns
- Git history integration
- Syntax highlighting for 30+ languages
- CLI alias `ctx`

## License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ctxcode-0.2.2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ctxcode-0.2.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file ctxcode-0.2.2.tar.gz.

File metadata

  • Download URL: ctxcode-0.2.2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for ctxcode-0.2.2.tar.gz
Algorithm Hash digest
SHA256 e5676857d4b27ed2bb8fecd245a649f7a1567e4958cb0bcd3461b35fbd999cb7
MD5 96a6d3000210518e86cc7e8db07b81dc
BLAKE2b-256 5df490c85fce30acef936b6869fda87568b89d03b0bf9dc8da2de341c3f403bc

See more details on using hashes here.

File details

Details for the file ctxcode-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: ctxcode-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for ctxcode-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 937c4617759161a4caf184ed6decee8efa3c4702ef93e793fb5eb43a6c18ba7e
MD5 507b604c706e8b532a9356bb46f29e4e
BLAKE2b-256 566b5bbe88323f81cb20826caa45abe135bde15c7b16508a8d988abe5096ab85

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page