Habr AI→ original

Deepseek-agent: how to write your own Claude Code in 2,000 lines of code

A developer built a custom Claude Code for DeepSeek in a single night instead of using Anthropic's API. The result: about 2,000 lines of clean Node.js with no f

Deepseek-agent: how to write your own Claude Code in 2,000 lines of code
Source: Habr AI. Collage: Hamidun News.
◐ Listen to article

A developer on Habr shared an intriguing story: how, in a single night, he wrote his own fully functional equivalent of Claude Code — a popular terminal AI assistant that works from the command line. Instead of being tied to the Anthropic API, he chose DeepSeek and built everything from scratch in pure Node.js, creating a minimalist yet truly powerful tool.

Why Build Your Own

Claude Code is undoubtedly a powerful and universal tool, but it has one critical problem for many developers: it is tightly bound to the Anthropic ecosystem and its API. The developer wanted to get similar functionality, but working with DeepSeek — an alternative provider that is rapidly evolving and offers interesting possibilities for independent experiments. Instead of using ready-made frameworks and heavy libraries, he decided to build everything needed from scratch. This approach allowed him to control every detail of the implementation, avoid unnecessary dependencies, and create a truly lightweight, fast solution that could be quickly modified for his specific needs.

What Turned Out in Practice

The project is named deepseek-agent and contains approximately 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 — SDK for working with DeepSeek API (fully compatible with OpenAI protocol)
  • fast-glob — fast and efficient file search in the file system
  • dotenv — convenient loading of environment variables from .env file
  • @modelcontextprotocol/sdk — support for Model Context Protocol for integration with external tools and services

No heavy frameworks like Express or other abstraction layers that add code but don't add functionality. Everything is built on pure Node.js, which makes the source code simple to understand, easy to modify, and fast to execute.

What Key Concepts Are Implemented

Despite the compactness and minimalism of the code, deepseek-agent implements all the key mechanics that make a modern AI assistant truly useful and secure:

  • Tool use — the agent can independently call functions: bash commands, file operations (read, write, delete), MCP tools from other systems
  • Permissions — an access control management system that allows users to approve potentially dangerous operations before execution
  • Memory — the agent remembers context between requests and can reference details from previous conversations
  • Context compaction — automatic intelligent compression of conversation history as it grows, to save tokens and keep size within reasonable limits
  • Subagents — the ability to run nested agents for parallel and independent processing of different tasks
"It might seem not so difficult to build your own agent, but there are

nuances," notes the author.

Where Real Complexity Begins

Each of these concepts has its own pitfalls that are far from obvious at first glance. The permissions system requires very careful architectural design to avoid creating security control loopholes. Context compaction needs to be done smartly and delicately to preserve truly important information and not lose key details from previous conversations. Working with the MCP protocol requires deep understanding of its specification and all the nuances of interaction with external tools. The author notes that even in 2000 lines of code, there were a huge number of places where one had to carefully account for edge cases, handle errors properly and elegantly, and anticipate various failure and malfunction scenarios.

What This Means for the AI Ecosystem

This project proves that powerful and fully functional AI assistants are quite achievable for experienced developers without being tied to a single provider. A minimalist approach with limited dependencies not only saves code and simplifies maintenance, but also makes the solution noticeably more reliable and understandable. Modular architecture allows you to easily connect new providers (Claude, Grok, local models) instead of DeepSeek, simply by replacing the API client and a few config parameters.

ZK
Hamidun News
AI news without noise. Daily editorial selection from 400+ sources. A product by Zhemal Khamidun, Head of AI at Alpina Digital.
What do you think?
Loading comments…