code2skill can be used as a Python package as well as a CLI. The Python API follows the same workflow as the CLI: preview, scan, adapt, validate, and refresh in CI.
The supported high-level API is available from code2skill.api and re-exported from the package root.
from code2skill import (
adapt_repository,
create_scan_config,
doctor,
estimate,
run_ci,
scan,
)Useful contracts are also exported:
from code2skill import (
AdoptionCheck,
AdoptionReadiness,
ArtifactLayout,
CommandRunSummary,
PricingConfig,
RunOptions,
ScanConfig,
ScanExecution,
ScanLimits,
)from code2skill import estimate
preview = estimate(".", output_dir=".code2skill")
print(preview.report_path)
print(preview.report.first_generation_cost.input_tokens)estimate(...) writes report.json, does not call an LLM, and does not write Skills or state.
from code2skill import scan
result = scan(".", structure_only=True)
print(result.output_files)This validates repository scanning and writes structural artifacts without planning or generating Skills.
from code2skill import adapt_repository, doctor, scan
result = scan(
".",
llm_provider="qwen",
llm_model="qwen-plus-latest",
max_skills=6,
)
written = adapt_repository(".", target="codex")
readiness = doctor(".", target="codex")
print(result.generated_skills)
print(written)
print(readiness.ready, readiness.score)from code2skill import doctor, run_ci
result = run_ci(
".",
mode="auto",
base_ref="origin/main",
head_ref="HEAD",
llm_provider="qwen",
llm_model="qwen-plus-latest",
)
readiness = doctor(".", target="codex")
if not readiness.ready:
raise SystemExit(readiness.next_steps)Use create_scan_config(...) when you need to build a config once and pass it to a lower-level repository runner:
from code2skill import create_scan_config, run_ci_repository
config = create_scan_config(
repo_path=".",
command="ci",
mode="auto",
output_dir=".code2skill",
base_ref="origin/main",
llm_provider="qwen",
llm_model="qwen-plus-latest",
)
result = run_ci_repository(config)Run the repository workflow and write the artifact bundle.
Common parameters:
repo_path="."output_dir=".code2skill"mode="full"structure_only=Falsellm_provider="openai"llm_model=Nonemax_skills=8
For OpenAI-compatible Responses endpoints, set CODE2SKILL_OPENAI_API_KEY and CODE2SKILL_OPENAI_BASE_URL; the Python API uses the same backend configuration as the CLI.
Run the report-only preview path.
Common parameters:
repo_path="."output_dir=".code2skill"mode="auto"base_ref=Nonehead_ref="HEAD"pricing_file=None
Run the automation-oriented path that can choose between full and incremental execution.
Common parameters:
repo_path="."output_dir=".code2skill"mode="auto"base_ref=Nonehead_ref="HEAD"diff_file=Nonestructure_only=Falsellm_provider="openai"llm_model=None
Publish generated Skills to target tool files under the repository root.
adapt_repository(".", target="codex")
adapt_repository(".", target="all")Relative source_dir values are resolved from repo_path.
Inspect readiness without writing files or calling an LLM.
readiness = doctor(".", target="codex")doctor(...) returns AdoptionReadiness, including:
readyscorechecksmissing_pathsnext_steps
scan(...), estimate(...), and run_ci(...) return ScanExecution:
repo_pathoutput_diroutput_filescandidate_countselected_counttotal_charsrun_modechanged_filesaffected_filesaffected_skillsgenerated_skillsreport_pathreport
The embedded ExecutionReport distinguishes:
final_product_files: generated Skill artifacts inside the bundleintermediate_artifact_files: blueprint, plan, references, report, adoption guide, project summary, and state-side artifacts
repo_path is resolved first and treated as the repository root.
- Relative
output_dirvalues are resolved fromrepo_path. - Relative
report_path,diff_file, andpricing_filevalues are resolved fromrepo_path. - Relative
source_dirvalues passed toadapt_repository(...)are resolved fromrepo_path. - If
report_pathis omitted, it defaults tooutput_dir/report.json.
Incremental state is reused only when the saved snapshot belongs to the same resolved repository root. Invalid or damaged state files are treated as missing state and fall back safely.