Back
33/61
Lesson 33
6 min

S2P: Source to Prompt

Combine source code into LLM-ready prompts with token counting

New to ACFS?

Complete the setup wizard first to get the most from these lessons.

Go to Choose Your OS
Goal

Combine source code files into LLM-ready prompts with interactive file selection and token counting.

What Is S2P?

S2P (Source to Prompt TUI) is a terminal-based tool for combining source code files into a single, LLM-ready prompt. It provides an interactive file browser where you can select exactly which files to include, see the combined output in real-time, and track your token count as you go.

Crafting prompts with code context is tedious when done manually. S2P lets you interactively navigate your codebase, toggle files on/off, preview the combined output, and copy everything to your clipboard in one keystroke. It respects your .gitignore automatically.

Interactive Selection

Browse and toggle files visually

Token Counting

tiktoken-accurate, real-time

Clipboard Copy

One keystroke to copy output

Gitignore-Aware

Respects .gitignore automatically

Essential Commands

Launch interactive TUI in current directory
Open specific directory
Show all options
Note
S2P is built with React and Ink, giving you a beautiful terminal UI. Use arrow keys to navigate, Space to toggle files, and Enter to confirm your selection.

TUI Navigation

Once you launch S2P, you get an interactive file browser. Here are the key controls:

bash
# Keyboard Controls
↑/↓ Navigate between files
Space Toggle file selection
Enter Expand/collapse directories
a Select all files
n Deselect all files
c Copy to clipboard
q / Esc Quit

The interface shows you the total token count in real-time as you select files. This helps you stay within Claude's or GPT's context window limits.

Try It: Source Bundling Laboratory

Explore different project types below. Toggle source files, apply glob filters, and watch S2P scan, measure, and combine them into a single LLM-ready prompt.

Select Project Type

Next.js frontend with components and hooks — context: 32K

Token Budget
0/32,000
0 files selected0.0% of 32K context
Source Files
7 files
Combined Prompt

Select files to preview prompt

Toggle files in the tree or use Select All

Pro Tip
In the real S2P TUI, press Space to toggle files, Enter to expand directories, and c to copy the combined prompt to your clipboard. Use --include for glob filtering.

Example Workflow

bash
# Navigate to your project
cd /data/projects/my-app
# Launch S2P
s2p
# In the TUI:
# 1. Navigate to src/ directory
# 2. Select relevant TypeScript files
# 3. Watch token count update
# 4. Press 'c' to copy to clipboard
# Now paste into Claude/GPT with your question:
# "Here's my source code. Can you help me..."
Pro Tip
S2P formats the output with clear file path headers and syntax-appropriate code blocks, making it easy for LLMs to understand the code structure.

Synergies with Other Tools

S2P works great alongside other flywheel tools:

  • CASS: The prompts you create with S2P can be searched later in your agent session history.
  • CM (CASS Memory): Use S2P outputs as reference material when extracting rules for your memory playbook.
  • NTM: Launch S2P in a dedicated tmux pane while your agent works in another.

Ready to level up?

Mark complete to track your learning progress.