aiar (AI Archive)
A simple LLM-friendly archive format and utility for creating self-extracting shell archives.
Inspired by the classic Unix shar (shell archive), aiar is a format and a tool for bundling a directory structure and its files into a single, executable bash/zsh script. It's designed to make sending and receiving file collections in a chat-based or text-only environment—like interacting with an LLM—as simple as copying and pasting a single block of text.
Purpose
The primary purpose of the aiar format is to package a project's files into a single text block for use with a Large Language Model. This allows an LLM to receive or transmit a collection of files within a text-only interface, bypassing the need for binary archive formats like .zip. (Yes, I once had an LLM try to send me a base 64 encoded zip file, I kid you not. And, no, it wasn’t a valid zip file.)
Key Features
- Single File: The entire archive is one text file. Easy to copy, paste, and save. Archives over a size limit (512 KiB by default) become a set of parts, each a complete archive that can extract the whole set.
- LLM-Friendly: The format is simple for an LLM to generate or consume. Because the file content is never executed, the LLM doesn't need to worry about shell-escaping special characters.
- Self-Contained: The extraction logic is bundled with the data. No external tools like zip or tar are needed to unpack it.
The aiar Format
An aiar script has two main parts, separated by an exit 0 command.
- The Unpacker Logic: A bash script that reads its own file, line by line. It looks for a unique separator line that denotes the start of a new file. This part is optional if you use the "aiar" tool and might even be desirable if you don't want to run code directly from an LLM.
- The exit 0 Guard: This command prevents the shell from ever trying to execute the data section below it.
- The Data Payload: The raw, unescaped contents of your files, each preceded by the unique separator line.
Supported Formats
The aiar tool supports multiple output formats:
- bare (
.aiar) - Data-only format without self-extraction script. Most LLM-friendly for creation. - bash (
.sh) - Self-extracting Bash script (default). Compatible with Linux/macOS/WSL. - python (
.py) - Self-extracting Python script. Requires Python 3.9+. - nodejs (
.js) - Self-extracting Node.js script. Requires Node.js. - powershell (
.ps1) - Self-extracting PowerShell script. Requires PowerShell 5.1+.
All formats support both text and binary files and can be extracted using the aiar extract command.
Text vs. binary and encodings
A file is stored as text if it contains only printable characters, tab, line feed, carriage return, form feed, and bytes 0x80 and above. That means text in any ASCII-compatible encoding (UTF-8, Latin-1, cp1252, Shift-JIS, ...) stays readable in the archive. Text is copied byte-for-byte, keeping its original encoding and line endings (CRLF included), and every extractor writes those exact bytes back. Any other control byte (NUL, BEL, ESC, DEL, ...) makes a file binary, which includes UTF-16 and UTF-32 files, so they are base64-encoded. A text file without a trailing newline gets one appended. Use --binary-all to avoid that.
Python self-extracting archives that contain non-UTF-8 text start with a # -*- coding: latin-1 -*- line, so that Python will still run them.
Example Archives
Below are examples of each format. Each demonstrates the same two-file archive structure.
Bare Format (.aiar)
The bare format is the simplest and most LLM-friendly. It contains only the data with a separator definition, no extraction logic. This format can be extracted using aiar extract archive.aiar.
Note for LLMs: To create a bare format archive:
- Start with
SEPARATOR="..."(use a unique string not found in file contents) - Mark each file with
:t:for text or:b:for binary - Use format:
SEPARATOR:t:filepathfollowed by file content - The contents of the binary blobs are base64 encoded.
SEPARATOR="++++++++++--------:a1b2c3d4-5678-90ab-cdef-1234567890ab:"
++++++++++--------:a1b2c3d4-5678-90ab-cdef-1234567890ab:t:example/README.md
# Example Project
This is a sample file in the bare aiar format.
++++++++++--------:a1b2c3d4-5678-90ab-cdef-1234567890ab:t:example/hello.txt
Hello from aiar!
This file can contain any text content.
Special characters like $, #, ', ", `, $(cmd) are preserved literally.
Bash Format (.sh)
The Bash format is a self-extracting shell script. Save as archive.sh and run with bash archive.sh. It runs on bash 3.2 and later, so the /bin/bash that macOS ships works. Every line of the extractor ends with #, so a CRLF line ending stays inside a comment. Shortened, with the extractor code left out:
#!/bin/bash
# aiar: AI Archive - Self-extracting script generated by aiar-py. #
#
# Note to LLMs: this archive contains multiple files with separator lines. #
# ... #
SEPARATOR="++++++++++--------:8c7163c6-4902-46b0-9629-f75517de083c:" #
# ... the extractor: about 400 lines, each ending with " #" ... #
exit 0 #
#
# --- DATA --- #
#
++++++++++--------:8c7163c6-4902-46b0-9629-f75517de083c:t:example/hello.txt
Hello from aiar!
She said, "He's going to the store for $5."
++++++++++--------:8c7163c6-4902-46b0-9629-f75517de083c:t:example/README.md
# Example Project
This file includes special characters: $PATH, #comment, 'quotes', "quotes", `backticks`, $(cmd)
All are preserved literally.
Python Format (.py)
The Python format is a self-extracting Python script. Save as archive.py and run with python archive.py. Files are embedded as commented lines with a # prefix. Shortened:
import sys, os, re, base64, stat
from pathlib import Path
# Note to LLMs: ...
SEPARATOR="++++++++++--------:a1b2c3d4-5678-90ab-cdef-1234567890ab:"
# ... the extractor ...
sys.exit(main(sys.argv[1:]))
# ++++++++++--------:a1b2c3d4-5678-90ab-cdef-1234567890ab:t:example/README.md
# # Example Project
#
# This file includes special characters: $PATH, #comment, 'quotes', "quotes", `backticks`, $(cmd)
# All are preserved literally.
#
# ++++++++++--------:a1b2c3d4-5678-90ab-cdef-1234567890ab:t:example/hello.txt
# Hello from aiar!
# She said, "He's going to the store for $5."
Node.js Format (.js)
The Node.js format is a self-extracting Node.js script. Save as archive.js and run with node archive.js. Files are embedded as commented lines with a // prefix. Shortened:
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
// Note to LLMs: ...
const SEPARATOR = "++++++++++--------:a1b2c3d4-5678-90ab-cdef-1234567890ab:";
// ... the extractor ...
process.exitCode = main(process.argv.slice(2));
// Stop here: the data below is never run. (A CommonJS module may return.)
return;
// ++++++++++--------:a1b2c3d4-5678-90ab-cdef-1234567890ab:t:example/hello.txt
// Hello from aiar!
// She said, "He's going to the store for $5."
PowerShell Format (.ps1)
The PowerShell format is a self-extracting PowerShell script for Windows PowerShell 5.1 and PowerShell 7. Save as archive.ps1 and run with powershell -ExecutionPolicy Bypass -File archive.ps1. Files are embedded as commented lines with a # prefix. Shortened:
#Requires -Version 5.1
$SEPARATOR="++++++++++--------:a1b2c3d4-5678-90ab-cdef-1234567890ab:"
# Note to LLMs: ...
# ... the extractor ...
$status = Invoke-Main -Arguments $args
# The script must exit here to prevent PowerShell from trying to interpret the payload.
exit $status
# --- PAYLOAD ---
# ++++++++++--------:a1b2c3d4-5678-90ab-cdef-1234567890ab:t:example/hello.txt
# Hello from aiar!
# She said, "He's going to the store for $5."
Size limits and sets
An archive can be too large to paste or upload in one piece, so aiar create limits the size of each output file. Output that does not fit is written as a set of parts, each a complete archive with its own extractor.
aiar create . -o release.aiar.sh.txt # default limit: 512 KiB per file
aiar create . -o release.aiar.sh.txt --max-size 100KiB
aiar create . -o release.aiar.sh.txt --max-size unlimited
- The limit.
--max-sizeis the largest size of each output file, extractor included. The default is 512 KiB (524288 bytes) and always applies. A size is a whole number of bytes, optionally followed by a binary unit in any case:B,KorKiB,MorMiB,GorGiB. Decimal units (KB,MB), fractions and negative numbers are rejected (status 2).0orunlimitedmeans one file however large. - One file when it fits. When everything fits, the output is a single file at
-o, exactly as before. - Repositories stay together. Files are grouped by their innermost Git repository (or by the command-line path that selected them). A repository that fits in one part is never split; one that does not is split along directory boundaries. Parts are filled first fit, in path order, and each part's header says which repositories it holds completely and which only partly, with the other parts they continue in.
- The limit is best effort. A file is never split and never rejected for its size. A file larger than the limit is written whole in a part of its own, with a warning naming the file, its size and the part.
- Standard output. Without
-othe archive goes to standard output as before, but only when it is one file. If it needs several parts,aiar createfails with status 1 and writes nothing; use-o, or--max-size unlimitedfor one file.
Part names and the parts directory
The parts go in a directory named after the whole -o name plus .parts, next to where -o points. Each part's name carries a tag NNofMM, with NN padded to the width of MM, placed so that the part keeps the language suffix of -o:
-o |
Parts |
|---|---|
release.aiar.sh.txt |
release.aiar.sh.txt.parts/release.aiar.01of10.sh.txt ... |
release.sh |
release.sh.parts/release.aiar.01of10.sh ... |
release.aiar (bare) |
release.aiar.parts/release.01of10.aiar ... |
notes.txt |
notes.txt.parts/notes.aiar.01of10.txt ... |
Line 2 of every part is its set line, # aiar-set: <id> part 03 of 10 (// for Node.js, with a closing # for bash), and the lines after it say what the part holds. Parts are recognised by that line, never by their names, so a renamed part (release.aiar.03of10 (1).sh) is still found.
Extracting a set
Run any one part, with its own extractor or with aiar extract, and the whole set is extracted:
bash release.sh.parts/release.aiar.03of10.sh
aiar extract release.sh.parts/release.aiar.03of10.sh
The extractor looks for the other parts in the part's own directory, reading them only as data (no part is ever run, sourced or imported by another), checks that every part from 1 to M is present, and only then extracts them in order, relative to the current directory, skipping files that already exist. Missing parts are reported by number and expected name, and nothing is written.
| Options | What happens | Status |
|---|---|---|
| none, set complete | extract every part | 0 |
| none, a part missing or conflicting | write nothing, report | 1 |
--partial, parts missing |
extract the parts present; list repositories that reach into a missing part | 3 |
--partial, conflicting duplicate |
write nothing, report | 1 |
--this-part |
extract only the file run, without looking for other parts | 0 |
--this-part with --partial |
usage error | 2 |
| an unknown argument (self-extractors) | usage message, nothing written | 2 |
-h, --help (self-extractors) |
usage message, nothing written | 0 |
-t (aiar extract only) |
write nothing; list the parts found, missing parts, other sets and each part's files | 0, or 1 if incomplete |
--include, --exclude, -C and -v apply to every part. -C sets where files are written; the parts are still looked for beside the part given. Identical duplicate parts are accepted with a note, different ones are an error, and parts of other sets in the same directory are counted and ignored.
aiar 0.2's aiar extract, given one part, extracts that part only and reports success. To extract a set, use the parts' own extractors or aiar extract 0.3 or later.
A part that picked up a UTF-8 BOM in transit still extracts with aiar extract and the bash and PowerShell extractors. Python refuses to run such a part when it declares latin-1 (because the set holds text that is not UTF-8), and Node.js refuses any script whose #! line follows a BOM; use aiar extract for those. The self-extractors report a part saved as UTF-16 and ask for UTF-8; aiar extract decodes it.
Replacing earlier output
Re-running aiar create with the same -o replaces whatever it wrote before: a single file at -o, a parts directory, or both. Only aiar output for that -o is ever removed. If the parts directory holds anything else, or the file at -o is not an aiar archive, aiar create lists what is in the way and stops with status 1 before changing anything. The new output is written under a .new-<id> name and renamed into place; if a rename fails (on Windows, usually because a program has a file open), the renames already made are undone and the old output is left as it was. A run interrupted at any point leaves a complete copy of the old or the new output, and the next run restores or removes the leftovers. aiar create never archives its own output, its parts directory or these leftovers, even when -o is inside the tree being archived.
Rust CLI
The rust/ directory contains a Rust port of the aiar command. It takes the same commands and options, and its archives are byte-for-byte identical to the Python version's (apart from the random separator). It is released separately from the Python package (tags rust/vX.Y.Z) as prebuilt binaries for macOS, Linux and Windows, with an installer script. See rust/README.md for installation.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for aiar 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiar-0.3.0.tar.gz | 197.0 kB | With provenance | Details for aiar-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aiar-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for aiar-0.3.0-py3-none-any.whl |
Total release size: 252.9 kB
Release files / aiar-0.3.0.tar.gz
| Download URL | aiar-0.3.0.tar.gz |
|---|---|
| Size | 197.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b96aa80435522ead7b634f952f3bb0c4aa3512de2ad67ebbf2cd81ce8f4d0bd
|
|
BLAKE2b-256 checksum How to use checksums |
0efeabec6fdd97cfb14caab59e1e9e4d783f1349b84dec494c52026ee6cf536f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / aiar-0.3.0-py3-none-any.whl
| Download URL | aiar-0.3.0-py3-none-any.whl |
|---|---|
| Size | 55.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b6d557312c0c0178f01cab68d242cdc6159ef711740e022a22cc5a02c22163f2
|
|
BLAKE2b-256 checksum How to use checksums |
1344f03f5be55b0c07dc1571e3e8f608d214670a055bb5f41482ca0d92d0f73d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for aiar 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for aiar-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.