A local Python coding agent with a Textual TUI.
Project description
FirstCoder
A local Python coding agent built to make agent internals visible.
English · 简体中文
FirstCoder is a real, runnable local coding agent with a Textual TUI, tool calling, permissions, sessions, and context compaction. It is designed to be useful in daily work and easy to study in code.
If you want to understand how coding agents actually work, FirstCoder keeps the moving parts visible instead of hiding them behind a black box.
- Learn the agent loop, tool calling, permissions, sessions, and context handling.
- Build on a small Python codebase with clear module boundaries.
- Use a local coding agent while still being able to inspect how it works.
Why FirstCoder
Most coding-agent demos show the surface: a prompt goes in, code changes come out. FirstCoder focuses on the machinery in between.
Compared with larger projects like OpenCode, FirstCoder is intentionally smaller in scope.
| Dimension | FirstCoder | Larger projects like OpenCode |
|---|---|---|
| Primary goal | Make agent internals readable and teachable | Deliver a broader production-style coding-agent platform |
| Codebase shape | Roughly 25k lines of Python under firstcoder/ (174 files) |
Roughly 575k lines of TS/JS across a much larger multi-surface codebase |
| Engineering tradeoff | Drops some extra platform surface area to stay inspectable | Accepts more complexity to support a broader product surface |
| Best fit | Learning, modification, interview prep, portfolio projects, and local experimentation | Users who want a larger, more full-surface coding-agent environment |
The goal is not to out-feature a bigger coding agent. The goal is to keep the system real enough to use, but small enough that you can still read it end to end and understand why each subsystem exists.
That also makes FirstCoder a practical repo to study deeply, adapt for your own workflow, and turn into a resume-worthy or portfolio-friendly project after you have extended it.
Compared with more tutorial-first or lightweight learning repos, FirstCoder also tries to stay closer to a small but testable engineering system.
| Dimension | FirstCoder | Many learning-oriented agent repos |
|---|---|---|
| Learning value | Readable subsystem boundaries and explicit docs | Often optimized for a single tutorial path or demo flow |
| Practical surface | Real TUI, tools, permissions, sessions, provider adapters | Often focused on a narrower loop or a simpler proof of concept |
| Verification | 108 test modules and multiple benchmark entry points | Often lighter on testing and benchmark integration |
| Extension path | Easier to adapt into a portfolio or resume project | Often better for following along than for long-term extension |
In this repo, the learning goal is important, but it is paired with enough runtime structure, tests, and benchmark hooks to make the project useful after the first read-through.
It is built for people who want to:
- study how a coding agent is assembled
- modify or extend a local Python implementation
- understand the architecture well enough to explain it in an interview
Detailed subsystem design lives in the docs, not in this README.
Quickstart
Install with pipx:
pipx install firstcoder
Start the TUI:
firstcoder
Run one message without opening the TUI:
firstcoder --message "Summarize this repository in one paragraph"
Use line-oriented interactive mode:
firstcoder --interactive
What You Get
- Local Python coding agent
- Textual TUI that exposes agent activity instead of hiding it
- Tool calling with highlighted diffs before direct file mutations
- Session persistence, resume flow, and context compaction
- Skills, provider adapters, and clean modules for study and modification
Configuration
Create a starter config:
firstcoder config init
firstcoder config path
firstcoder config show
Keep secrets in environment variables:
export FIRSTCODER_API_KEY="your-api-key"
Default config locations:
global: ~/.config/firstcoder/config.toml
project: ./firstcoder.toml
Provider support is centered on the OpenAI Chat Completions-compatible path and a native Anthropic Messages API adapter. Both paths implement the same internal complete/streaming contracts (text deltas, tool-call accumulation, forced tool_choice, usage, and PROMPT_TOO_LONG-style error classification). The TUI's native multimodal input can stage pasted file paths and clipboard images; images and small text files then travel through the session/context pipeline to providers that support vision. Model and provider vision capability still matters. Anthropic-only extras such as prompt caching remain optional future work. FirstCoder does not use the OpenAI Responses API yet.
Multiple models and request options
You can keep several provider/model profiles in one global or project TOML file. Project values are merged over global values, so a project can override only the fields it needs:
default_model = "yuren/gpt-5.6-terra"
[providers.yuren]
type = "openai-compatible"
base_url = "https://yurenapi.cn/v1"
api_key_env = "YURENAPI_API_KEY"
[models."yuren/gpt-5.6-terra"]
label = "Yuren Terra"
[models."yuren/gpt-5.6-terra".request]
temperature = 0.2
max_tokens = 8192
reasoning_effort = "high"
extra_body = { reasoning_summary = "auto" }
Use firstcoder --model provider/model to choose the initial profile for a run. In the TUI, /models opens the configured model picker and /model provider/model switches immediately. firstcoder config show prints the configured model references and labels, but never prints API keys, environment-variable values, request bodies, or model-state contents.
temperature, max_tokens, and extra_body are sent with the main model request. reasoning_effort is represented as a request extension and passed through when the selected provider supports it; providers that do not recognize it may reject or ignore it. Internal classifiers and compact summarization keep their own bounded token budgets.
A small detail for observant users: some provider/model combinations give the TUI topbar a little more character.
TUI
FirstCoder's TUI is designed to expose the agent loop instead of hiding it. You can see session state, streamed assistant output, tool calls, tool results, and permission prompts in one place.
Before write, edit, apply_patch, or delete changes local files, FirstCoder builds a trusted unified diff with red removals, green additions, per-file statistics, and bounded expansion controls. In standard mode it accompanies the normal permission confirmation; an existing grant or aggressive mode still requires a review-only Apply confirmation. Approve the reviewed operation, deny it, or reply with reject: <feedback> so the model can revise the proposed change. FirstCoder rechecks reviewed file snapshots immediately before dispatch and blocks stale operations, reducing accidental overwrites from concurrent changes; this is a guard, not a filesystem-level atomic transaction. In bypass mode the review is shown as a non-blocking event and the operation proceeds immediately; non-interactive benchmark adapters explicitly disable that event. Shell commands follow the permission policy for the active mode because arbitrary command effects cannot be precomputed safely.
Ready state:
Conversation flow:
Documentation
- Technical Docs Index
- Chinese Docs Index
- Architecture
- Codebase Reading Guide
- Multimodal Input Design
- MCP Client Configuration
Development
Install dev dependencies:
python -m venv .venv
.venv/bin/python -m pip install -e ".[dev]"
Run all tests:
.venv/bin/python -m pytest
Run a focused test file:
.venv/bin/python -m pytest tests/test_app_tui.py -q
Philosophy
FirstCoder was built to answer a question most coding agents do not address:
What actually happens inside when an agent streams, calls tools, asks for permission, compacts context, and resumes a session?
It is a real runnable agent, but it is also a readable Python project you can learn from one subsystem at a time.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file firstcoder-0.1.7.tar.gz.
File metadata
- Download URL: firstcoder-0.1.7.tar.gz
- Upload date:
- Size: 240.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95b458829f022d2c82e44a9f424735bfe99aa266e288174479a36b6e49ed57f3
|
|
| MD5 |
fabf903f4a29fc8fcd747f80b7b29ba7
|
|
| BLAKE2b-256 |
56484195de23143b99f10addb6435003b7ee5674ee881f34324f57469757a652
|
File details
Details for the file firstcoder-0.1.7-py3-none-any.whl.
File metadata
- Download URL: firstcoder-0.1.7-py3-none-any.whl
- Upload date:
- Size: 316.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52eeab7967e7460b7a8f16b1f1c6727ec9a88517c506fa3bed1cfe8b217e516e
|
|
| MD5 |
d71dc3981b28df92c029f07e6ffcff82
|
|
| BLAKE2b-256 |
80699a9434a92e028438ae1d9618a98050beaf688c605178c3b43d05b2efd5e7
|