Skip to main content

Serialize a repository into XML-like workspace context for LLM input

Project description

simple-workspace-contextualizer

A small CLI for serializing a source repository into a structured, LLM-friendly context format.

It prints:

  • a filtered file tree for the workspace
  • the full contents of selected files
  • stable XML-like wrapper tags so the output can be pasted directly into an LLM prompt

The intended use case is: "take a repo and turn it into a single prompt payload that gives an LLM useful project context."

Why this exists

LLMs usually perform better when they can see:

  • the repository structure
  • the important source files
  • toolchain and config files
  • README / markdown documentation
  • the exact source text, without reformatting or lossy transformations

This tool packages that information into one stream.

Features

  • Recursively prints a workspace file tree
  • Includes common source files by default
  • Includes common toolchain / config files by default
  • Supports additional user-supplied glob patterns
  • Supports --override to disable the built-in file selection globs
  • Hides ignored paths from the file tree
  • Allows user-supplied globs to explicitly include ignored files in the emitted file contents
  • Produces a simple structured output format that is easy to paste into an LLM

Installation

From PyPI

pip install simple-workspace-contextualizer

Local development

git clone <your-repo-url>
cd simple-workspace-contextualizer
python -m pip install -e .

This installs the CLI command:

swc

Or the full command name:

simple_workspace_contextualizer

Requirements

  • Python 3.13+

Usage

swc PROJECT_ROOT [--override] [GLOB ...]

Arguments

ROOT

Root project directory to scan.

--override

Disable the built-in default include globs.

When --override is present, only the user-supplied globs are used for <file_contents>.

GLOB ...

Zero or more additional glob patterns to include in <file_contents>.

These user globs are additive by default, and they can explicitly include files that would otherwise be ignored.

Examples

Serialize a repo with the default built-in file patterns:

swc .

Add a few extra file patterns:

swc . "docs/**/*.txt" "proto/**/*.proto"

Only include files matching your own globs:

swc . --override "src/**/*.py" "tests/**/*.py"

Explicitly include something under an otherwise ignored path:

swc . ".venv/lib/python3.13/site-packages/pip-25.3.dist-info/LICENSE.txt"

Output format

The tool emits XML-like structured text:

<workspace_context>
  <file_tree>
    ...
  </file_tree>
  <file_contents>
    <file path="src/example.py">
      ...
    </file>
    <file path="pyproject.toml">
      ...
    </file>
  </file_contents>
</workspace_context>

Semantics

  • <file_tree> contains the filtered directory tree
  • <file_contents> contains the full contents of selected files
  • each <file> element has a path attribute relative to the workspace root

File selection model

The set of files included in <file_contents> is:

  1. the built-in default glob set
  2. plus any user-supplied globs

If --override is used, the built-in default glob set becomes empty.

So the effective rule is:

  • default mode: default globs ∪ user globs
  • override mode: user globs

Ignore behavior

Ignored paths are hidden from the file tree and excluded from files selected by the built-in default glob set.

However, user-supplied globs are allowed to explicitly include ignored files.

That means:

  • ignored paths do not appear in <file_tree>
  • ignored files do not get included by default
  • ignored files can still appear in <file_contents> if the user explicitly requests them with a glob argument

This is intentional: it keeps the default output clean while still allowing targeted overrides.

Default included files

The built-in include globs are aimed at "files that are useful to show an LLM."

They include:

  • source files such as Python, JavaScript, TypeScript, Go, Rust, Java, C/C++, shell, SQL, and others
  • markdown files
  • common toolchain and config files such as:
    • Makefile
    • Dockerfile
    • pyproject.toml
    • requirements.txt
    • package.json
    • tsconfig.json
    • go.mod
    • Cargo.toml
    • pom.xml
    • Gradle files
    • common lint / formatter config files

Typical ignored paths

The ignore list is intended to filter out noisy or generated content such as:

  • VCS metadata
  • editor / IDE folders
  • caches
  • virtual environments
  • node_modules
  • build outputs
  • coverage artifacts
  • generated packaging metadata

Examples include:

  • .git/
  • .venv/
  • node_modules/
  • dist/
  • build/
  • __pycache__/
  • *.egg-info/
  • *.dist-info/

Example workflow with an LLM

Generate workspace context:

swc . > workspace_context.xml

Then paste that output into your LLM prompt along with a task, for example:

Here is the current repository context. Please explain the architecture, identify likely entry points, and suggest how to add feature X.

Design goals

  • Minimal dependencies
  • Easy to inspect
  • Easy to pipe to stdout
  • Easy to compose with shell tooling
  • Optimized for LLM context generation rather than archival fidelity

Non-goals

  • Full XML document modeling
  • Perfect reproduction of every file in a repository
  • Preserving large binary assets
  • Replacing dedicated indexing or retrieval systems

Limitations

  • Large repositories can produce very large outputs
  • The default globs are heuristic, not exhaustive
  • Ignored paths are policy-driven and may need adjustment for your codebase
  • Prompt quality still depends on what files are included

Development

Run locally:

python -m simple_workspace_contextualizer.cli .

Or, if installed in editable mode:

swc .

Naming

Package name:

simple-workspace-contextualizer

Default CLI:

swc

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

simple_workspace_contextualizer-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file simple_workspace_contextualizer-0.1.0.tar.gz.

File metadata

File hashes

Hashes for simple_workspace_contextualizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 19f272fcdf3cb604468c2cf9f4b43d42ba16230bbb78eeb8c17a995c7cb3220e
MD5 b2e0557a9acb9c61e3a62b701148e0d9
BLAKE2b-256 1cf6d85aaa50c53c6baad9fd7f71eb3f74c640b54e6fb34a5bafe175d56c6371

See more details on using hashes here.

File details

Details for the file simple_workspace_contextualizer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_workspace_contextualizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 435033155b3e1a9ab27bc5f103d0493ac1bc7f8b239947302e642e63d8d12953
MD5 89fcd579b654f9942d9ae25c8672163a
BLAKE2b-256 de4dc0227027c3100dfa99d4597952f28a057cff34e5267330397e02a4ac71b8

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