一键导入
context-budget
Optimize token usage and context window discipline. Reduce costs and improve response quality through smart context management.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Optimize token usage and context window discipline. Reduce costs and improve response quality through smart context management.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Unified context lifecycle for FlowDeck sessions — ingest, filter, prune, protect, summarize, and persist with telemetry.
Predict affected files, modules, APIs, tests, and DB paths before changes. Returns an impact map for human review.
Map architecture, conventions, and file structure into `.codebase/`. Use when onboarding or before deep feature work.
Plan differently when the agent has low certainty — ask for clarification or narrow scope instead of pretending full understanding.
Protect critical context from pruning during compaction. Preserve active plans, safety files, pending operations, and user intent anchors.
Load full project context at session start. Read STATE.md, PLAN.md, PROJECT.md, CONVENTIONS.md, and ARCHITECTURE.md to brief any agent on where work stands.
| name | context-budget |
| description | Optimize token usage and context window discipline. Reduce costs and improve response quality through smart context management. |
| origin | FlowDeck |
Treat context window as a finite resource. Every token loaded — files, rules, tool outputs, conversation history — consumes budget. Optimizing context improves speed, cuts costs, and prevents mid-session truncation.
Activate when:
| Factor | Impact |
|---|---|
| Context window limit | Hard cap — exceed it and early conversation is lost |
| Cost per token | More context = more input tokens = higher bill |
| Response latency | Large context increases time-to-first-token |
| Attention degradation | Models perform worse on content near the middle of long context |
| Model | Context Window |
|---|---|
| Claude 3.5 Haiku | 200K tokens |
| Claude 3.5 Sonnet | 200K tokens |
| GPT-4o | 128K tokens |
| GPT-4o mini | 128K tokens |
Treat 80% of the window as your practical maximum. Beyond that, truncation risk rises sharply.
Oversized skills waste context on every activation. Audit yours regularly.
| Metric | Warning | Critical |
|---|---|---|
| Lines per SKILL.md | > 300 | > 400 |
| Words in description | > 25 | > 30 |
| Files loaded per task | > 5 | > 10 |
| Rules active at once | > 8 | > 12 |
# Count lines in all skills
find src/skills -name "SKILL.md" -exec wc -l {} + | sort -n
# Flag skills over 300 lines
find src/skills -name "SKILL.md" -exec sh -c 'lines=$(wc -l < "$1"); [ "$lines" -gt 300 ] && echo "$lines $1"' _ {} \;
# Check description word counts
grep -r "^description:" src/skills/ | awk '{print NF, $0}' | sort -n
execute or verify stages.codebase/ARCHITECTURE.md only when neededNot every task needs the strongest model. Route by complexity.
| Task Type | Example | Model Tier |
|---|---|---|
| Simple edit | Fix typo, rename variable | Fast / Small |
| Code review | Lint, style check | Fast / Small |
| Research | Look up API docs | Fast / Small |
| Feature implementation | Multi-file change | Strong / Large |
| Debug | Root cause analysis | Strong / Large |
| Architecture design | New module design | Strong / Large |
FlowDeck routes by agent cost tier:
@mapper (structural lookup, listing, summarization)@planner, @researcher, coders, @tester, @reviewer@architect, @debug-specialist, @security-auditor, @orchestratorRespect this routing. Do not escalate a cheap task to an expensive agent.
MCP servers add context overhead: schema discovery, tool definitions, and response envelopes. Native CLI tools are leaner.
| Use Case | Heavy MCP | Lean Alternative |
|---|---|---|
| Git operations | GitHub MCP | git, gh CLI |
| AWS queries | AWS MCP | aws CLI |
| Kubernetes checks | K8s MCP | kubectl |
| File search | File-system MCP | find, rg |
| Database query | DB MCP | psql, mysql CLI |
Chatty sessions burn context fast. Accumulate edits, then run checks once.
Edit file A → run test → fix error → edit file B → run test → fix error → edit file C → run test
Each test run consumes output tokens. Three runs = 3x test output in context.
Edit file A
Edit file B
Edit file C
Run tests once
Fix all errors
Use /fd-checkpoint after a batch of edits, then /fd-resume to continue. This preserves your work without carrying full error output forward indefinitely.
Long sessions accumulate noise: failed attempts, dead-ends, large tool outputs. Clear context before it degrades quality.
| Signal | Action |
|---|---|
| Session > 1 hour | /fd-checkpoint |
| Tokens > 50K | /fd-checkpoint |
| Multiple failed attempts | /fd-checkpoint and reassess |
| Task complete, new task next | /fd-checkpoint |
1. `/fd-checkpoint` — save current state to STATE.md
2. Start fresh session
3. `/fd-resume` — load checkpoint.json, STATE.md, plan.md, active context
4. Continue with clean context
This is cheaper than carrying 80K tokens of conversation history.
FlowDeck uses stage-gated rules. Only rules matching the current stage are loaded.
| Stage | Typical Rules Loaded |
|---|---|
discuss | Behavioral, lightweight |
plan | Planning, architecture |
execute | Coding standards, language patterns, security |
verify | Testing, security, linting |
fix-bug | Debug, testing |
stages array to gate loadingalways_on: false for heavy rulesAudit with:
# Find rules loaded in every stage (always_on = true)
grep -r "always_on: true" src/rules/
# Find oversized rules
find src/rules -name "*.md" -exec sh -c 'lines=$(wc -l < "$1"); [ "$lines" -gt 200 ] && echo "$lines $1"' _ {} \;
Smaller files = less context per task. A 400-line file forces the model to hold the entire file in working memory. Four 100-line files let the model focus on one at a time.
| File Size | Context Impact |
|---|---|
| < 200 lines | Minimal — load on demand |
| 200-400 lines | Moderate — acceptable for core files |
| 400-800 lines | Heavy — consider splitting |
| > 800 lines | Critical — split immediately |
utils/ or helpers/types.tscodegraph to find natural split points: codegraph_impact on a large symbol reveals which parts are independentRun this monthly or when context feels heavy:
.opencode/skills/always_on: false)/fd-checkpoint used at natural boundariescodegraphgit diff | head -50 instead of full difftail -20 instead of full log filecodegraph_search — find symbols without reading entire filesload-rules instead of pre-loading everythingplan-task — break work into right-sized chunksperformance-profiling — measure before optimizingcontext-load — load only the context you need/fd-checkpoint — save session state, clear context/fd-resume — restore from checkpointload-rules — stage-gated rule loadingcodegraph — symbol search without full-file readscodegraph_impact — find split points in large filescodegraph_search — locate symbols efficiently