Skip to content

Repository files navigation

CodeForge

CodeForge is a local-first AI coding agent for VS Code / Kiro, powered by local large language models via Ollama. Everything runs offline on your machine, no cloud, no API keys.

It has two modes:

  • Chat - a plain streaming conversation with the model.
  • Agent - a LangGraph.js ReAct agent that can explore your codebase with tools before answering.

Features

  • Chat panel in the activity bar (CodeForge icon).
  • Streaming responses, token by token, in Chat mode.
  • Agent mode that reads your workspace, edits files to refactor, and runs commands to verify its work (build/tests) - all with per-change approval - and shows each step it takes.
  • Model picker populated from the models you have installed locally.
  • Right-click in the editor to Explain Selected Code or Explain Current File.
  • Uses your VS Code theme colors.

Pulling models

You can download models without leaving the editor: click the download button in the chat toolbar, or run CodeForge: Pull Model from the Command Palette, and enter a model name (e.g. qwen2.5-coder). A progress notification shows the real download percentage reported by Ollama and can be cancelled. The model list refreshes automatically when the download completes.

Requirements

  1. Install Ollama: https://ollama.com/download
  2. Pull at least one model. For Chat mode any model works, for example:
    ollama pull deepseek-coder
    ollama pull llama3.2
    ollama pull gemma2
    
    For Agent mode a model with native tool calling works best, for example:
    ollama pull qwen2.5-coder
    ollama pull llama3.1
    ollama pull mistral
    
    Models without native tool calling (e.g. deepseek-coder) still work in Agent mode through a prompt-based fallback, but it is less reliable.
  3. Make sure the Ollama server is running (it listens on http://localhost:11434 by default). ollama serve starts it, and pulling/running a model starts it automatically.

Usage

  • Open the CodeForge view from the activity bar.
  • Pick a model from the dropdown (click the refresh button if the list is empty).
  • Choose Chat or Agent in the mode bar.
  • Type a question and press Enter (Shift+Enter for a newline).
  • To explain code: select code in the editor, right-click, and choose CodeForge: Explain Selected Code. Or run CodeForge: Explain Current File from the command palette.

Agent mode

In Agent mode the model can call these tools, and you see each call and its result inline.

Read-only:

  • list_directory - list files and folders in the workspace.
  • read_file - read a file's contents.
  • grep_search - search file contents by regular expression.
  • get_open_file - read the file currently open in the editor, including the selection.

Editing (each change is shown for approval before it is applied):

  • apply_edit - replace an exact snippet in an existing file (used for refactors).
  • write_file - create a new file or overwrite an existing one.
  • create_directory - create a folder.

Verification:

  • run_command - run a shell command in the workspace (build, type-check, tests, linter, or environment checks like flutter --version) and read the result. The agent uses this to verify changes and to answer questions about your environment.

Commands run through your login shell so the agent sees the same PATH and tools as your terminal (Flutter, Node version managers, etc.). Pick a specific shell with ollamaCodeChat.agentShell if auto-detection is wrong.

Known read-only commands (version checks, which/where, git status, and similar) run without approval so questions like "what Flutter version do I have?" are answered directly. This is controlled by ollamaCodeChat.agentAllowSafeReadCommands (on by default) and is deliberately strict: anything with chaining, piping, or redirection (;, &&, |, >) still requires Apply/Skip, as does any command that writes or changes state.

When the agent wants to change a file or run a command, a card appears in the chat with the target path or command and a preview/diff, plus Apply and Skip buttons. Nothing happens until you click Apply. Edits are applied through VS Code's workspace edit API, so they show up in the editor and can be undone with Ctrl+Z.

To let trusted commands run without prompting, add their prefixes to ollamaCodeChat.agentCommandAllowlist, for example ["npm run build", "npm test"]. A command runs automatically only if it equals a listed prefix or starts with it followed by a space; anything else still prompts. Commands are terminated after ollamaCodeChat.agentCommandTimeout seconds. Set ollamaCodeChat.agentAutoApplyEdits to true to apply file edits automatically (this does not affect commands).

All tools are sandboxed to the open workspace folder (paths that escape it are rejected). The agent is told not to start long-running processes such as dev servers or watchers.

Tool calling and the prompt-based fallback

The extension detects each model's capabilities via Ollama's /api/show. Models that support native tool calling are marked with a wrench in the model dropdown.

  • If the selected model supports tools, Agent mode uses them natively (via LangGraph's tool node).
  • If it does not, Agent mode automatically falls back to a prompt-based loop: the model is asked to reply with a JSON action each turn, which the extension parses and executes. This lets models like deepseek-coder act as agents too, though native tool calling is more reliable. A notice appears in the chat when the fallback is used.

Progress and stats

While a reply is being generated you see a live indicator: a spinner with the current phase ("Loading model", "Thinking", "Generating", or the tool the agent is running) and an elapsed-seconds counter, so it is always clear the model is still working.

After each reply a small dimmed line shows usage reported by Ollama: prompt tokens (and how much of the model's context window they use), reply tokens, generation speed in tokens/second, and the total time (with model load time when relevant). Turn it off with ollamaCodeChat.showStats.

Session logging

Each project keeps a log of your chat/agent sessions under <project>/.ollama-chat/:

  • sessions/<sessionId>.jsonl - one JSON record per line (messages, tool calls and results, commands, approvals, errors). JSONL is append-only and is the shape RAG and fine-tuning pipelines expect, so this log doubles as a future dataset.
  • env.json - a snapshot of the environment for the project: OS, Node/VS Code versions, the Ollama server version, and the installed models with their capabilities.

History and restore

When you open a project, the most recent session for that folder is reloaded automatically into the chat panel, including messages, tool steps, approvals and errors. Use the clock button in the toolbar to browse and open older sessions, and New to start a fresh conversation (the old one stays on disk).

When you continue a long or restored conversation, only the last few turns are sent to the model to avoid overflowing the context window. Control how many with ollamaCodeChat.historyContextTurns (0 = send everything). Older messages remain visible; they just aren't re-sent.

Logging is on by default; turn it off with ollamaCodeChat.logging.

Commands (Command Palette):

  • Ollama: Open Session Log (current project) - opens the current project's JSONL log.
  • Ollama: Open Sessions Folder (current project) - reveals the .ollama-chat folder.

If you do not want these files committed, add .ollama-chat/ to your .gitignore.

Settings

Setting Default Description
ollamaCodeChat.baseUrl http://localhost:11434 Base URL of the Ollama server.
ollamaCodeChat.model `` Chat model. Leave empty to use the first installed model.
ollamaCodeChat.agentModel `` Model for Agent mode (must support tool calling). Empty reuses the chat model.
ollamaCodeChat.temperature 0.2 Sampling temperature.
ollamaCodeChat.agentMaxSteps 12 Max reasoning/tool steps before the agent stops.
ollamaCodeChat.agentAutoApplyEdits false Apply agent file edits without asking for approval each time.
ollamaCodeChat.agentCommandAllowlist [] Command prefixes the agent may run without prompting.
ollamaCodeChat.agentCommandTimeout 120 Seconds before an agent command is terminated.
ollamaCodeChat.agentShell `` Shell for agent commands (empty = auto-detect login shell).
ollamaCodeChat.agentAllowSafeReadCommands true Run known read-only commands (version checks, etc.) without approval.
ollamaCodeChat.logging true Log sessions and an env snapshot per project under .ollama-chat/.
ollamaCodeChat.showStats true Show a token/timing/context stats line under each reply.
ollamaCodeChat.historyContextTurns 10 Recent turns sent to the model when continuing a conversation (0 = no limit).

Develop

npm install
npm run build     # bundle with esbuild -> dist/extension.js
npm run watch     # rebuild on change
npm run compile   # type-check only (tsc --noEmit)

Press F5 in VS Code to launch an Extension Development Host.

How it works

  • Chat mode talks to the Ollama REST API directly (GET /api/tags for models, POST /api/chat streaming NDJSON for responses) using Node's built-in http.
  • Agent mode builds a StateGraph with LangGraph.js: a model node (an @langchain/ollama ChatOllama bound to the workspace tools) and a ToolNode. A conditional edge loops back to the model whenever it requests a tool, and ends when it produces a plain answer. Editing tools route through a WriteGuard that asks for approval and applies changes via VS Code's WorkspaceEdit.

The extension is bundled with esbuild into a single dist/extension.js.

About

Local Autonomous Software Engineering Agent

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages