Professional CLI tool powered by Apple Intelligence for on-device code generation. Features modern terminal UI, real-time streaming, multi-language support, and conversation management.
Inspired by Apple-AI-CLI.
- Rust 1.70+ (edition 2021)
- macOS 26+ with Apple Intelligence enabled and its on-device model downloaded
- Apple Silicon Mac
- Xcode 26+ or compatible Command Line Tools with
swiftcavailable
cargo install apple-code-assistantThen use the apple-code binary:
apple-code --helpcargo build
cargo run -- --helpTo replace an installed apple-code with the version from this checkout:
cargo install --path . --force
apple-code --versionThe checkout sets MACOSX_DEPLOYMENT_TARGET=26.0 in .cargo/config.toml,
required by the Swift bridge. For a crates.io installation, set it explicitly:
MACOSX_DEPLOYMENT_TARGET=26.0 cargo install apple-code-assistant --force# Simple generation
apple-code -p "hello world in Python" -l python --tool-mode
# Summarize a diff (smartcat-style)
git diff | apple-code -p "summarize the changes" --tool-mode --char-limit 2000 --max-tokens 512
# Use a template for tests
apple-code -p "write tests for this function" -T tests --tool-modeIn tool mode, omit -l for text tasks such as summaries; the configured default
language is only applied outside tool mode. Use -l python (or another language)
when generating code.
The on-device model has a limited context window. The apple_ai 0.1.1 bridge
also duplicates the current prompt in its transcript and can expose model errors
as JSON parsing errors. If a large diff fails, reduce --char-limit and
--max-tokens. These are input/output caps, not a guarantee that a request fits.
--char-limit truncates the input: a summary then covers only that portion of
the diff. For a full review, process smaller diffs separately.
By default, some models may still wrap code in ``` fences and add explanations.
When saving, editing, or redirecting source code, specify its language with -l
and use `--tool-mode` to request raw code and remove Markdown fences. This does
not validate the generated program: review and test it before use.
# Only code written to the file (no markdown, no explanation)
apple-code -p "implement binary search" -l python --save -o binary_search.py --tool-modeYou can further tighten behavior with a prompt template in config.toml, for example:
[prompts.strict_code]
system = "Never use markdown or explanations. Return only the final code."Then call (use --config config.toml to load the file from this checkout;
otherwise configuration is read from the user config directory):
apple-code --config config.toml -p "implement binary search" -l python -T strict_code --save -o binary_search.py --tool-mode# Interactive mode (REPL with logo, /help, /exit, /history, /sessions)
cargo run -- -i
# Interactive Rust session: -l overrides the configured default for this session
apple-code -l rust
# Direct code generation with preview
cargo run -- -p "hello world in Python" -l python --preview
# Save raw Rust code, without terminal formatting or Markdown fences
cargo run -- -p "Implement pub fn sort_numbers(values: &mut [i32]) by calling values.sort_unstable()." -l rust --save -o sort.rs --tool-mode
rustc --edition 2021 --crate-type lib --emit metadata sort.rs
# Copy to clipboard
cargo run -- -p "utility function" --copy
# Use stdin as context (pipe data in, smartcat-style)
git diff | apple-code -p "summarize the changes"
git diff | apple-code -p "summarize the changes" > summary.txt
cat src/main.rs | apple-code -p "add doc comments to this code" -l rust --tool-mode
# Use prompt templates from config.toml
apple-code -p "write tests for this function" -T tests
apple-code -p "refactor this module" -T refactor -l rust
# Extend previous conversation in non-interactive mode
apple-code -p "summarize the architecture of this project" --extend-conversation
apple-code -p "now propose improvements" --extend-conversation
# Repeat input before output (useful in editors)
git diff | apple-code -p "apply these changes but fix formatting" --repeat-input --tool-mode
# Limit size of piped/context data and add globbed context files
git diff | apple-code -p "summarize the changes" --char-limit 8000 --context-glob "src/**/*.rs"
# Edit a copy: --edit overwrites its input file
cp src/main.rs main.generated.rs
cargo run -- -p "Import anyhow::Context and add .context(\"Failed to load configuration\") to the Config::load result. Keep main returning anyhow::Result<()> and preserve the CLI behavior. Return the complete source file." -l rust --tool-mode -e main.generated.rs
# Review the result before integrating it; diff exits with 1 when files differ
# Do not replace src/main.rs until the generated code has been checked and tested
diff -u src/main.rs main.generated.rs
# Configuration
cargo run -- config --list
cargo run -- config --get theme
cargo run -- config --set default_language=python
cargo run -- config --reset
# List models and languages, test API
cargo run -- models
cargo run -- languages
cargo run -- test- Config – Load from
.envand~/.config/apple-code-assistant/config.toml; subcommandconfig --list/get/set/reset - Terminal UI – ASCII logo, theme (light/dark), bordered code preview
- Code generation – Trait-based client (mock included); direct mode with
-pand options - REPL – Interactive mode with
/help,/exit,/clear,/history,/sessions,/models,/languages,/test - Conversations – Sessions persisted under config dir;
/historyand/sessions - File operations –
--save -o <file>,--edit <file> - Clipboard –
--copy(arboard) - Syntax highlighting – syntect in preview and REPL when language is set
- Multi-language – 20+ languages and aliases;
languagessubcommand; validation of--language - Stdin piping – When stdin is not a TTY (e.g.
git diff | apple-code -p "…") the piped content is appended to the prompt (smartcat-style) - Prompt templates – Templates configurables dans
config.toml, sélectionnés via--template/-T - CLI conversations –
--extend-conversationpour réutiliser la dernière session,--repeat-inputpour rejouer l’entrée avant la sortie - Context control –
--char-limitpour borner la taille de stdin/contexte,--context-globpour ajouter des fichiers de contexte par glob - Tool mode –
--tool-modepour une sortie brute adaptée aux éditeurs (aucun cadre ni mise en forme) - Signals – Ctrl+C handled with “Operation cancelled”
A step-by-step development plan (phases 1–8) is in docs/DEVELOPMENT_PLAN.md.
MIT