Focus on a task
A focus query combines lexical matching with the repository's dependency graph. BM25F scores terms in file metadata and source spans, while personalized PageRank uses local dependency edges to carry relevance between connected files.
Describe the task
Use identifiers and concepts that appear in the code:
contextcraft . --focus "validate an expired authentication token" --budget 8000 -o context.md
A query changes relative scores rather than requiring every word to appear in a file. Dependencies can remain useful even when their names do not match the task.
Favor paths
Repeat --focus-file to favor several paths or glob patterns:
contextcraft . --focus-file 'src/auth/**' --focus-file 'src/session/**' -o context.md
Path focus changes ranking, while exclusions remove inputs from directory discovery. Neither path focus nor a high score guarantees full source, because allocation also weighs the token cost of each available tier.
Configure focus in Python
from dataclasses import replace
from contextcraft import Config, Engine
config = Config(budget_tokens=8000, focus_files=("src/auth/**",))
with Engine(config) as engine:
with engine.analyze_path(".") as analysis:
artifact = engine.generate(analysis, replace(config, focus_query="refresh token"))
An analysis can be reused for several focus queries without rereading the repository. Changing discovery settings requires a new analysis.
Continue with set budget and detail to control how much of the ranked source can fit in the artifact.