packx

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PACKX - AI Context Bundler

PACKX - AI上下文打包工具

Bundle and filter code files for AI context.
为AI上下文打包并过滤代码文件。

CRITICAL: Always Use
--limit 49k

重要提示:请始终使用
--limit 49k

MANDATORY: Every packx command MUST include
--limit 49k
unless the user explicitly requests a different limit. This is non-negotiable. Using 49k instead of 50k provides a safety buffer.
bash
undefined
强制要求:所有packx命令必须包含
--limit 49k
,除非用户明确要求其他限制。这一点没有商量余地。使用49k而非50k是为了留出安全缓冲空间。
bash
undefined

CORRECT - always include --limit 49k

正确示例 - 始终包含--limit 49k

packx --limit 49k -c src/ packx --limit 49k -s "pattern" -i "*.ts" -c
packx --limit 49k -c src/ packx --limit 49k -s "pattern" -i "*.ts" -c

WRONG - never omit the limit

错误示例 - 绝不能省略限制参数

packx -c src/ # NO! Missing --limit packx -s "pattern" -i "*.ts" -c # NO! Missing --limit
undefined
packx -c src/ # 错误!缺少--limit packx -s "pattern" -i "*.ts" -c # 错误!缺少--limit
undefined

Prerequisites

前置条件

bash
packx --version    # Verify installed
npm install -g packx   # If not installed
bash
packx --version    # 验证是否已安装
npm install -g packx   # 若未安装则执行此命令

Standard Command Pattern

标准命令格式

bash
packx --limit 49k [filters] [output] [paths]
Always start with
--limit 49k
, then add filters and output options.
bash
packx --limit 49k [过滤参数] [输出参数] [路径]
请始终以
--limit 49k
开头
,然后添加过滤和输出选项。

CLI Reference

CLI参考

Token Budget (Required)

Token预算(必填)

bash
undefined
bash
undefined

Standard (default for all commands)

标准用法(所有命令的默认设置)

packx --limit 49k -c src/
packx --limit 49k -c src/

Only use different limits if user explicitly requests

仅当用户明确要求时才使用不同的限制

packx --limit 32k -c src/ # User said "32k" packx --limit 128k -c src/ # User said "large context"
packx --limit 32k -c src/ # 用户要求"32k" packx --limit 128k -c src/ # 用户要求"大上下文"

Split into chunks if content exceeds limit (requires -o for numbered files)

若内容超出限制则拆分块(需要使用-o参数生成编号文件)

packx -M 49k -o context src/ # Creates context-1.xml, context-2.xml

**Limit formats:** `8k`=8,000 | `32K`=32,768 | `50000`=50,000
packx -M 49k -o context src/ # 生成context-1.xml, context-2.xml

**限制格式**:`8k`=8,000 | `32K`=32,768 | `50000`=50,000

Search & Filter

搜索与过滤

bash
undefined
bash
undefined

Find files containing text

查找包含指定文本的文件

packx --limit 49k -s "TODO" -c packx --limit 49k -s "useState" -i "*.tsx" -c packx --limit 49k -s "error" -s "warning" -c
packx --limit 49k -s "TODO" -c packx --limit 49k -s "useState" -i "*.tsx" -c packx --limit 49k -s "error" -s "warning" -c

Exclude content

排除指定内容

packx --limit 49k -S "test" -S "mock" -c
packx --limit 49k -S "test" -S "mock" -c

Filter by glob patterns

按glob模式过滤

packx --limit 49k -i ".ts" -c packx --limit 49k -i "src/**/.tsx" -c packx --limit 49k -x ".test.ts" -x ".spec.ts" -c
packx --limit 49k -i ".ts" -c packx --limit 49k -i "src/**/.tsx" -c packx --limit 49k -x ".test.ts" -x ".spec.ts" -c

Regex patterns

正则表达式模式

packx --limit 49k -R -s "function\s+\w+" -c
packx --limit 49k -R -s "function\s+\w+" -c

Case-sensitive

区分大小写

packx --limit 49k -C -s "Error" -c
undefined
packx --limit 49k -C -s "Error" -c
undefined

Git Integration

Git集成

bash
packx --limit 49k --staged -c        # Staged files
packx --limit 49k --diff -c          # Changed from main
packx --limit 49k --dirty -c         # Modified/untracked
bash
packx --limit 49k --staged -c        # 暂存区文件
packx --limit 49k --diff -c          # 与main分支相比有变更的文件
packx --limit 49k --dirty -c         # 已修改/未跟踪的文件

Processing Options

处理选项

bash
undefined
bash
undefined

Strip comments (reduces tokens)

移除注释(减少Token数量)

packx --limit 49k --strip-comments -c src/
packx --limit 49k --strip-comments -c src/

Minify (remove empty lines)

压缩(移除空行)

packx --limit 49k --minify -c src/
packx --limit 49k --minify -c src/

Both (maximum token efficiency)

同时使用两者(最大化Token效率)

packx --limit 49k --strip-comments --minify -c src/
packx --limit 49k --strip-comments --minify -c src/

Context lines around matches

匹配内容的上下文行数

packx --limit 49k -s "TODO" -l 5 -c
packx --limit 49k -s "TODO" -l 5 -c

Follow imports

跟随导入关系

packx --limit 49k --follow-imports src/index.ts -c
packx --limit 49k --follow-imports src/index.ts -c

Related files (tests, stories)

关联文件(测试、Storybook文件)

packx --limit 49k -r src/utils.ts -c
undefined
packx --limit 49k -r src/utils.ts -c
undefined

Output Options

输出选项

bash
undefined
bash
undefined

Copy to clipboard (most common)

复制到剪贴板(最常用)

packx --limit 49k -c src/
packx --limit 49k -c src/

Save to file (use --stdout > to avoid WriteFile hook limits)

保存到文件(使用--stdout > 以避免WriteFile钩子的大小限制)

packx --limit 49k --stdout src/ > context.md
packx --limit 49k --stdout src/ > context.md

Output formats

输出格式

packx --limit 49k -f xml -c src/ # XML (default) packx --limit 49k -f markdown -c src/ # Markdown packx --limit 49k -f plain -c src/ # Plain text packx --limit 49k -f jsonl -c src/ # JSONL

**IMPORTANT:** Always use `--stdout > <file>` instead of `--output <file>` to avoid triggering WriteFile hook size limits on large bundles.
packx --limit 49k -f xml -c src/ # XML(默认格式) packx --limit 49k -f markdown -c src/ # Markdown packx --limit 49k -f plain -c src/ # 纯文本 packx --limit 49k -f jsonl -c src/ # JSONL

**重要提示**:请始终使用`--stdout > <file>`而非`--output <file>`,以避免在打包大文件时触发WriteFile钩子的大小限制。

Preview (Check Before Packing)

预览(打包前检查)

bash
undefined
bash
undefined

Preview matching files without packing

预览匹配的文件但不执行打包

packx --limit 49k --preview src/ packx --limit 49k -s "pattern" --preview
undefined
packx --limit 49k --preview src/ packx --limit 49k -s "pattern" --preview
undefined

Interactive Mode

交互模式

bash
packx --limit 49k -I src/            # Interactive selection
packx --limit 49k --no-interactive src/  # Scripting mode
Controls: Tab=preview focus | PgUp/PgDn=scroll | Enter=confirm
bash
packx --limit 49k -I src/            # 交互式选择
packx --limit 49k --no-interactive src/  # 脚本模式
操作说明:Tab=切换预览焦点 | PgUp/PgDn=滚动 | Enter=确认

Bundles (Saved Configs)

打包配置(已保存的配置)

bash
packx -b api                         # Load .pack/bundles/api
bash
packx -b api                         # 加载.pack/bundles/api配置

Common Workflows

常见工作流

Default: Feature Context

默认:功能上下文

bash
undefined
bash
undefined

Most common - search for feature, copy to clipboard

最常用 - 搜索功能相关代码,复制到剪贴板

packx --limit 49k -s "auth" -i "*.ts" -c
undefined
packx --limit 49k -s "auth" -i "*.ts" -c
undefined

PR Review Context

PR评审上下文

bash
packx --limit 49k --diff -c
packx --limit 49k --staged -f markdown --stdout > pr.md
bash
packx --limit 49k --diff -c
packx --limit 49k --staged -f markdown --stdout > pr.md

Debug Context

调试上下文

bash
packx --limit 49k --follow-imports src/problem.ts -c
packx --limit 49k -r src/problem.ts -c    # Include tests
bash
packx --limit 49k --follow-imports src/problem.ts -c
packx --limit 49k -r src/problem.ts -c    # 包含测试文件

Minimal Context (Max Efficiency)

最小化上下文(最高效率)

bash
packx --limit 49k --strip-comments --minify -i "*.ts" -c src/
bash
packx --limit 49k --strip-comments --minify -i "*.ts" -c src/

Specific Files

指定文件

bash
undefined
bash
undefined

List specific files directly

直接列出指定文件

packx --limit 49k src/auth.ts src/user.ts src/api.ts -c
undefined
packx --limit 49k src/auth.ts src/user.ts src/api.ts -c
undefined

Best Practices

最佳实践

  1. ALWAYS use
    --limit 49k
    - No exceptions unless user specifies
  2. Use
    -c
    for clipboard
    - Most common output method
  3. Preview first -
    --preview
    to check file selection
  4. Strip noise -
    --strip-comments --minify
    when token-tight
  5. Be specific - Use
    -s
    search and
    -i
    globs to narrow scope
  6. Check git state -
    --diff
    and
    --staged
    for PR context
  1. 始终使用
    --limit 49k
    - 除非用户指定,否则无例外
  2. 使用
    -c
    复制到剪贴板
    - 最常用的输出方式
  3. 先预览 - 使用
    --preview
    检查文件选择是否正确
  4. 移除冗余内容 - 当Token紧张时使用
    --strip-comments --minify
  5. 精准定位 - 使用
    -s
    搜索和
    -i
    glob模式缩小范围
  6. 检查Git状态 - 使用
    --diff
    --staged
    获取PR上下文

Troubleshooting

故障排除

ProblemSolution
Too many tokensAdd
-i "*.ts"
,
-x "test"
, or
--strip-comments
Missing filesCheck globs, use
--preview
Over 49k neededSplit with
-M 49k -o output
(creates numbered files)
WriteFile hook errorUse
--stdout > file.md
instead of
--output file.md
问题解决方案
Token数量过多添加
-i "*.ts"
-x "test"
--strip-comments
文件缺失检查glob模式,使用
--preview
需要超过49k的上下文使用
-M 49k -o output
拆分(生成编号文件)
WriteFile钩子错误使用
--stdout > file.md
替代
--output file.md