| name | use-zephyr-cli |
| description | Guides AI agents to correctly use zephyr-cli and the west agent extension when working on Zephyr RTOS projects. Covers building, inspecting (Kconfig, Devicetree, memory, threads), emulating, testing, flashing, debugging, and safely managing Zephyr domain skills and documentation. Use this skill whenever the user is working on a Zephyr project, mentions west builds, Kconfig symbols, devicetree overlays, board targets, Zephyr SDK, flashing firmware, QEMU emulation, Twister tests, or asks about any zephyr-cli or west agent command — even if they don't name the tool explicitly. Also use when the user wants to find or install Zephyr skills, refresh Zephyr docs, or scaffold a new Zephyr project.
|
Using zephyr-cli and west agent
This skill teaches you how to use two complementary tools for Zephyr RTOS development:
zephyr-cli — A global CLI for environment inspection, SDK management, project scaffolding, skills, and docs. Works anywhere.
west agent — A west extension for build, inspect, emulate, test, flash, and debug. Requires a west workspace.
Both tools emit structured JSON by default when stdout is not a TTY (i.e., when you're piping output or running programmatically). This is intentional — JSON output is precise and parseable, so prefer it when you need to extract data. Use --format human only when showing output directly to the user.
For the full flag reference for every command, read references/commands.md in this skill's directory.
First step: Orient yourself
Before doing anything else in a Zephyr workspace, run:
zephyr-cli env --format json
This tells you:
- Whether the Zephyr SDK is installed and which version is active
- Whether
west is available and initialized
- The workspace root path
- Which Zephyr skills are already installed
- The docs cache status
Parse this output to understand what's available before suggesting installations or builds. If ZEPHYR_BASE isn't set or west isn't initialized, address that first.
Building firmware
west agent --format json build --board <board>
Note: --format is a top-level west agent flag — it goes before the subcommand.
Key patterns:
- Always specify
--board explicitly (e.g., nrf52840dk/nrf52840, qemu_cortex_m3). Don't rely on the $BOARD env var — it may not be set.
- Use
--pristine for clean rebuilds when changing boards or after significant config changes.
- Apply extra Kconfig settings via
--extra-conf myoverlay.conf — this sets OVERLAY_CONFIG and merges with the project's prj.conf.
- The build directory defaults to
build/<board-slug>. Override with --build-dir if needed.
- Build errors come back as structured JSON — check
errors[].message for actionable error details and raw_stderr for the full build log. Don't try to parse raw log output.
Inspecting the build
west agent inspect has several subcommands. Some require build artifacts (kconfig, dts, memory, threads) — build first before using those. Others (modules, bindings, env) work without a prior build.
Kconfig
Use inspect kconfig to understand what's enabled and why:
west agent --format json inspect kconfig --symbol CONFIG_BT
west agent --format json inspect kconfig --search 'BT_.*'
west agent --format json inspect kconfig --changed
The --symbol output includes the dependency chain, which is invaluable for understanding why a symbol is enabled or disabled. When a user asks "why can't I enable X?", use --symbol to trace the dependency tree.
Devicetree
west agent --format json inspect dts
west agent --format json inspect dts --node /soc/i2c@40003000
west agent --format json inspect dts --compatible nordic,nrf-spim
west agent --format json inspect dts --chosen
Memory, threads, modules, bindings
west agent --format json inspect memory
west agent --format json inspect threads
west agent --format json inspect modules
west agent --format json inspect bindings --compatible nordic,nrf-uart
west agent --format json inspect bindings --search 'spi.*controller'
Managing Zephyr skills
Zephyr skills are modular knowledge packs (markdown files with optional code templates) that provide current, Zephyr-specific guidance on topics like BLE GATT setup, devicetree overlays, or power management. They live in .zephyr/skills/<name>/ in the workspace.
The anti-clobber rule
Installed skills may have been customized by the developer or by you in a previous session. Treat them as potentially modified files — never overwrite without asking.
Before installing any skill:
zephyr-cli skills list --installed --format json
Parse the output. If the skill is already installed, do not re-install it. Instead, read the existing .zephyr/skills/<name>/SKILL.md to use its guidance.
Only use --force if the user explicitly asks to update or re-download a skill. Explain that --force will overwrite their local copy.
Finding the right skill
zephyr-cli skills suggest "bluetooth low energy peripheral" --format json
zephyr-cli skills suggest "wireless" --kconfig CONFIG_BT,CONFIG_BT_PERIPHERAL --format json
zephyr-cli skills suggest "sensor" --dts bosch,bme280 --format json
The suggest command uses deterministic lexical scoring (not an LLM) — Kconfig and DTS matches score highest (8.0 each), so always pass them when available. You can get the active Kconfig symbols via west agent --format json inspect kconfig --changed.
Installing and using
zephyr-cli skills install <name> --format json
zephyr-cli skills show <name> --format json
zephyr-cli skills apply <name> --target src/ --format json
After installing, read the skill's SKILL.md:
cat .zephyr/skills/<name>/SKILL.md
These skills contain up-to-date Zephyr guidance that supplements your training data. Prefer their recommendations over your built-in knowledge when there's a conflict — the skills track the latest Zephyr releases.
Complete workflow example
zephyr-cli skills list --installed --format json
west agent --format json inspect kconfig --changed
zephyr-cli skills suggest "bluetooth" --kconfig CONFIG_BT,CONFIG_BT_PERIPHERAL --format json
zephyr-cli skills install ble-peripheral --format json
cat .zephyr/skills/ble-peripheral/SKILL.md
Documentation
Zephyr docs can be cached locally as LLM-optimized markdown. These are useful as authoritative context when the user asks about Zephyr APIs, configuration, or hardware support.
zephyr-cli docs list --format json
zephyr-cli docs refresh --format json
zephyr-cli docs refresh --version v4.1.0 --format json
Docs are cached at ~/.local/share/zephyr-cli/docs/<version>/. Once cached, you can read files from that directory for context.
Emulating
west agent --format json emulate
west agent --format json emulate --backend qemu
west agent --format json emulate --timeout 60
The auto-detect logic picks QEMU for boards like qemu_cortex_m3 and native_sim for native_sim targets. Always set a timeout when running programmatically to avoid hanging.
Testing
west agent --format json test --platform qemu_cortex_m3
west agent --format json test --platform qemu_cortex_m3 --build-only
west agent --format json test --platform qemu_cortex_m3 --inline-logs
Use --inline-logs when you need to diagnose test failures — it embeds the full test output in the JSON response.
Flashing and debugging
west agent --format json flash
west agent --format json flash --runner jlink
west agent --format json debug --server
west agent --format json debug --rtt-port 19021 --rtt-timeout 30
Scaffolding new projects
zephyr-cli create my-app --board nrf52840dk/nrf52840 --format json
zephyr-cli create my-app --topology T2 --board nrf52840dk/nrf52840 --format json
After scaffolding, follow the generated next-steps in the output to initialize the workspace.
SDK management
zephyr-cli sdk list --available --format json
zephyr-cli sdk install 0.16.8 --format json
zephyr-cli sdk select 0.16.8 --format json
Key principles to remember
- JSON first. Always use
--format json when you need to parse output. Human format is for display only.
- Orient before acting. Run
zephyr-cli env at the start of every session to understand the workspace state.
- Don't clobber skills. Check
skills list --installed before installing. Never use --force without the user's explicit request.
- Use Kconfig/DTS context for skill discovery. The
--kconfig and --dts flags on skills suggest give much better results than plain text queries.
- Read installed skills. After installing a skill, read its
SKILL.md — it contains current best practices that may be newer than your training data.
- Build before inspecting (some subcommands). The
kconfig, dts, memory, and threads inspect subcommands require build artifacts. modules, bindings, and env work without a build.
- Set timeouts on emulation. Always pass
--timeout when running west agent emulate programmatically to avoid indefinite hangs.