Skip to content

Codebase Context Packer

Pack code files into an LLM prompt under a token budget with per-file truncation (full, signatures, first N lines) and XML, Markdown or plain output.

Codebase Context Packer

Model:
tokens
Format:
Raw: 252After truncation: 240Budget: 128,000
00% used128,000

Files (3)

src/index.ts44 tok
src/app.ts105 tok
src/users.ts103 tok → 91

Output preview

Packed 266 tokens266 tokens
<file path="src/index.ts">
import { createApp } from "./app";

const port = Number(process.env.PORT ?? 3000);
createApp().listen(port, () => {
  console.log(`Listening on http://localhost:${port}`);
});
</file>

<file path="src/app.ts">
import express from "express";
import { listUsers, getUser } from "./users";

export function createApp() {
  const app = express();
  app.get("/users", async (_req, res) => {
    res.json(await listUsers());
  });
  app.get("/users/:id", async (req, res) => {
    const user = await getUser(req.params.id);
    if (!user) return res.status(404).json({ error: "Not found" });
    res.json(user);
  });
  return app;
}
</file>

<file path="src/users.ts">
export interface User {
  id: string;
  name: string;
  email: string;
}

const users: User[] = [
  { id: "1", name: "Jane Doe", email: "jane@example.com" },
  { id: "2", name: "John Smith", email: "john@example.com" },
];

export async function listUsers(): Promise<User[]> { ... }
}

export async function getUser(id: string): Promise<User | undefined> { ... }
}
</file>

Token allocation per file:

src/index.ts
44
src/app.ts
105
src/users.ts
91

Updated . Provided as is. Check the output before you rely on it in production.

How to use Codebase Context Packer

  1. 1

    Add your code files

    Click Add File for each file you want to include. Enter the file path and paste the contents. You can also use bulk paste mode with file separators.

  2. 2

    Set your token budget

    Enter your target token budget or select a model preset (the current Anthropic, OpenAI and Google flagships plus the 200K Haiku tier, from the live model catalog). The budget bar shows how much space your files use.

  3. 3

    Choose truncation mode

    For large files, switch from Full to Signatures Only (keeps function and class signatures, drops bodies) or First N Lines to fit within your budget.

  4. 4

    Copy the packed output

    Select your output format (XML for Claude, Markdown, or Plain), review the preview, and click Copy to get the optimized context package ready to paste.

Questions and answers

What is Codebase Context Packer?
Context packing means fitting the files a model needs into one prompt without overflowing its context window. This packer takes pasted files, estimates tokens at about four characters each, truncates per file (full, signatures only, first N lines or smart), fits them to a budget and outputs XML, Markdown or plain text.
What output formats are available?
Three formats: XML-wrapped (ideal for Claude), markdown fenced code blocks, and plain text with file separators. All formats include file paths for context.
Does it send my code to a server?
No. All processing happens entirely in your browser. Your code files never leave your device.
How does the signatures-only truncation work?
Signatures-only mode keeps function and class declarations but removes implementation bodies, dramatically reducing token count while preserving the API surface that LLMs need for context.
For AI agents: how to call this tool

Machine-readable contract, endpoints and examples. Humans can ignore this section.

Best Path For Builders

Browser workflow

Runs instantly in the browser with private local processing and copy/export-ready output.

Browser Workflow

This tool is optimized for instant in-browser execution with local data handling. Run it here and copy/export the output directly.

/codebase-context-packer/

For automation planning, fetch the canonical contract at /api/tool/codebase-context-packer.json.