Live Nov 18 · Cohort 3Nov 18, 19:00 MSK — free hands-on AI agents live workshop · Live Cohort 3 starts Nov 23Join Nov 18 Live →Cohort 3 (Nov 23)
ReleaseAPI / Product · ActionableHabr AI→ original

Deepseek-agent: How to Write Your Own Claude Code in 2,000 Lines

A developer built his own Claude Code for DeepSeek in a single night, instead of relying on the Anthropic API. The result is roughly 2000 lines of plain Node.js with no frameworks and just 4 dependencies. It implements all the key concepts: tool use, permissions, memory, compaction and subagents. The tool is minimalist, but powerful.

AI-processed from Habr AI; edited by Hamidun News
Deepseek-agent: How to Write Your Own Claude Code in 2,000 Lines
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Openaian SDK for working with the DeepSeek API (fully compatible with the OpenAI protocol)
Fast-globfast and efficient file search across the file system
Dotenvconvenient loading of environment variables from a .env file

A developer on Habr has shared an intriguing story: in a single night, he wrote his own full-featured analog of Claude Code, the popular terminal-based AI assistant that runs from the command line. Rather than tie himself to the Anthropic API, he chose DeepSeek and built everything from scratch in plain Node.js, producing a minimalist but genuinely powerful tool.

Why build a custom tool

Claude Code is widely recognized as powerful and versatile, but it has one critical problem for many developers: it is tightly bound to Anthropic's ecosystem and its API. The developer wanted similar functionality that works with DeepSeek, an alternative provider that is developing quickly and offers interesting possibilities for experimentation.

Instead of using off-the-shelf frameworks and heavy libraries, he decided to build everything he needed from scratch. This approach let him control every implementation detail, avoid unnecessary dependencies and create a truly lightweight, fast solution that can be quickly modified to fit his needs.

What came out of it

The project is called deepseek-agent and contains roughly 2000 lines of clean, well-organized code. But the main achievement is extreme minimalism in dependencies. The author limited himself to just four external libraries, each solving a specific task:

  • openai: an SDK for working with the DeepSeek API (fully compatible with the OpenAI protocol)
  • fast-glob: fast and efficient file search across the file system
  • dotenv: convenient loading of environment variables from a .env file
  • @modelcontextprotocol/sdk: support for the Model Context Protocol, for integrating external tools and services

There are no heavy frameworks such as Express, and no other abstraction layers that add code without adding functionality. Everything is built on plain Node.js, which makes the source code easy to understand, easy to modify and fast to run.

Which key concepts are implemented

Despite the compact, minimalist code, deepseek-agent implements all the key mechanics that make a modern AI assistant genuinely useful and safe:

  • Tool use: the agent can call functions on its own: bash commands, file operations (read, write, delete), and MCP tools from other systems
  • Permissions: an access-rights system that lets the user approve potentially dangerous operations before they run
  • Memory: the agent remembers context between requests and can refer to details of previous conversations
  • Context compaction: automatic, intelligent compression of the dialogue history as it grows, to save tokens and keep its size within reasonable limits
  • Subagents: the ability to launch nested agents to handle different tasks in parallel and independently
"It would seem that writing your own agent isn't that hard, but there are nuances," the author notes.

Where the real difficulties begin

Implementing each of these concepts has pitfalls that are far from obvious at first glance. The permissions system requires very careful architectural design so as not to leave holes in security controls. Context compaction has to be done smartly and delicately, to keep the truly important information and not lose key details from earlier conversations. Working with MCP requires a deep understanding of its specification and all the nuances of interacting with external tools.

The author notes that even within 2000 lines of code there were a huge number of places where edge cases had to be carefully considered, errors handled correctly and elegantly, and various failure scenarios anticipated.

What this means for the AI ecosystem

This project shows that powerful, full-featured AI assistants are quite achievable for experienced developers without being tied to a single provider. The minimalist approach of limiting dependencies not only saves code and simplifies maintenance, but also makes the solution noticeably more reliable and easier to understand.

The modular architecture makes it easy to plug in new providers (Claude, Grok, local models) in place of DeepSeek, simply by swapping the API client and a few config parameters.

Story

Key Questions Answered

Why build a custom tool?

Claude Code is widely recognized as powerful and versatile, but it has one critical problem for many developers: it is tightly bound to Anthropic's ecosystem and its API. The developer wanted similar functionality that works with DeepSeek, an alternative provider that is developing quickly and offers interesting possibilities for experimentation. Instead of using off-the-shelf frameworks and heavy libraries, he decided to build everything he needed from scratch.

What came out of it?

The project is called deepseek-agent and contains roughly 2000 lines of clean, well-organized code. But the main achievement is extreme minimalism in dependencies. The author limited himself to just four external libraries, each solving a specific task: openai: an SDK for working with the DeepSeek API (fully compatible with the OpenAI protocol) fast-glob: fast and efficient file search across the file system dotenv: convenient loading of environment variables from a .env file…

Which key concepts are implemented?

Despite the compact, minimalist code, deepseek-agent implements all the key mechanics that make a modern AI assistant genuinely useful and safe: Tool use: the agent can call functions on its own: bash commands, file operations (read, write, delete), and MCP tools from other systems Permissions: an access-rights system that lets the user approve potentially dangerous operations before they run Memory: the agent remembers context between requests and can refer to details of previous conversations…

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Hands-On AI Engineering · Hamidun Academy

Build & Ship Production AI Agents Without Boilerplate Code

Start your free 72-hour trial at Hamidun Academy (academy.hamidun.com) — interactive lessons on Claude Code & Cursor, live Tech Radar, and production agent templates.

Start 72h Free Trial →Vibe-Coding Intensive
What do you think?
Loading comments…