arbazkhan971/bharatcode-cli

BharatCode โ€” an open, sovereign terminal AI coding agent. OpenCode for India. Local-first, your code stays in India.

Rust

1

38 commits

updated Sep 12, 2026

See the code

README

BharatCode

Your code stays in India ๐Ÿ‡ฎ๐Ÿ‡ณ

A local-first, Apache-2.0, Rust terminal AI coding agent โ€” built for India.

License: Apache-2.0 Local-first by default Telemetry off by default Built with Rust

BharatCode is a terminal-native AI coding agent that runs on your machine and, by default, talks to a local model instead of a cloud API. It is engineered for developers who want data residency, predictable cost in rupees, and a tool that defaults to keeping work on-device โ€” without giving up a modern agentic coding experience.


Why BharatCode

  • Local-first by default. With nothing configured, BharatCode targets a local Ollama provider and a local model โ€” no forced cloud sign-in. Cloud and hosted providers remain available, but they are opt-in.
  • Data residency. An opt-in egress guard can block requests to endpoints outside an India allowlist, and an offline switch can lock the agent to local-only operation.
  • Cost in rupees. A built-in INR cost ledger and an optional budget cap let you track and bound spend in โ‚น, not dollars.
  • India model presets. First-class presets and declarative providers for India-hosted, open-weight friendly options (Sarvam, Krutrim) alongside local Qwen-Coder / DeepSeek via Ollama.
  • Telemetry off. No product analytics phone-home; telemetry is disabled in code, not merely defaulted off.

Install (build from source)

BharatCode is currently built from source. You need a recent Rust toolchain (rustup + cargo; the repo pins a toolchain via rust-toolchain.toml).

# from the repo root
cargo build -p bharatcode-cli --no-default-features --features portable-default

This produces the bharatcode binary:

./target/debug/bharatcode --help
./target/debug/bharatcode --version

Notes:

  • The portable-default feature set is the light build: it drops heavy native in-process inference engines (llama.cpp / candle / mlx), code-mode, and the system keyring so the CLI builds quickly and runs anywhere. A plain cargo build uses the default features and pulls those engines in.
  • Because BharatCode is local-first, the recommended setup is to install Ollama and pull a coding model, then run bharatcode with no provider configured โ€” it will target your local Ollama by default.

Quick start

# 1) (recommended) run a local model
ollama pull qwen2.5-coder       # or any coding model you prefer

# 2) start BharatCode in your project
bharatcode

# first run walks you through setup; "Local model โ€” Ollama (Recommended)"
# is offered first, so you can stay fully on-device.

Handy commands:

bharatcode                  # interactive session in the current directory
bharatcode tui              # terminal UI (launches the ui/text artifact)
bharatcode presets          # list the India / open-weight model presets
bharatcode cost             # INR spend ledger (per session / day / month)
bharatcode git              # read-only summary of the current git repo
bharatcode recipes-library  # curated recipe templates for Indian dev workflows
bharatcode doctor           # environment + BharatCode settings summary
bharatcode configure        # providers, models, and onboarding

Features

Everything below is actually built and wired in this repository. Features that are opt-in / default OFF are marked with the environment variable that turns them on.

Always on

  • Local-first defaults โ€” with no provider configured, BharatCode targets a local Ollama provider and a local default model; env/config/cloud still take precedence when you set them.
  • apply_patch file-editing tool โ€” a streaming patch parser/applier in the bharatcode-apply-patch crate, wired into the developer toolset as the apply_patch tool.
  • INR cost ledger โ€” per-session / day / month spend tracked and shown in โ‚น via bharatcode cost, with a compact โ‚น figure in the session footer. USDโ†’INR rate is configurable with BHARATCODE_USD_INR; day/month buckets use IST.
  • India model presets โ€” declarative sarvam and krutrim providers plus a presets module / bharatcode presets listing and a "Recommended (India / open-weight)" first-run choice (local Qwen-Coder / DeepSeek via Ollama; hosted Sarvam / Krutrim / Qwen / DeepSeek).
  • India recipe library โ€” bharatcode recipes-library ships curated templates (e.g. UPI review, Aadhaar/PII + DPDP audit, GST helper, Indic localization).
  • bharatcode git โ€” a concise, read-only repo summary (branch, status, ahead/behind, recent commits).
  • bharatcode doctor โ€” environment checks plus a read-only summary of the active BharatCode settings (residency mode, budget, USDโ†”INR rate, offline, etc.).
  • Tiranga theme โ€” a saffron/white/green CLI palette, selectable with BHARATCODE_THEME (tiranga / bharat / india); honors NO_COLOR, and when unset the output is byte-identical to the default theme.
  • Telemetry off โ€” product analytics are disabled in code (no PostHog key, the enablement check returns false); nothing phones home.
  • i18n / Hindi scaffold โ€” a std-only locale resolver (BHARATCODE_LANG โ†’ config โ†’ LANG โ†’ en) with embedded en.json / hi.json and a tr!() helper. A starter set of high-traffic strings is translated to Hindi today; English output is unchanged. This is a scaffold, not a complete Hindi UI.

Opt-in (default OFF)

  • BHARATCODE_SANDBOX โ€” in-process Linux exec sandbox (landlock + seccomp) applied to shell commands. Modes: read-only / workspace-write (default off). Linux-only; a no-op stub elsewhere.
  • BHARATCODE_EXEC_POLICY โ€” path to a JSON allow/deny policy that gates shell commands (a hardened, clean-room exec policy).
  • BHARATCODE_RESIDENCY (+ BHARATCODE_RESIDENCY_ALLOWLIST) โ€” data-residency egress guard that can block requests to non-allowlisted (e.g. non-India) endpoints. Wired centrally so it screens every provider.
  • BHARATCODE_OFFLINE โ€” a single switch that composes local-only egress + residency + telemetry-off for an offline/no-egress posture.
  • BHARATCODE_BUDGET_INR (+ BHARATCODE_BUDGET_MODE = warn default / deny) โ€” an INR spend cap that warns near the cap and, in deny mode, refuses to start the next model turn once exceeded.
  • BHARATCODE_COST_ROUTING โ€” cost-aware routing that prefers cheaper / local models for the lead model when enabled.
  • BHARATCODE_VERIFY โ€” verify-before-done: runs your project's test/build and reports Verified / Failed / Skipped before finalizing.
  • BHARATCODE_CACHE โ€” on-disk prompt/response cache (SHA-256 keyed) wired into the streaming path; a hit short-circuits to a zero-cost stream.
  • BHARATCODE_RETRY_* โ€” retry/backoff tuning (BHARATCODE_RETRY_MAX, BHARATCODE_RETRY_BASE_MS, BHARATCODE_RETRY_MAX_MS) applied centrally so all providers honor it.
  • BHARATCODE_CODEBASE_CONTEXT โ€” a bounded, gitignore-respecting codebase scanner (RAG-lite) that builds a compact repo layout/manifest blob.
  • BHARATCODE_KEYS / BHARATCODE_CLI_NEWLINE_KEY โ€” customizable interactive keybindings (built-in defaults reproduced when unset).
  • BHARATCODE_APPROVAL โ€” approval-mode selection (chat / ask / auto / full) with a safe default when unset.

Heads-up on honesty: the i18n layer is a scaffold (starter Hindi strings only). The sandbox is Linux-only and off by default. Cost routing, prompt cache, retry, residency, offline, budget, exec-policy, verify, and codebase context are all off unless you set their environment variable. None of these change default behavior until you opt in.


Configuration

BharatCode reads its configuration from ~/.config/bharatcode/ and from BHARATCODE_* environment variables (the env namespace was rebranded throughout). Common ones:

VariableEffect
BHARATCODE_PROVIDER / BHARATCODE_MODELOverride the active provider / model
BHARATCODE_LANGUI language (en, hi)
BHARATCODE_THEMEtiranga / bharat / india for the Tiranga palette
BHARATCODE_USD_INRUSDโ†’INR rate for the cost ledger
BHARATCODE_OFFLINELocal-only / no-egress posture
BHARATCODE_RESIDENCYEgress residency guard
BHARATCODE_SANDBOXread-only / workspace-write exec sandbox (Linux)

See the per-feature notes above for the full opt-in set.


License

Apache License 2.0 โ€” see LICENSE.

Contributors

arbazkhan971

38 commits

arbazkhan971/bharatcode-cli

BharatCode โ€” an open, sovereign terminal AI coding agent. OpenCode for India. Local-first, your code stays in India.

Rust

1

38 commits

updated Sep 12, 2026

See the code

README

BharatCode

Your code stays in India ๐Ÿ‡ฎ๐Ÿ‡ณ

A local-first, Apache-2.0, Rust terminal AI coding agent โ€” built for India.

License: Apache-2.0 Local-first by default Telemetry off by default Built with Rust

BharatCode is a terminal-native AI coding agent that runs on your machine and, by default, talks to a local model instead of a cloud API. It is engineered for developers who want data residency, predictable cost in rupees, and a tool that defaults to keeping work on-device โ€” without giving up a modern agentic coding experience.


Why BharatCode

  • Local-first by default. With nothing configured, BharatCode targets a local Ollama provider and a local model โ€” no forced cloud sign-in. Cloud and hosted providers remain available, but they are opt-in.
  • Data residency. An opt-in egress guard can block requests to endpoints outside an India allowlist, and an offline switch can lock the agent to local-only operation.
  • Cost in rupees. A built-in INR cost ledger and an optional budget cap let you track and bound spend in โ‚น, not dollars.
  • India model presets. First-class presets and declarative providers for India-hosted, open-weight friendly options (Sarvam, Krutrim) alongside local Qwen-Coder / DeepSeek via Ollama.
  • Telemetry off. No product analytics phone-home; telemetry is disabled in code, not merely defaulted off.

Install (build from source)

BharatCode is currently built from source. You need a recent Rust toolchain (rustup + cargo; the repo pins a toolchain via rust-toolchain.toml).

# from the repo root
cargo build -p bharatcode-cli --no-default-features --features portable-default

This produces the bharatcode binary:

./target/debug/bharatcode --help
./target/debug/bharatcode --version

Notes:

  • The portable-default feature set is the light build: it drops heavy native in-process inference engines (llama.cpp / candle / mlx), code-mode, and the system keyring so the CLI builds quickly and runs anywhere. A plain cargo build uses the default features and pulls those engines in.
  • Because BharatCode is local-first, the recommended setup is to install Ollama and pull a coding model, then run bharatcode with no provider configured โ€” it will target your local Ollama by default.

Quick start

# 1) (recommended) run a local model
ollama pull qwen2.5-coder       # or any coding model you prefer

# 2) start BharatCode in your project
bharatcode

# first run walks you through setup; "Local model โ€” Ollama (Recommended)"
# is offered first, so you can stay fully on-device.

Handy commands:

bharatcode                  # interactive session in the current directory
bharatcode tui              # terminal UI (launches the ui/text artifact)
bharatcode presets          # list the India / open-weight model presets
bharatcode cost             # INR spend ledger (per session / day / month)
bharatcode git              # read-only summary of the current git repo
bharatcode recipes-library  # curated recipe templates for Indian dev workflows
bharatcode doctor           # environment + BharatCode settings summary
bharatcode configure        # providers, models, and onboarding

Features

Everything below is actually built and wired in this repository. Features that are opt-in / default OFF are marked with the environment variable that turns them on.

Always on

  • Local-first defaults โ€” with no provider configured, BharatCode targets a local Ollama provider and a local default model; env/config/cloud still take precedence when you set them.
  • apply_patch file-editing tool โ€” a streaming patch parser/applier in the bharatcode-apply-patch crate, wired into the developer toolset as the apply_patch tool.
  • INR cost ledger โ€” per-session / day / month spend tracked and shown in โ‚น via bharatcode cost, with a compact โ‚น figure in the session footer. USDโ†’INR rate is configurable with BHARATCODE_USD_INR; day/month buckets use IST.
  • India model presets โ€” declarative sarvam and krutrim providers plus a presets module / bharatcode presets listing and a "Recommended (India / open-weight)" first-run choice (local Qwen-Coder / DeepSeek via Ollama; hosted Sarvam / Krutrim / Qwen / DeepSeek).
  • India recipe library โ€” bharatcode recipes-library ships curated templates (e.g. UPI review, Aadhaar/PII + DPDP audit, GST helper, Indic localization).
  • bharatcode git โ€” a concise, read-only repo summary (branch, status, ahead/behind, recent commits).
  • bharatcode doctor โ€” environment checks plus a read-only summary of the active BharatCode settings (residency mode, budget, USDโ†”INR rate, offline, etc.).
  • Tiranga theme โ€” a saffron/white/green CLI palette, selectable with BHARATCODE_THEME (tiranga / bharat / india); honors NO_COLOR, and when unset the output is byte-identical to the default theme.
  • Telemetry off โ€” product analytics are disabled in code (no PostHog key, the enablement check returns false); nothing phones home.
  • i18n / Hindi scaffold โ€” a std-only locale resolver (BHARATCODE_LANG โ†’ config โ†’ LANG โ†’ en) with embedded en.json / hi.json and a tr!() helper. A starter set of high-traffic strings is translated to Hindi today; English output is unchanged. This is a scaffold, not a complete Hindi UI.

Opt-in (default OFF)

  • BHARATCODE_SANDBOX โ€” in-process Linux exec sandbox (landlock + seccomp) applied to shell commands. Modes: read-only / workspace-write (default off). Linux-only; a no-op stub elsewhere.
  • BHARATCODE_EXEC_POLICY โ€” path to a JSON allow/deny policy that gates shell commands (a hardened, clean-room exec policy).
  • BHARATCODE_RESIDENCY (+ BHARATCODE_RESIDENCY_ALLOWLIST) โ€” data-residency egress guard that can block requests to non-allowlisted (e.g. non-India) endpoints. Wired centrally so it screens every provider.
  • BHARATCODE_OFFLINE โ€” a single switch that composes local-only egress + residency + telemetry-off for an offline/no-egress posture.
  • BHARATCODE_BUDGET_INR (+ BHARATCODE_BUDGET_MODE = warn default / deny) โ€” an INR spend cap that warns near the cap and, in deny mode, refuses to start the next model turn once exceeded.
  • BHARATCODE_COST_ROUTING โ€” cost-aware routing that prefers cheaper / local models for the lead model when enabled.
  • BHARATCODE_VERIFY โ€” verify-before-done: runs your project's test/build and reports Verified / Failed / Skipped before finalizing.
  • BHARATCODE_CACHE โ€” on-disk prompt/response cache (SHA-256 keyed) wired into the streaming path; a hit short-circuits to a zero-cost stream.
  • BHARATCODE_RETRY_* โ€” retry/backoff tuning (BHARATCODE_RETRY_MAX, BHARATCODE_RETRY_BASE_MS, BHARATCODE_RETRY_MAX_MS) applied centrally so all providers honor it.
  • BHARATCODE_CODEBASE_CONTEXT โ€” a bounded, gitignore-respecting codebase scanner (RAG-lite) that builds a compact repo layout/manifest blob.
  • BHARATCODE_KEYS / BHARATCODE_CLI_NEWLINE_KEY โ€” customizable interactive keybindings (built-in defaults reproduced when unset).
  • BHARATCODE_APPROVAL โ€” approval-mode selection (chat / ask / auto / full) with a safe default when unset.

Heads-up on honesty: the i18n layer is a scaffold (starter Hindi strings only). The sandbox is Linux-only and off by default. Cost routing, prompt cache, retry, residency, offline, budget, exec-policy, verify, and codebase context are all off unless you set their environment variable. None of these change default behavior until you opt in.


Configuration

BharatCode reads its configuration from ~/.config/bharatcode/ and from BHARATCODE_* environment variables (the env namespace was rebranded throughout). Common ones:

VariableEffect
BHARATCODE_PROVIDER / BHARATCODE_MODELOverride the active provider / model
BHARATCODE_LANGUI language (en, hi)
BHARATCODE_THEMEtiranga / bharat / india for the Tiranga palette
BHARATCODE_USD_INRUSDโ†’INR rate for the cost ledger
BHARATCODE_OFFLINELocal-only / no-egress posture
BHARATCODE_RESIDENCYEgress residency guard
BHARATCODE_SANDBOXread-only / workspace-write exec sandbox (Linux)

See the per-feature notes above for the full opt-in set.


License

Apache License 2.0 โ€” see LICENSE.

Contributors

arbazkhan971

38 commits

Languages

Rust

95.3%

Python

1.1%

HTML

1.1%

Shell

1.0%